#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*/ memory;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ decompile(char *, unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, unsigned int, int, int /*<<< orphan*/ *);
unsigned int fsize(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char memory[1024];
  FILE *fp;
  if (argc == 1) {
    printf("%s filename.com\r\n", argv[0]);
    exit(1);
  }
  memset(memory, 0, sizeof(memory));
  fp = fopen(argv[1], "rb");
  if (fp == NULL) {
    printf("Error opening file");
    return (-1);
  }
  unsigned int size = fsize(fp);
  fread(memory, size, 1, fp);
  decompile(memory, size);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c2 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1218 <main+0x98>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126d <main+0xed>
mov    -0x418(%rbp),%rdi
call   1080 <fsize@plt>
mov    %eax,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x41c(%rbp),%esi
mov    -0x418(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
lea    -0x410(%rbp),%rdi
mov    -0x41c(%rbp),%esi
call   1030 <decompile@plt>
mov    -0x418(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
je     121b <main+0x9b>
mov    %rsp,%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    0x8(%rbx),%rdi
lea    0xe5c(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11f6 <main+0x76>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <fsize@plt>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <decompile@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    120a <main+0x8a>
lea    0xe18(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"%s filename.com\0D\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Error opening file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 @memset(i8* %18, i32 0, i32 1024)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %17
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
28: ; preds = %17
%29 = load i32*, i32** %7
%30 = call i32 @fsize(i32* %29)
store i32 %30, i32* %8
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %8
%33 = load i32*, i32** %7
%34 = call i32 @fread(i8* %31, i32 %32, i32 1, i32* %33)
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call i32 @decompile(i8* %35, i32 %36)
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %28, %26
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [18 x i8] c"%s filename.com\0D\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [19 x i8] c"Error opening file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = call i32 @memset(i8* %4, i32 0, i32 1024)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %23
18: ; preds = %10
%19 = call i32 @fsize(i32* %14)
%20 = call i32 @fread(i8* %4, i32 %19, i32 1, i32* %14)
%21 = call i32 @decompile(i8* %4, i32 %19)
%22 = call i32 @fclose(i32* %14)
br label %23
23: ; preds = %18, %16
%24 = phi i32 [ -1, %16 ], [ 0, %18 ]
ret i32 %24
}