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;
}
|