#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 binary_exec();
int binary_init(int, char **);
int binary_load();
int /*<<< orphan*/ mem_init();
int /*<<< orphan*/ reg_init();
int /*<<< orphan*/ stack_init();
int /*<<< orphan*/ vm_fail(char *);
int main(int argc, char *argv[]) {
  int ret;
  ret = binary_init(argc, argv);
  if (ret < 0) {
    vm_fail("Please provide path to binary file ...");
  }
  reg_init();
  mem_init();
  stack_init();
  ret = binary_load();
  if (ret < 0) {
    vm_fail("Loading failed ...\n");
  }
  ret = binary_exec();
  if (ret < 0) {
    vm_fail("Execution failed ...\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <binary_init@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11ab <main+0x3b>
lea    0xe5a(%rip),%rdi
call   1030 <vm_fail@plt>
mov    $0x0,%al
call   1070 <reg_init@plt>
mov    $0x0,%al
call   1040 <mem_init@plt>
mov    $0x0,%al
call   1090 <stack_init@plt>
mov    $0x0,%al
call   1050 <binary_load@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e0 <main+0x70>
lea    0xe4c(%rip),%rdi
call   1030 <vm_fail@plt>
mov    $0x0,%al
call   1060 <binary_exec@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1200 <main+0x90>
lea    0xe40(%rip),%rdi
call   1030 <vm_fail@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
call   1080 <binary_init@plt>
test   %eax,%eax
jns    1186 <main+0x16>
lea    0xe7f(%rip),%rdi
call   1030 <vm_fail@plt>
xor    %eax,%eax
call   1070 <reg_init@plt>
xor    %eax,%eax
call   1040 <mem_init@plt>
xor    %eax,%eax
call   1090 <stack_init@plt>
xor    %eax,%eax
call   1050 <binary_load@plt>
test   %eax,%eax
jns    11b2 <main+0x42>
lea    0xe7a(%rip),%rdi
call   1030 <vm_fail@plt>
xor    %eax,%eax
call   1060 <binary_exec@plt>
test   %eax,%eax
jns    11c9 <main+0x59>
lea    0xe77(%rip),%rdi
call   1030 <vm_fail@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Please provide path to binary file ...\00"
@.str.1 = [20 x i8] c"Loading failed ...\0A\00"
@.str.2 = [22 x i8] c"Execution failed ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = load i8**, i8*** %5
%9 = call i32 @binary_init(i32 %7, i8** %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @vm_fail(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 (...) @reg_init()
%16 = call i32 (...) @mem_init()
%17 = call i32 (...) @stack_init()
%18 = call i32 (...) @binary_load()
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = call i32 @vm_fail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %14
%24 = call i32 (...) @binary_exec()
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @vm_fail(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %23
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Please provide path to binary file ...\00"
@.str.1 = [20 x i8] c"Loading failed ...\0A\00"
@.str.2 = [22 x i8] c"Execution failed ...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @binary_init(i32 %0, i8** %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @vm_fail(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = tail call i32 (...) @reg_init()
%9 = tail call i32 (...) @mem_init()
%10 = tail call i32 (...) @stack_init()
%11 = tail call i32 (...) @binary_load()
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @vm_fail(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
%16 = tail call i32 (...) @binary_exec()
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @vm_fail(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret i32 0
}