[go: up one dir, main page]

File: s-unroll.c

package info (click to toggle)
uftrace 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,212 kB
  • sloc: ansic: 53,313; python: 9,846; makefile: 838; asm: 703; cpp: 602; sh: 560; javascript: 191
file content (53 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>

#define LOOP_CNT 4

int big(int n)
{
	char string[] = "a local string variable saved in the stack memory";
	volatile unsigned x = n;
	int i;

	for (i = 0; i < LOOP_CNT; i++) {
		x *= 3 + i;
		x ^= 0xf0f0f0f0;
		x &= (1 << i) - 1;

		if (x == 0)
			x = (unsigned)string[i] << i;
	}
	return n;
}

int small(int n)
{
	return big(n) ? n : 1;
}

int main(int argc, char *argv[])
{
	char string[] = "a very long string variable saved in the stack memory";
	int n = 123456;
	int i;

	if (argc > 1)
		n = atoi(argv[1]);
	else if (argc > 2)
		n = strtol(argv[1], NULL, atoi(argv[2]));

	small(n ? n : 123456);

	for (i = 0; i < LOOP_CNT; i++) {
		static volatile unsigned x = 42;

		x *= 1 << i;
		x ^= 0xdeadbeef;
		x >>= i;

		if (x == 0)
			x = (unsigned)string[i] << i;
	}

	return n ? (n ^ n) : 0;
}