#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*/ bufbomb_init();
int /*<<< orphan*/ fio_printf(int, char *);
scalar_t__ level1();
scalar_t__ level2();
scalar_t__ level3();
void bufbomb(void) {
  bufbomb_init();
  if (level1()) {
    fio_printf(1, "Fail, try again!\n\r");
    return;
  }
  fio_printf(1, "You pass level1!\n\r");
  if (level2()) {
    fio_printf(1, "Fail, try again!\n\r");
    return;
  }
  fio_printf(1, "You pass level2!\n\r");
  if (level3()) {
    fio_printf(1, "Fail, try again!\n\r");
    return;
  }
  fio_printf(1, "You pass level3!\n\r");
  fio_printf(1, "Congratulation! You finish this job!\n\r");
  return;
}


x86 assembly (clang, -O0):
<bufbomb>:
push   %rbp
mov    %rsp,%rbp
mov    $0x0,%al
call   1070 <bufbomb_init@plt>
mov    $0x0,%al
call   1040 <level1@plt>
cmp    $0x0,%rax
je     1182 <bufbomb+0x32>
mov    $0x1,%edi
lea    0xe88(%rip),%rsi
call   1050 <fio_printf@plt>
jmp    1214 <bufbomb+0xc4>
mov    $0x1,%edi
lea    0xe85(%rip),%rsi
call   1050 <fio_printf@plt>
mov    $0x0,%al
call   1060 <level2@plt>
cmp    $0x0,%rax
je     11ba <bufbomb+0x6a>
mov    $0x1,%edi
lea    0xe50(%rip),%rsi
call   1050 <fio_printf@plt>
jmp    1214 <bufbomb+0xc4>
mov    $0x1,%edi
lea    0xe60(%rip),%rsi
call   1050 <fio_printf@plt>
mov    $0x0,%al
call   1030 <level3@plt>
cmp    $0x0,%rax
je     11f2 <bufbomb+0xa2>
mov    $0x1,%edi
lea    0xe18(%rip),%rsi
call   1050 <fio_printf@plt>
jmp    1214 <bufbomb+0xc4>
mov    $0x1,%edi
lea    0xe3b(%rip),%rsi
call   1050 <fio_printf@plt>
mov    $0x1,%edi
lea    0xe3d(%rip),%rsi
call   1050 <fio_printf@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufbomb>:
push   %rbx
xor    %eax,%eax
call   1070 <bufbomb_init@plt>
xor    %eax,%eax
call   1040 <level1@plt>
lea    0xe9a(%rip),%rbx
test   %rax,%rax
jne    11bd <bufbomb+0x6d>
lea    0xea1(%rip),%rsi
mov    $0x1,%edi
call   1050 <fio_printf@plt>
xor    %eax,%eax
call   1060 <level2@plt>
test   %rax,%rax
jne    11bd <bufbomb+0x6d>
lea    0xe97(%rip),%rsi
mov    $0x1,%edi
call   1050 <fio_printf@plt>
xor    %eax,%eax
call   1030 <level3@plt>
test   %rax,%rax
jne    11bd <bufbomb+0x6d>
lea    0xe8d(%rip),%rsi
mov    $0x1,%edi
call   1050 <fio_printf@plt>
lea    0xe8f(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1050 <fio_printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Fail, try again!\0A\0D\00"
@.str.1 = [19 x i8] c"You pass level1!\0A\0D\00"
@.str.2 = [19 x i8] c"You pass level2!\0A\0D\00"
@.str.3 = [19 x i8] c"You pass level3!\0A\0D\00"
@.str.4 = [39 x i8] c"Congratulation! You finish this job!\0A\0D\00"
define void @bufbomb() {
%1 = call i32 (...) @bufbomb_init()
%2 = call i64 (...) @level1()
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %21
6: ; preds = %0
%7 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = call i64 (...) @level2()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %21
12: ; preds = %6
%13 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%14 = call i64 (...) @level3()
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %21
18: ; preds = %12
%19 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %18, %16, %10, %4
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"Fail, try again!\0A\0D\00"
@.str.1 = [19 x i8] c"You pass level1!\0A\0D\00"
@.str.2 = [19 x i8] c"You pass level2!\0A\0D\00"
@.str.3 = [19 x i8] c"You pass level3!\0A\0D\00"
@.str.4 = [39 x i8] c"Congratulation! You finish this job!\0A\0D\00"
define void @bufbomb() {
%1 = tail call i32 (...) @bufbomb_init()
%2 = tail call i64 (...) @level1()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0
%5 = tail call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i64 (...) @level2()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = tail call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i64 (...) @level3()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @fio_printf(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %8, %4, %0, %12
%15 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %4 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %8 ]
%16 = tail call i32 @fio_printf(i32 1, i8* %15)
ret void
}