#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int strtol(char *, char **, int /*<<< orphan*/);
int main() {
  char test[100] = {0};
  char *end = NULL;
  read(0, test, 80);
  if (strtol(test, &end, 0) == 0xaaaa) {
    if (test[0] == '0' && test[1] != 'x') {
      puts("base 8 worked");
    } else if (test[0] == '+' && test[1] == '0' && test[2] != 'x') {
      puts("base +8 worked");
    } else if (test[0] == '0' && test[1] == 'x') {
      puts("0x worked");
    } else if (test[0] == '+' && test[1] == '0' && test[2] == 'x') {
      puts("+0x worked");
    } else if (test[0] == '+' && test[1] != '0') {
      puts("base +10 worked");
    } else {
      puts("base 10 worked");
    }
  } else if (strtol(test, &end, 0) == -0xcdcd) {
    if (test[0] == '-' && test[1] == '0' && test[2] != 'x') {
      puts("base -8 worked");
    } else if (test[0] == '-' && test[1] == '0' && test[2] == 'x') {
      puts("-0x worked");
    } else if (test[0] == '-' && test[1] != '0') {
      puts("base -10 worked");
    } else {
      puts("shouldn't happen");
    }
  } else {
    puts("Nope");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
movq   $0x0,-0x78(%rbp)
lea    -0x70(%rbp),%rsi
xor    %edi,%edi
mov    $0x50,%edx
call   1050 <read@plt>
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
cmp    $0xaaaa,%eax
jne    12aa <main+0x16a>
movsbl -0x70(%rbp),%eax
cmp    $0x30,%eax
jne    11bf <main+0x7f>
movsbl -0x6f(%rbp),%eax
cmp    $0x78,%eax
je     11bf <main+0x7f>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
jmp    12a5 <main+0x165>
movsbl -0x70(%rbp),%eax
cmp    $0x2b,%eax
jne    11f7 <main+0xb7>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
jne    11f7 <main+0xb7>
movsbl -0x6e(%rbp),%eax
cmp    $0x78,%eax
je     11f7 <main+0xb7>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
jmp    12a0 <main+0x160>
movsbl -0x70(%rbp),%eax
cmp    $0x30,%eax
jne    1222 <main+0xe2>
movsbl -0x6f(%rbp),%eax
cmp    $0x78,%eax
jne    1222 <main+0xe2>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
jmp    129b <main+0x15b>
movsbl -0x70(%rbp),%eax
cmp    $0x2b,%eax
jne    125a <main+0x11a>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
jne    125a <main+0x11a>
movsbl -0x6e(%rbp),%eax
cmp    $0x78,%eax
jne    125a <main+0x11a>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
jmp    1296 <main+0x156>
movsbl -0x70(%rbp),%eax
cmp    $0x2b,%eax
jne    1285 <main+0x145>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
je     1285 <main+0x145>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
jmp    1291 <main+0x151>
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
jmp    1296 <main+0x156>
jmp    129b <main+0x15b>
jmp    12a0 <main+0x160>
jmp    12a5 <main+0x165>
jmp    138b <main+0x24b>
lea    -0x70(%rbp),%rdi
lea    -0x78(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
cmp    $0xffff3233,%eax
jne    137a <main+0x23a>
movsbl -0x70(%rbp),%eax
cmp    $0x2d,%eax
jne    12fc <main+0x1bc>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
jne    12fc <main+0x1bc>
movsbl -0x6e(%rbp),%eax
cmp    $0x78,%eax
je     12fc <main+0x1bc>
lea    0xd55(%rip),%rdi
call   1030 <puts@plt>
jmp    1375 <main+0x235>
movsbl -0x70(%rbp),%eax
cmp    $0x2d,%eax
jne    1334 <main+0x1f4>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
jne    1334 <main+0x1f4>
movsbl -0x6e(%rbp),%eax
cmp    $0x78,%eax
jne    1334 <main+0x1f4>
lea    0xd2c(%rip),%rdi
call   1030 <puts@plt>
jmp    1370 <main+0x230>
movsbl -0x70(%rbp),%eax
cmp    $0x2d,%eax
jne    135f <main+0x21f>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
je     135f <main+0x21f>
lea    0xd0c(%rip),%rdi
call   1030 <puts@plt>
jmp    136b <main+0x22b>
lea    0xd0b(%rip),%rdi
call   1030 <puts@plt>
jmp    1370 <main+0x230>
jmp    1375 <main+0x235>
jmp    1386 <main+0x246>
lea    0xd01(%rip),%rdi
call   1030 <puts@plt>
jmp    138b <main+0x24b>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1040 <read@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    $0xaaaa,%eax
jne    11ae <main+0x7e>
mov    0x10(%rsp),%al
mov    0x11(%rsp),%bl
cmp    $0x30,%al
jne    11f2 <main+0xc2>
cmp    $0x78,%bl
je     11f2 <main+0xc2>
lea    0xe54(%rip),%rdi
jmp    121c <main+0xec>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    $0xffff3233,%eax
jne    1215 <main+0xe5>
mov    0x10(%rsp),%sil
mov    0x11(%rsp),%al
mov    %esi,%edx
xor    $0x2d,%dl
mov    %eax,%ecx
xor    $0x30,%cl
or     %dl,%cl
sete   %dl
mov    0x12(%rsp),%bl
jne    122c <main+0xfc>
cmp    $0x78,%bl
je     122c <main+0xfc>
lea    0xe57(%rip),%rdi
jmp    121c <main+0xec>
mov    %eax,%edx
xor    $0x2b,%dl
mov    %ebx,%ecx
xor    $0x30,%cl
or     %dl,%cl
sete   %dl
mov    0x12(%rsp),%cl
jne    123f <main+0x10f>
cmp    $0x78,%cl
je     123f <main+0x10f>
lea    0xdfb(%rip),%rdi
jmp    121c <main+0xec>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret
cmp    $0x78,%bl
sete   %cl
test   %cl,%dl
je     1251 <main+0x121>
lea    0xe19(%rip),%rdi
jmp    121c <main+0xec>
cmp    $0x30,%al
jne    126f <main+0x13f>
cmp    $0x78,%bl
jne    126f <main+0x13f>
lea    0xdcf(%rip),%rdi
jmp    121c <main+0xec>
cmp    $0x30,%al
lea    0xe07(%rip),%rdi
lea    0xe10(%rip),%rax
cmove  %rax,%rdi
cmp    $0x2d,%sil
cmovne %rax,%rdi
jmp    121c <main+0xec>
cmp    $0x78,%cl
sete   %cl
test   %cl,%dl
je     1282 <main+0x152>
lea    0xd9d(%rip),%rdi
jmp    121c <main+0xec>
cmp    $0x30,%bl
lea    0xd9c(%rip),%rdi
lea    0xda5(%rip),%rcx
cmove  %rcx,%rdi
cmp    $0x2b,%al
cmovne %rcx,%rdi
jmp    121c <main+0xec>

LLVM IR (-O0):
@.str = [14 x i8] c"base 8 worked\00"
@.str.1 = [15 x i8] c"base +8 worked\00"
@.str.2 = [10 x i8] c"0x worked\00"
@.str.3 = [11 x i8] c"+0x worked\00"
@.str.4 = [16 x i8] c"base +10 worked\00"
@.str.5 = [15 x i8] c"base 10 worked\00"
@.str.6 = [15 x i8] c"base -8 worked\00"
@.str.7 = [11 x i8] c"-0x worked\00"
@.str.8 = [16 x i8] c"base -10 worked\00"
@.str.9 = [17 x i8] c"shouldn't happen\00"
@.str.10 = [5 x i8] c"Nope\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = bitcast [100 x i8]* %2 to i8*
store i8* null, i8** %3
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %5, i32 80)
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @strtol(i8* %7, i8** %3, i32 0)
%9 = icmp eq i32 %8, 43690
br i1 %9, label %10, label %87
10: ; preds = %0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 48
br i1 %14, label %15, label %22
15: ; preds = %10
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 120
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %86
22: ; preds = %15, %10
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 43
br i1 %26, label %27, label %39
27: ; preds = %22
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 48
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 120
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %85
39: ; preds = %32, %27, %22
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 48
br i1 %43, label %44, label %51
44: ; preds = %39
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 120
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %84
51: ; preds = %44, %39
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 43
br i1 %55, label %56, label %68
56: ; preds = %51
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 48
br i1 %60, label %61, label %68
61: ; preds = %56
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 120
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %83
68: ; preds = %61, %56, %51
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 43
br i1 %72, label %73, label %80
73: ; preds = %68
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%75 = load i8, i8* %74
%76 = sext i8 %75 to i32
%77 = icmp ne i32 %76, 48
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %82
80: ; preds = %73, %68
%81 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %82
82: ; preds = %80, %78
br label %83
83: ; preds = %82, %66
br label %84
84: ; preds = %83, %49
br label %85
85: ; preds = %84, %37
br label %86
86: ; preds = %85, %20
br label %145
87: ; preds = %0
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%89 = call i32 @strtol(i8* %88, i8** %3, i32 0)
%90 = icmp eq i32 %89, -52685
br i1 %90, label %91, label %142
91: ; preds = %87
%92 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 45
br i1 %95, label %96, label %108
96: ; preds = %91
%97 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%98 = load i8, i8* %97
%99 = sext i8 %98 to i32
%100 = icmp eq i32 %99, 48
br i1 %100, label %101, label %108
101: ; preds = %96
%102 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp ne i32 %104, 120
br i1 %105, label %106, label %108
106: ; preds = %101
%107 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %141
108: ; preds = %101, %96, %91
%109 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 45
br i1 %112, label %113, label %125
113: ; preds = %108
%114 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = icmp eq i32 %116, 48
br i1 %117, label %118, label %125
118: ; preds = %113
%119 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 120
br i1 %122, label %123, label %125
123: ; preds = %118
%124 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %140
125: ; preds = %118, %113, %108
%126 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp eq i32 %128, 45
br i1 %129, label %130, label %137
130: ; preds = %125
%131 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
%132 = load i8, i8* %131
%133 = sext i8 %132 to i32
%134 = icmp ne i32 %133, 48
br i1 %134, label %135, label %137
135: ; preds = %130
%136 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %139
137: ; preds = %130, %125
%138 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %139
139: ; preds = %137, %135
br label %140
140: ; preds = %139, %123
br label %141
141: ; preds = %140, %106
br label %144
142: ; preds = %87
%143 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %144
144: ; preds = %142, %141
br label %145
145: ; preds = %144, %86
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"base 8 worked\00"
@.str.1 = [15 x i8] c"base +8 worked\00"
@.str.2 = [10 x i8] c"0x worked\00"
@.str.3 = [11 x i8] c"+0x worked\00"
@.str.4 = [16 x i8] c"base +10 worked\00"
@.str.5 = [15 x i8] c"base 10 worked\00"
@.str.6 = [15 x i8] c"base -8 worked\00"
@.str.7 = [11 x i8] c"-0x worked\00"
@.str.8 = [16 x i8] c"base -10 worked\00"
@.str.9 = [17 x i8] c"shouldn't happen\00"
@.str.10 = [5 x i8] c"Nope\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = call i32 @read(i32 0, i8* %3, i32 80)
%6 = call i32 @strtol(i8* %3, i8** %2, i32 0)
%7 = icmp eq i32 %6, 43690
br i1 %7, label %8, label %33
8: ; preds = %0
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 48
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 120
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %54, label %15
15: ; preds = %8
%16 = icmp eq i8 %9, 43
%17 = icmp eq i8 %12, 48
%18 = select i1 %16, i1 %17, i1 false
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 120
%22 = select i1 %18, i1 %21, i1 false
br i1 %22, label %54, label %23
23: ; preds = %15
%24 = icmp eq i8 %12, 120
%25 = select i1 %10, i1 %24, i1 false
br i1 %25, label %54, label %26
26: ; preds = %23
%27 = icmp eq i8 %20, 120
%28 = select i1 %18, i1 %27, i1 false
br i1 %28, label %54, label %29
29: ; preds = %26
%30 = icmp ne i8 %12, 48
%31 = select i1 %16, i1 %30, i1 false
%32 = select i1 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0)
br label %54
33: ; preds = %0
%34 = call i32 @strtol(i8* %3, i8** %2, i32 0)
%35 = icmp eq i32 %34, -52685
br i1 %35, label %36, label %54
36: ; preds = %33
%37 = load i8, i8* %3
%38 = icmp eq i8 %37, 45
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 48
%42 = select i1 %38, i1 %41, i1 false
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 120
%46 = select i1 %42, i1 %45, i1 false
br i1 %46, label %54, label %47
47: ; preds = %36
%48 = icmp eq i8 %44, 120
%49 = select i1 %42, i1 %48, i1 false
br i1 %49, label %54, label %50
50: ; preds = %47
%51 = icmp ne i8 %40, 48
%52 = select i1 %38, i1 %51, i1 false
%53 = select i1 %52, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0)
br label %54
54: ; preds = %33, %50, %47, %36, %29, %26, %23, %15, %8
%55 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %15 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %26 ], [ %32, %29 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), %36 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %47 ], [ %53, %50 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), %33 ]
%56 = call i32 @puts(i8* dereferenceable(1) %55)
ret i32 0
}