#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 scalar_t__ uint8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(scalar_t__ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  printf("#include <stdint.h>\n"
         "#include <SDL.h>\n"
         "#include \"mako-vm.h\"\n"
         "#ifndef NAME\n"
         "#define NAME \"\"\n"
         "#endif\n"
         "char *argv0;\n"
         "int32_t mem[] = {");
  while (!feof(stdin)) {
    uint8_t buf[4];
    int n = fread(buf, sizeof *buf, 4, stdin);
    if (ferror(stdin))
      goto onerr;
    if (n == 0)
      break;
    if (n != 4) {
      fprintf(stderr, "%s: The file was invalid.\n", argv[0]);
      exit(1);
    }
    printf("0x%04X,", (int32_t)buf[0] << 24 | (int32_t)buf[1] << 16 |
                          (int32_t)buf[2] << 8 | (int32_t)buf[3]);
  }
  printf("0};\n"
         "int main(int argc, char **argv)\n"
         "{\n"
         "\targv0 = argv[0];\n"
         "\trun_vm(mem, NAME);\n"
         "}\n");
  exit(0);
onerr:
  perror(argv[0]);
  exit(1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b7 <main+0x47>
jmp    1266 <main+0xf6>
lea    -0x30(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    $0x8,%esi
mov    $0x4,%edx
call   1040 <fread@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11f3 <main+0x83>
jmp    127b <main+0x10b>
cmpl   $0x0,-0x34(%rbp)
jne    1202 <main+0x92>
jmp    1266 <main+0xf6>
cmpl   $0x4,-0x34(%rbp)
je     1232 <main+0xc2>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5a(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rax
mov    %eax,%esi
shl    $0x18,%esi
mov    -0x28(%rbp),%rax
shl    $0x10,%eax
or     %eax,%esi
mov    -0x20(%rbp),%rax
shl    $0x8,%eax
or     %eax,%esi
mov    -0x18(%rbp),%rax
or     %eax,%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1194 <main+0x24>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e44(%rip),%rbx
mov    (%rbx),%edi
call   1080 <feof@plt>
test   %eax,%eax
jne    121e <main+0x9e>
mov    %rsp,%r15
lea    0xedf(%rip),%r12
nopl   0x0(%rax)
mov    (%rbx),%ecx
mov    %r15,%rdi
mov    $0x8,%esi
mov    $0x4,%edx
call   1050 <fread@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1231 <main+0xb1>
cmp    $0x4,%ebp
jne    121a <main+0x9a>
mov    (%rsp),%eax
mov    0x8(%rsp),%ecx
shl    $0x18,%eax
shl    $0x10,%ecx
or     %eax,%ecx
mov    0x10(%rsp),%esi
shl    $0x8,%esi
or     %ecx,%esi
or     0x18(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%edi
call   1080 <feof@plt>
test   %eax,%eax
je     11c0 <main+0x40>
jmp    121e <main+0x9e>
test   %ebp,%ebp
jne    1243 <main+0xc3>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    (%r14),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe27(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [125 x i8] c"#include <stdint.h>\0A#include <SDL.h>\0A#include \22mako-vm.h\22\0A#ifndef NAME\0A#define NAME \22\22\0A#endif\0Achar *argv0;\0Aint32_t mem[] = {\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s: The file was invalid.\0A\00"
@.str.2 = [8 x i8] c"0x%04X,\00"
@.str.3 = [79 x i8] c"0};\0Aint main(int argc, char **argv)\0A{\0A\09argv0 = argv[0];\0A\09run_vm(mem, NAME);\0A}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i64]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %36, %2
%10 = load i32, i32* @stdin
%11 = call i32 @feof(i32 %10)
%12 = icmp ne i32 %11, 0
%13 = xor i1 %12, true
br i1 %13, label %14, label %56
14: ; preds = %9
%15 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fread(i64* %15, i32 8, i32 4, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* @stdin
%19 = call i64 @ferror(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %14
br label %59
22: ; preds = %14
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %56
26: ; preds = %22
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 4
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 0
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = shl i32 %39, 24
%41 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 1
%42 = load i64, i64* %41
%43 = trunc i64 %42 to i32
%44 = shl i32 %43, 16
%45 = or i32 %40, %44
%46 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 2
%47 = load i64, i64* %46
%48 = trunc i64 %47 to i32
%49 = shl i32 %48, 8
%50 = or i32 %45, %49
%51 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 3
%52 = load i64, i64* %51
%53 = trunc i64 %52 to i32
%54 = or i32 %50, %53
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %54)
br label %9
56: ; preds = %25, %9
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %21
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @perror(i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [125 x i8] c"#include <stdint.h>\0A#include <SDL.h>\0A#include \22mako-vm.h\22\0A#ifndef NAME\0A#define NAME \22\22\0A#endif\0Achar *argv0;\0Aint32_t mem[] = {\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"%s: The file was invalid.\0A\00"
@.str.2 = [8 x i8] c"0x%04X,\00"
@str = [78 x i8] c"0};\0Aint main(int argc, char **argv)\0A{\0A\09argv0 = argv[0];\0A\09run_vm(mem, NAME);\0A}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i64]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([125 x i8], [125 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @feof(i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %46
8: ; preds = %2
%9 = bitcast [4 x i64]* %3 to i8*
%10 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 0
%11 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 1
%12 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 2
%13 = getelementptr inbounds [4 x i64], [4 x i64]* %3, i64 0, i64 3
br label %14
14: ; preds = %8, %27
%15 = load i32, i32* @stdin
%16 = call i32 @fread(i64* %10, i32 8, i32 4, i32 %15)
%17 = load i32, i32* @stdin
%18 = call i64 @ferror(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %49
20: ; preds = %14
switch i32 %16, label %22 [
i32 0, label %21
i32 4, label %27
]
21: ; preds = %20
br label %46
22: ; preds = %20
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %1
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i64, i64* %10
%29 = trunc i64 %28 to i32
%30 = shl i32 %29, 24
%31 = load i64, i64* %11
%32 = trunc i64 %31 to i32
%33 = shl i32 %32, 16
%34 = or i32 %33, %30
%35 = load i64, i64* %12
%36 = trunc i64 %35 to i32
%37 = shl i32 %36, 8
%38 = or i32 %34, %37
%39 = load i64, i64* %13
%40 = trunc i64 %39 to i32
%41 = or i32 %38, %40
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @stdin
%44 = call i32 @feof(i32 %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %14, label %46
46: ; preds = %27, %2, %21
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @str, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
49: ; preds = %14
%50 = load i8*, i8** %1
%51 = call i32 @perror(i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
}