#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 */
typedef int /*<<< orphan*/ input;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int main() {
  int cost = 100;
  int priv_level = 0;
  puts("Not only did you make it back to ground level, but you found the door "
       "to our secret research equipment. Too bad you don't have the privilege "
       "level to enter it. However you can raise the privilege level if you "
       "want.");
  char input[1000];
  while (1 == 1) {
    memset(input, 0, sizeof(input));
    fgets(input, sizeof(input) - 1, stdin);
    if (atoi(input) > 0 && atoi(input) < (0x7fffffff - cost)) {
      cost = cost + atoi(input);
    }
    printf("Current privilege level needed to access this is %d.\n", cost);
    if (cost <= priv_level) {
      puts("I'm pretty sure that wasn't supposed to happen. Level Cleared!");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x400(%rbp),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    $0x3e7,%esi
call   1060 <fgets@plt>
lea    -0x400(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x0,%eax
jle    11fc <main+0xac>
lea    -0x400(%rbp),%rdi
call   1070 <atoi@plt>
mov    $0x7fffffff,%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jge    11fc <main+0xac>
mov    -0x8(%rbp),%eax
mov    %eax,-0x404(%rbp)
lea    -0x400(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    -0x404(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1223 <main+0xd3>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
jmp    117c <main+0x2c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    $0x64,%ebx
mov    %rsp,%r12
mov    0x2e6c(%rip),%r13
lea    0xf54(%rip),%r14
lea    0xf83(%rip),%r15
jmp    11a4 <main+0x54>
nopl   0x0(%rax)
test   %eax,%eax
cmovg  %ecx,%ebp
lea    (%rbx,%rbp,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    %ebp,%ebx
jle    11e0 <main+0x90>
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x3e7,%esi
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    $0x7fffffff,%edx
sub    %ebx,%edx
mov    %eax,%ecx
cmp    %edx,%eax
jl     1190 <main+0x40>
xor    %ecx,%ecx
jmp    1190 <main+0x40>
nop
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    11a4 <main+0x54>

LLVM IR (-O0):
@.str = [215 x i8] c"Not only did you make it back to ground level, but you found the door to our secret research equipment. Too bad you don't have the privilege level to enter it. However you can raise the privilege level if you want.\00"
@stdin = global i32 0
@.str.1 = [54 x i8] c"Current privilege level needed to access this is %d.\0A\00"
@.str.2 = [63 x i8] c"I'm pretty sure that wasn't supposed to happen. Level Cleared!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 100, i32* %2
store i32 0, i32* %3
%5 = call i32 @puts(i8* getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %34
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1000)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 999, i32 %10)
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%13 = call i32 @atoi(i8* %12)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %6
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%17 = call i32 @atoi(i8* %16)
%18 = load i32, i32* %2
%19 = sub nsw i32 2147483647, %18
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* %2
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
%25 = add nsw i32 %22, %24
store i32 %25, i32* %2
br label %26
26: ; preds = %21, %15, %6
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
br label %6
}

LLVM IR (-O2):
@.str = [215 x i8] c"Not only did you make it back to ground level, but you found the door to our secret research equipment. Too bad you don't have the privilege level to enter it. However you can raise the privilege level if you want.\00"
@stdin = global i32 0
@.str.1 = [54 x i8] c"Current privilege level needed to access this is %d.\0A\00"
@.str.2 = [63 x i8] c"I'm pretty sure that wasn't supposed to happen. Level Cleared!\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([215 x i8], [215 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
br label %4
4: ; preds = %20, %0
%5 = phi i32 [ 100, %0 ], [ %15, %20 ]
%6 = call i32 @memset(i8* %3, i32 0, i32 1000)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %3, i32 999, i32 %7)
%9 = call i32 @atoi(i8* %3)
%10 = icmp sgt i32 %9, 0
%11 = sub nsw i32 2147483647, %5
%12 = icmp slt i32 %9, %11
%13 = select i1 %10, i1 %12, i1 false
%14 = select i1 %13, i32 %9, i32 0
%15 = add nsw i32 %14, %5
%16 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = icmp slt i32 %15, 1
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %4
br label %4
}