#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ disassemble(unsigned char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int filesize;
  unsigned char *buf = NULL;
  FILE *fh;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <binary file>\n", argv[0]);
    exit(0);
  }
  fh = fopen(argv[1], "rb");
  if (fh == NULL) {
    fprintf(stderr, "error opening file %s\n", argv[1]);
    exit(0);
  }
  fseek(fh, 0, SEEK_END);
  filesize = ftell(fh);
  fseek(fh, 0, SEEK_SET);
  buf = (unsigned char *)malloc(filesize);
  fread(buf, 1, filesize, fh);
  disassemble(buf, filesize);
  free(buf);
  fclose(fh);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11eb <main+0x4b>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe21(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1232 <main+0x92>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x14(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <disassemble@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
jne    123d <main+0x9d>
mov    0x8(%r14),%rdi
lea    0xe5e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1252 <main+0xb2>
mov    %rax,%rbx
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r14d
mov    0x2ddf(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %r14d,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   10a0 <disassemble@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdb0(%rip),%rsi
jmp    1266 <main+0xc6>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xdb6(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s <binary file>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"error opening file %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %32
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %18
%33 = load i32*, i32** %8
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %8
%37 = call i32 @ftell(i32* %36)
store i32 %37, i32* %6
%38 = load i32*, i32** %8
%39 = load i32, i32* @SEEK_SET
%40 = call i32 @fseek(i32* %38, i32 0, i32 %39)
%41 = load i32, i32* %6
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = load i32, i32* %6
%46 = load i32*, i32** %8
%47 = call i32 @fread(i8* %44, i32 1, i32 %45, i32* %46)
%48 = load i8*, i8** %7
%49 = load i32, i32* %6
%50 = call i32 @disassemble(i8* %48, i32 %49)
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s <binary file>\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [23 x i8] c"error opening file %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %9
%20 = load i32, i32* @SEEK_END
%21 = tail call i32 @fseek(i32* %12, i32 0, i32 %20)
%22 = tail call i32 @ftell(i32* %12)
%23 = load i32, i32* @SEEK_SET
%24 = tail call i32 @fseek(i32* %12, i32 0, i32 %23)
%25 = tail call i64 @malloc(i32 %22)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @fread(i8* %26, i32 1, i32 %22, i32* %12)
%28 = tail call i32 @disassemble(i8* %26, i32 %22)
%29 = tail call i32 @free(i8* %26)
%30 = tail call i32 @fclose(i32* %12)
ret i32 0
}