#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) {
      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    11e0 <main+0x90>
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    0xeed(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1207 <main+0xb7>
lea    0xf0b(%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
xor    %r13d,%r13d
mov    0x2e69(%rip),%rbp
lea    0xf51(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%r15d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    $0x3e7,%esi
call   1060 <fgets@plt>
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
test   %eax,%eax
cmovs  %r13d,%ebx
lea    (%rbx,%r15,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    %r15d,%ebx
jg     1190 <main+0x40>
lea    0xf33(%rip),%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x40>

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, %28
%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 %20
15: ; preds = %6
%16 = load i32, i32* %2
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
%19 = add nsw i32 %16, %18
store i32 %19, i32* %2
br label %20
20: ; preds = %15, %6
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = icmp sle i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @puts(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
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 = %17, %0
%5 = phi i32 [ 100, %0 ], [ %12, %17 ]
%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 = select i1 %10, i32 %9, i32 0
%12 = add nuw nsw i32 %11, %5
%13 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %12, 1
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %4
br label %4
}