#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*/ emit_json_command(char *, char *);
int /*<<< orphan*/ object_module_deinit();
int object_module_init();
int /*<<< orphan*/ printf(char *, ...);
int receive_bytecode();
int run();
int /*<<< orphan*/ vm_init(int);
int vm_run(int fd) {
  int ret;
  printf("Red Bank vm start...\n");
  vm_init(fd);
  emit_json_command("READY", "");
  ret = receive_bytecode();
  if (ret < 0) {
    return -1;
  }
  ret = object_module_init();
  if (ret < 0) {
    return -1;
  }
  ret = run();
  if (ret < 0) {
    return -1;
  }
  object_module_deinit();
  emit_json_command("FINISH", "SUCCESS");
  printf("Red Bank vm exits %s\n",
         (ret == 0) ? "successfully" : "with failure");
  return ret;
}


x86 assembly (clang, -O0):
<vm_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <vm_init@plt>
lea    0xe7e(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1040 <emit_json_command@plt>
mov    $0x0,%al
call   1070 <receive_bytecode@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11c4 <vm_run+0x54>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <vm_run+0xda>
mov    $0x0,%al
call   1090 <object_module_init@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e4 <vm_run+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <vm_run+0xda>
mov    $0x0,%al
call   1050 <run@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1204 <vm_run+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <vm_run+0xda>
mov    $0x0,%al
call   1080 <object_module_deinit@plt>
lea    0xe0a(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <emit_json_command@plt>
mov    -0xc(%rbp),%ecx
lea    0xe26(%rip),%rsi
lea    0xe12(%rip),%rax
cmp    $0x0,%ecx
cmove  %rax,%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vm_run>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1030 <vm_init@plt>
lea    0xe61(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1050 <emit_json_command@plt>
xor    %eax,%eax
call   1080 <receive_bytecode@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1211 <vm_run+0x91>
xor    %eax,%eax
call   10a0 <object_module_init@plt>
test   %eax,%eax
js     1211 <vm_run+0x91>
xor    %eax,%eax
call   1060 <run@plt>
test   %eax,%eax
js     1211 <vm_run+0x91>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <object_module_deinit@plt>
lea    0xe25(%rip),%rdi
lea    0xe25(%rip),%rsi
call   1050 <emit_json_command@plt>
test   %ebp,%ebp
lea    0xe35(%rip),%rax
lea    0xe3b(%rip),%rsi
cmove  %rax,%rsi
lea    0xe0d(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Red Bank vm start...\0A\00"
@.str.1 = [6 x i8] c"READY\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [7 x i8] c"FINISH\00"
@.str.4 = [8 x i8] c"SUCCESS\00"
@.str.5 = [22 x i8] c"Red Bank vm exits %s\0A\00"
@.str.6 = [13 x i8] c"successfully\00"
@.str.7 = [13 x i8] c"with failure\00"
define i32 @vm_run(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* %3
%7 = call i32 @vm_init(i32 %6)
%8 = call i32 @emit_json_command(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (...) @receive_bytecode()
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %32
13: ; preds = %1
%14 = call i32 (...) @object_module_init()
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 -1, i32* %2
br label %32
18: ; preds = %13
%19 = call i32 (...) @run()
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %2
br label %32
23: ; preds = %18
%24 = call i32 (...) @object_module_deinit()
%25 = call i32 @emit_json_command(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = load i32, i32* %4
store i32 %31, i32* %2
br label %32
32: ; preds = %23, %22, %17, %12
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"READY\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [7 x i8] c"FINISH\00"
@.str.4 = [8 x i8] c"SUCCESS\00"
@.str.5 = [22 x i8] c"Red Bank vm exits %s\0A\00"
@.str.6 = [13 x i8] c"successfully\00"
@.str.7 = [13 x i8] c"with failure\00"
@str = [21 x i8] c"Red Bank vm start...\00"
define i32 @vm_run(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @vm_init(i32 %0)
%4 = tail call i32 @emit_json_command(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 (...) @receive_bytecode()
%6 = icmp slt i32 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = tail call i32 (...) @object_module_init()
%9 = icmp slt i32 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %7
%11 = tail call i32 (...) @run()
%12 = icmp slt i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = tail call i32 (...) @object_module_deinit()
%15 = tail call i32 @emit_json_command(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i32 %11, 0
%17 = select i1 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %10, %7, %1, %13
%20 = phi i32 [ %11, %13 ], [ -1, %1 ], [ -1, %7 ], [ -1, %10 ]
ret i32 %20
}