-
Notifications
You must be signed in to change notification settings - Fork 1
/
phase_4.c
56 lines (48 loc) · 876 Bytes
/
phase_4.c
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
54
55
56
// %edi %esi %edx
static int func4(int a, int b, int c)
{
int tmp = (((c - b) + ((c - b) >> 31)) >> 1) + b;
if (tmp <= a) {
if (tmp == a) {
return (0);
} else {
return func4(a, tmp + 1, c) * 2 + 1;
}
} else {
return func4(a, b, tmp - 1) * 2;
}
}
void phase_4(const char *input)
{
// 0x8(%rsp) 0xc(%rsp)
int num1, num2;
// %rdi %rsi %rdx %rcx
int result = sscanf(input, "%d %d", &num1, &num2);
if (result != 2) {
explode_bomb();
}
if (num1 > 0xe) {
explode_bomb();
}
// %edi %esi %edx
result = func4(num1, 0, 0xe);
if (result != 0) {
explode_bomb();
}
if (num2 != 0) {
explode_bomb();
}
}
#if 0
int main(int argc, const char *argv[])
{
int i, result;
for (i = 0; i < 14; ++i) {
result = func4(i, 0, 14);
if (result == 0) {
printf("%d\n", i);
}
}
return 0;
}
#endif