#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*/ flush_stdin();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ run_level(int);
int scanf(char *, int *);
int main() {
  int level;
  puts("Enter a negative integer to exit.");
  for (;;) {
    printf("Enter level: ");
    if (scanf("%d", &level) != 1) {
      puts("Please try again.");
      flush_stdin();
    } else if (level < 0) {
      puts("Goodbye!");
      break;
    } else {
      run_level(level);
      flush_stdin();
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb0(%rip),%rdi
call   1060 <printf@plt>
lea    0xeb2(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
je     11a8 <main+0x58>
lea    0xe9c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1030 <flush_stdin@plt>
jmp    11d7 <main+0x87>
cmpl   $0x0,-0x8(%rbp)
jge    11c3 <main+0x73>
lea    0xe8c(%rip),%rdi
call   1050 <puts@plt>
jmp    11dc <main+0x8c>
mov    -0x8(%rbp),%edi
call   1040 <run_level@plt>
mov    $0x0,%al
call   1030 <flush_stdin@plt>
jmp    11d7 <main+0x87>
jmp    116b <main+0x1b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1050 <puts@plt>
lea    0xeb7(%rip),%r14
lea    0xebe(%rip),%r15
lea    0x4(%rsp),%rbx
lea    0xeb5(%rip),%r12
jmp    118f <main+0x3f>
mov    %r12,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <flush_stdin@plt>
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
cmp    $0x1,%eax
jne    1180 <main+0x30>
mov    0x4(%rsp),%edi
test   %edi,%edi
js     11b6 <main+0x66>
call   1040 <run_level@plt>
jmp    1188 <main+0x38>
lea    0xe88(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter a negative integer to exit.\00"
@.str.1 = [14 x i8] c"Enter level: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"Please try again.\00"
@.str.4 = [9 x i8] c"Goodbye!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @puts(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %21, %0
%5 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (...) @flush_stdin()
br label %21
11: ; preds = %4
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %22
16: ; preds = %11
%17 = load i32, i32* %2
%18 = call i32 @run_level(i32 %17)
%19 = call i32 (...) @flush_stdin()
br label %20
20: ; preds = %16
br label %21
21: ; preds = %20, %8
br label %4
22: ; preds = %14
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter a negative integer to exit.\00"
@.str.1 = [14 x i8] c"Enter level: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [18 x i8] c"Please try again.\00"
@.str.4 = [9 x i8] c"Goodbye!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %17, %0
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %17
10: ; preds = %4
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
15: ; preds = %10
%16 = call i32 @run_level(i32 %11)
br label %17
17: ; preds = %15, %8
%18 = call i32 (...) @flush_stdin()
br label %4
}