#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int arc, char **argv) {
  FILE *fp = fopen("assets/DMG_ROM.bin", "r");
  char romBuffer[256];
  for (int i = 0; i < 256; i++) {
    int fileChar = fgetc(fp);
    if (fileChar == EOF)
      break;
    romBuffer[i] = (char)fileChar;
    printf("%x ", romBuffer[i] & 0xff);
  }
  printf("\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x124(%rbp)
cmpl   $0x100,-0x124(%rbp)
jge    1200 <main+0xc0>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x128(%rbp)
mov    -0x128(%rbp),%eax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
jne    11b3 <main+0x73>
jmp    1200 <main+0xc0>
mov    -0x128(%rbp),%eax
mov    %al,%cl
movslq -0x124(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
movslq -0x124(%rbp),%rax
movsbl -0x120(%rbp,%rax,1),%esi
ff
and    $0xff,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    117a <main+0x3a>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    $0x100,%ebp
mov    0x2e6f(%rip),%r15
lea    0xe95(%rip),%r14
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%eax
je     119f <main+0x4f>
movzbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"assets/DMG_ROM.bin\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%x \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
store i32 0, i32* %8
br label %11
11: ; preds = %34, %2
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %37
14: ; preds = %11
%15 = load i32*, i32** %6
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
br label %37
21: ; preds = %14
%22 = load i32, i32* %9
%23 = trunc i32 %22 to i8
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %25
store i8 %23, i8* %26
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = and i32 %31, 255
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %21
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 1
store i32 %36, i32* %8
br label %11
37: ; preds = %20, %11
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"assets/DMG_ROM.bin\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%x \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %4
4: ; preds = %2, %9
%5 = phi i32 [ 0, %2 ], [ %12, %9 ]
%6 = tail call i32 @fgetc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = and i32 %6, 255
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = add nuw nsw i32 %5, 1
%13 = icmp eq i32 %12, 256
br i1 %13, label %14, label %4
14: ; preds = %4, %9
%15 = tail call i32 @putchar(i32 10)
%16 = tail call i32 @fclose(i32* %3)
ret i32 0
}