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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  srand(time(NULL));
  char input1[20];
  char input2[5];
  int f;
  int c = 0;
  f = rand() % 100 + 1;
  printf("We finally patched that pesky buffer overflow vulnerabillity.\n");
  fgets(input1, sizeof(input1), stdin);
  printf(input1);
  printf("So now you can do your favorite thing in the world!\n");
  fgets(input2, sizeof(input2), stdin);
  c = atoi(input2);
  if (c == f) {
    printf("If you keep on going, we will have to cancel the celebration. "
           "Level Cleared\n");
  } else {
    printf("You must really love to research.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1050 <fgets@plt>
lea    -0x20(%rbp),%rdi
call   1030 <printf@plt>
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
lea    -0x25(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1050 <fgets@plt>
lea    -0x25(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jne    1213 <main+0xb3>
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    121f <main+0xbf>
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r14d
add    $0x1,%r14d
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e25(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%edx
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1080 <atoi@plt>
cmp    %r14d,%eax
lea    0xe81(%rip),%rax
lea    0xe58(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [63 x i8] c"We finally patched that pesky buffer overflow vulnerabillity.\0A\00"
@stdin = global i32 0
@.str.1 = [53 x i8] c"So now you can do your favorite thing in the world!\0A\00"
@.str.2 = [77 x i8] c"If you keep on going, we will have to cancel the celebration. Level Cleared\0A\00"
@.str.3 = [35 x i8] c"You must really love to research.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
store i32 0, i32* %5
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 100
%10 = add nsw i32 %9, 1
store i32 %10, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 20, i32 %13)
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%16 = call i32 @printf(i8* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 5, i32 %19)
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %0
%27 = call i32 @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
br label %30
28: ; preds = %0
%29 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %26
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [62 x i8] c"We finally patched that pesky buffer overflow vulnerabillity.\00"
@str.4 = [52 x i8] c"So now you can do your favorite thing in the world!\00"
@str.5 = [34 x i8] c"You must really love to research.\00"
@str.6 = [76 x i8] c"If you keep on going, we will have to cancel the celebration. Level Cleared\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [5 x i8]
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = add nsw i32 %8, 1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %5, i32 20, i32 %11)
%13 = call i32 @printf(i8* %5)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.4, i64 0, i64 0))
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %6, i32 5, i32 %15)
%17 = call i32 @atoi(i8* %6)
%18 = icmp eq i32 %17, %9
%19 = select i1 %18, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0)
%20 = call i32 @puts(i8* dereferenceable(1) %19)
ret i32 0
}