#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, long, int, int /*<<< orphan*/ *);
unsigned char *malloc(long);
int /*<<< orphan*/ memcpy(unsigned char *, void *, long);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char *name = NULL;
  FILE *in;
  int mod = 0;
  if (argc > 1) {
    name = argv[1];
    if (argc > 2) {
      if (!strcmp(argv[2], "mod"))
        mod = 1;
    }
  }
  in = fopen(name, "rb");
  if (!in) {
    printf("couldn't open '%s' !\n", name);
  } else {
    long sizef, i;
    unsigned char *buf;
    fseek(in, 0, SEEK_END);
    sizef = ftell(in);
    if (sizef < 3) {
      printf("file is too small !\n");
      exit(42);
    };
    rewind(in);
    buf = malloc(sizef);
    if (buf) {
      int sum = 0;
      char sizes;
      long sizeb;
      int should_mod = 0;
      unsigned char pad = 0;
      fread(buf, sizef, 1, in);
      if ((buf[0] != 0x55) || (buf[1] != 0xAA)) {
        printf("file is not a ROM extension !\n");
        exit(42);
      }
      sizes = buf[2];
      ;
      if (!sizes)
        sizes = sizef / 512 + 1;
      ;
      sizeb = sizes * 512;
      if (sizef < sizeb) {
        void *old = buf;
        buf = malloc(sizeb);
        memset(buf, 0, sizeb);
        memcpy(buf, old, sizef);
        free(old);
        sizef = sizeb;
      }
      for (i = 0; i < sizeb; i++) {
        unsigned char c;
        c = buf[i];
        sum += c;
      };
      if (sum % 256) {
        pad = -sum;
        printf("sum mismatch should be %04X\n", (unsigned short)pad);
        should_mod = 1;
      } else {
        ;
      }
      if (should_mod) {
        if (mod) {
          fclose(in);
          in = fopen(name, "rb+");
          buf[2] = sizes;
          buf[sizeb - 2] = 0;
          buf[sizeb - 1] = pad;
          fwrite(buf, sizef, 1, in);
          ;
        } else
          printf("invalid ROM, please use mod argument to fix\n");
      } else
        printf("file is a valid ROM extension\n");
      free(buf);
    }
    fclose(in);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1253 <main+0x73>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    124e <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdcc(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1249 <main+0x69>
movl   $0x1,-0x24(%rbp)
jmp    124e <main+0x6e>
jmp    1253 <main+0x73>
mov    -0x18(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1289 <main+0xa9>
mov    -0x18(%rbp),%rsi
lea    0xd8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1507 <main+0x327>
mov    -0x20(%rbp),%rdi
mov    0x2d54(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   10a0 <ftell@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x3,-0x30(%rbp)
jge    12cd <main+0xed>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2a,%edi
call   10f0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1070 <rewind@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     14fe <main+0x31e>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x54(%rbp)
movb   $0x0,-0x55(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x55,%eax
jne    1339 <main+0x159>
mov    -0x40(%rbp),%rax
movzbl 0x1(%rax),%eax
cmp    $0xaa,%eax
je     1351 <main+0x171>
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2a,%edi
call   10f0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x45(%rbp)
cmpb   $0x0,-0x45(%rbp)
jne    137a <main+0x19a>
mov    -0x30(%rbp),%rax
mov    $0x200,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    %al,-0x45(%rbp)
movsbl -0x45(%rbp),%eax
shl    $0x9,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x50(%rbp),%rax
jge    13db <main+0x1fb>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x50(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rdx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x40(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10b0 <memcpy@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x50(%rbp),%rax
jge    141a <main+0x23a>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x61(%rbp)
movzbl -0x61(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    13e3 <main+0x203>
mov    -0x44(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1457 <main+0x277>
xor    %eax,%eax
sub    -0x44(%rbp),%eax
mov    %al,-0x55(%rbp)
movzbl -0x55(%rbp),%eax
movzwl %ax,%esi
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x54(%rbp)
jmp    145c <main+0x27c>
jmp    145c <main+0x27c>
cmpl   $0x0,-0x54(%rbp)
je     14e7 <main+0x307>
cmpl   $0x0,-0x24(%rbp)
je     14d4 <main+0x2f4>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xbea(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x45(%rbp),%cl
mov    -0x40(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    $0x2,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x55(%rbp),%dl
mov    -0x40(%rbp),%rax
mov    -0x50(%rbp),%rcx
sub    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1100 <fwrite@plt>
jmp    14e2 <main+0x302>
lea    0xb97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14f5 <main+0x315>
lea    0xbb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%r14b
cmp    $0x2,%edi
jl     1224 <main+0x34>
mov    0x8(%rsi),%rbp
je     1226 <main+0x36>
mov    0x10(%rsi),%rdi
lea    0xde9(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
setne  %r14b
jmp    1226 <main+0x36>
xor    %ebp,%ebp
lea    0xdd7(%rip),%rsi
mov    %rbp,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1333 <main+0x143>
mov    %rax,%r15
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10e0 <fseek@plt>
mov    %r15,%rdi
call   10b0 <ftell@plt>
cmp    $0x2,%rax
jle    13f6 <main+0x206>
mov    %rax,%r12
mov    %r15,%rdi
call   1080 <rewind@plt>
mov    %r12,%rdi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1459 <main+0x269>
mov    %rax,%rbx
mov    %r14b,0xf(%rsp)
mov    %rax,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
cmpb   $0x55,(%rbx)
jne    13ed <main+0x1fd>
cmpb   $0xaa,0x1(%rbx)
jne    13ed <main+0x1fd>
movzbl 0x2(%rbx),%eax
mov    %r12,%rcx
shr    $0x9,%rcx
add    $0x1,%cl
test   %al,%al
movzbl %cl,%r14d
cmovne %eax,%r14d
movsbq %r14b,%r13
shl    $0x9,%r13
cmp    %r13,%r12
mov    %rbp,0x10(%rsp)
jge    130e <main+0x11e>
mov    %r13,%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r13,%rdx
call   1090 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10c0 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%r12
mov    %rbp,%rbx
test   %r14b,%r14b
jle    1445 <main+0x255>
cmp    $0x2,%r13
mov    $0x1,%eax
cmovge %r13,%rax
cmp    $0x8,%rax
jae    1349 <main+0x159>
xor    %ebp,%ebp
xor    %ecx,%ecx
jmp    140c <main+0x21c>
lea    0xccd(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1461 <main+0x271>
movabs $0x7ffffffffffffe00,%rcx
ff ff 7f
and    %rax,%rcx
lea    -0x8(%rcx),%rdx
shr    $0x3,%rdx
pxor   %xmm0,%xmm0
mov    $0xffffffffffffffff,%rsi
pxor   %xmm2,%xmm2
pxor   %xmm1,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movd   0x8(%rbx,%rsi,8),%xmm3
movd   0xc(%rbx,%rsi,8),%xmm4
punpcklbw %xmm0,%xmm3
punpcklwd %xmm0,%xmm3
paddd  %xmm2,%xmm3
punpcklbw %xmm0,%xmm4
punpcklwd %xmm0,%xmm4
paddd  %xmm1,%xmm4
movd   0x10(%rbx,%rsi,8),%xmm2
movd   0x14(%rbx,%rsi,8),%xmm1
punpcklbw %xmm0,%xmm2
punpcklwd %xmm0,%xmm2
paddd  %xmm3,%xmm2
punpcklbw %xmm0,%xmm1
punpcklwd %xmm0,%xmm1
paddd  %xmm4,%xmm1
add    $0x2,%rsi
cmp    %rsi,%rdx
jne    1380 <main+0x190>
paddd  %xmm2,%xmm1
pshufd $0xee,%xmm1,%xmm0
paddd  %xmm1,%xmm0
pshufd $0x55,%xmm0,%xmm1
paddd  %xmm0,%xmm1
movd   %xmm1,%ebp
jmp    1416 <main+0x226>
lea    0xc94(%rip),%rdi
jmp    13fd <main+0x20d>
lea    0xca9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2a,%edi
call   1100 <exit@plt>
movzbl (%rbx,%rcx,1),%edx
add    %edx,%ebp
add    $0x1,%rcx
cmp    %rcx,%rax
jne    140c <main+0x21c>
test   %bpl,%bpl
je     1445 <main+0x255>
neg    %bpl
movzbl %bpl,%esi
lea    0xbef(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpb   $0x0,0xf(%rsp)
je     1472 <main+0x282>
lea    0xc19(%rip),%rdi
jmp    144c <main+0x25c>
lea    0xbf2(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xbb9(%rip),%rsi
mov    0x10(%rsp),%rdi
call   10f0 <fopen@plt>
mov    %rax,%r15
mov    %r14b,0x2(%rbx)
movb   $0x0,-0x2(%r13,%rbx,1)
mov    %bpl,-0x1(%r13,%rbx,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1110 <fwrite@plt>
jmp    1451 <main+0x261>

LLVM IR (-O0):
@.str = [4 x i8] c"mod\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"couldn't open '%s' !\0A\00"
@SEEK_END = global i32 0
@.str.3 = [21 x i8] c"file is too small !\0A\00"
@.str.4 = [31 x i8] c"file is not a ROM extension !\0A\00"
@.str.5 = [29 x i8] c"sum mismatch should be %04X\0A\00"
@.str.6 = [4 x i8] c"rb+\00"
@.str.7 = [45 x i8] c"invalid ROM, please use mod argument to fix\0A\00"
@.str.8 = [31 x i8] c"file is a valid ROM extension\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8
%14 = alloca i64
%15 = alloca i32
%16 = alloca i8
%17 = alloca i8*
%18 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %8
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %36
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 2
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %27
store i32 1, i32* %8
br label %34
34: ; preds = %33, %27
br label %35
35: ; preds = %34, %21
br label %36
36: ; preds = %35, %2
%37 = load i8*, i8** %6
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %7
%40 = icmp ne i32* %39, null
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i8*, i8** %6
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %182
44: ; preds = %36
%45 = load i32*, i32** %7
%46 = load i32, i32* @SEEK_END
%47 = call i32 @fseek(i32* %45, i32 0, i32 %46)
%48 = load i32*, i32** %7
%49 = call i64 @ftell(i32* %48)
store i64 %49, i64* %9
%50 = load i64, i64* %9
%51 = icmp slt i64 %50, 3
br i1 %51, label %52, label %55
52: ; preds = %44
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 42)
unreachable
55: ; preds = %44
%56 = load i32*, i32** %7
%57 = call i32 @rewind(i32* %56)
%58 = load i64, i64* %9
%59 = call i8* @malloc(i64 %58)
store i8* %59, i8** %11
%60 = load i8*, i8** %11
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %179
62: ; preds = %55
store i32 0, i32* %12
store i32 0, i32* %15
store i8 0, i8* %16
%63 = load i8*, i8** %11
%64 = load i64, i64* %9
%65 = load i32*, i32** %7
%66 = call i32 @fread(i8* %63, i64 %64, i32 1, i32* %65)
%67 = load i8*, i8** %11
%68 = getelementptr inbounds i8, i8* %67, i64 0
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = icmp ne i32 %70, 85
br i1 %71, label %78, label %72
72: ; preds = %62
%73 = load i8*, i8** %11
%74 = getelementptr inbounds i8, i8* %73, i64 1
%75 = load i8, i8* %74
%76 = zext i8 %75 to i32
%77 = icmp ne i32 %76, 170
br i1 %77, label %78, label %81
78: ; preds = %72, %62
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%80 = call i32 @exit(i32 42)
unreachable
81: ; preds = %72
%82 = load i8*, i8** %11
%83 = getelementptr inbounds i8, i8* %82, i64 2
%84 = load i8, i8* %83
store i8 %84, i8* %13
%85 = load i8, i8* %13
%86 = icmp ne i8 %85, 0
br i1 %86, label %92, label %87
87: ; preds = %81
%88 = load i64, i64* %9
%89 = sdiv i64 %88, 512
%90 = add nsw i64 %89, 1
%91 = trunc i64 %90 to i8
store i8 %91, i8* %13
br label %92
92: ; preds = %87, %81
%93 = load i8, i8* %13
%94 = sext i8 %93 to i32
%95 = mul nsw i32 %94, 512
%96 = sext i32 %95 to i64
store i64 %96, i64* %14
%97 = load i64, i64* %9
%98 = load i64, i64* %14
%99 = icmp slt i64 %97, %98
br i1 %99, label %100, label %114
100: ; preds = %92
%101 = load i8*, i8** %11
store i8* %101, i8** %17
%102 = load i64, i64* %14
%103 = call i8* @malloc(i64 %102)
store i8* %103, i8** %11
%104 = load i8*, i8** %11
%105 = load i64, i64* %14
%106 = call i32 @memset(i8* %104, i32 0, i64 %105)
%107 = load i8*, i8** %11
%108 = load i8*, i8** %17
%109 = load i64, i64* %9
%110 = call i32 @memcpy(i8* %107, i8* %108, i64 %109)
%111 = load i8*, i8** %17
%112 = call i32 @free(i8* %111)
%113 = load i64, i64* %14
store i64 %113, i64* %9
br label %114
114: ; preds = %100, %92
store i64 0, i64* %10
br label %115
115: ; preds = %128, %114
%116 = load i64, i64* %10
%117 = load i64, i64* %14
%118 = icmp slt i64 %116, %117
br i1 %118, label %119, label %131
119: ; preds = %115
%120 = load i8*, i8** %11
%121 = load i64, i64* %10
%122 = getelementptr inbounds i8, i8* %120, i64 %121
%123 = load i8, i8* %122
store i8 %123, i8* %18
%124 = load i8, i8* %18
%125 = zext i8 %124 to i32
%126 = load i32, i32* %12
%127 = add nsw i32 %126, %125
store i32 %127, i32* %12
br label %128
128: ; preds = %119
%129 = load i64, i64* %10
%130 = add nsw i64 %129, 1
store i64 %130, i64* %10
br label %115
131: ; preds = %115
%132 = load i32, i32* %12
%133 = srem i32 %132, 256
%134 = icmp ne i32 %133, 0
br i1 %134, label %135, label %143
135: ; preds = %131
%136 = load i32, i32* %12
%137 = sub nsw i32 0, %136
%138 = trunc i32 %137 to i8
store i8 %138, i8* %16
%139 = load i8, i8* %16
%140 = zext i8 %139 to i16
%141 = zext i16 %140 to i32
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %141)
store i32 1, i32* %15
br label %144
143: ; preds = %131
br label %144
144: ; preds = %143, %135
%145 = load i32, i32* %15
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %174
147: ; preds = %144
%148 = load i32, i32* %8
%149 = icmp ne i32 %148, 0
br i1 %149, label %150, label %171
150: ; preds = %147
%151 = load i32*, i32** %7
%152 = call i32 @fclose(i32* %151)
%153 = load i8*, i8** %6
%154 = call i32* @fopen(i8* %153, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
store i32* %154, i32** %7
%155 = load i8, i8* %13
%156 = load i8*, i8** %11
%157 = getelementptr inbounds i8, i8* %156, i64 2
store i8 %155, i8* %157
%158 = load i8*, i8** %11
%159 = load i64, i64* %14
%160 = sub nsw i64 %159, 2
%161 = getelementptr inbounds i8, i8* %158, i64 %160
store i8 0, i8* %161
%162 = load i8, i8* %16
%163 = load i8*, i8** %11
%164 = load i64, i64* %14
%165 = sub nsw i64 %164, 1
%166 = getelementptr inbounds i8, i8* %163, i64 %165
store i8 %162, i8* %166
%167 = load i8*, i8** %11
%168 = load i64, i64* %9
%169 = load i32*, i32** %7
%170 = call i32 @fwrite(i8* %167, i64 %168, i32 1, i32* %169)
br label %173
171: ; preds = %147
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0))
br label %173
173: ; preds = %171, %150
br label %176
174: ; preds = %144
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
br label %176
176: ; preds = %174, %173
%177 = load i8*, i8** %11
%178 = call i32 @free(i8* %177)
br label %179
179: ; preds = %176, %55
%180 = load i32*, i32** %7
%181 = call i32 @fclose(i32* %180)
br label %182
182: ; preds = %179, %41
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"mod\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"couldn't open '%s' !\0A\00"
@SEEK_END = global i32 0
@.str.5 = [29 x i8] c"sum mismatch should be %04X\0A\00"
@.str.6 = [4 x i8] c"rb+\00"
@str = [30 x i8] c"file is a valid ROM extension\00"
@str.9 = [44 x i8] c"invalid ROM, please use mod argument to fix\00"
@str.10 = [30 x i8] c"file is not a ROM extension !\00"
@str.11 = [20 x i8] c"file is too small !\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br label %13
13: ; preds = %8, %4, %2
%14 = phi i1 [ true, %4 ], [ true, %2 ], [ %12, %8 ]
%15 = phi i8* [ %6, %4 ], [ null, %2 ], [ %6, %8 ]
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %145
20: ; preds = %13
%21 = load i32, i32* @SEEK_END
%22 = tail call i32 @fseek(i32* %16, i32 0, i32 %21)
%23 = tail call i64 @ftell(i32* %16)
%24 = icmp slt i64 %23, 3
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.11, i64 0, i64 0))
%27 = tail call i32 @exit(i32 42)
unreachable
28: ; preds = %20
%29 = tail call i32 @rewind(i32* %16)
%30 = tail call i8* @malloc(i64 %23)
%31 = icmp eq i8* %30, null
br i1 %31, label %142, label %32
32: ; preds = %28
%33 = tail call i32 @fread(i8* %30, i64 %23, i32 1, i32* %16)
%34 = load i8, i8* %30
%35 = icmp eq i8 %34, 85
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = getelementptr inbounds i8, i8* %30, i64 1
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, -86
br i1 %39, label %43, label %40
40: ; preds = %36, %32
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.10, i64 0, i64 0))
%42 = tail call i32 @exit(i32 42)
unreachable
43: ; preds = %36
%44 = getelementptr inbounds i8, i8* %30, i64 2
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
%47 = lshr i64 %23, 9
%48 = trunc i64 %47 to i8
%49 = add i8 %48, 1
%50 = select i1 %46, i8 %49, i8 %45
%51 = sext i8 %50 to i32
%52 = shl nsw i32 %51, 9
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %23, %53
br i1 %54, label %55, label %60
55: ; preds = %43
%56 = tail call i8* @malloc(i64 %53)
%57 = tail call i32 @memset(i8* %56, i32 0, i64 %53)
%58 = tail call i32 @memcpy(i8* %56, i8* %30, i64 %23)
%59 = tail call i32 @free(i8* %30)
br label %60
60: ; preds = %55, %43
%61 = phi i64 [ %53, %55 ], [ %23, %43 ]
%62 = phi i8* [ %56, %55 ], [ %30, %43 ]
%63 = icmp sgt i8 %50, 0
br i1 %63, label %64, label %137
64: ; preds = %60
%65 = call i64 @llvm.smax.i64(i64 %53, i64 1)
%66 = icmp ult i64 %65, 8
br i1 %66, label %105, label %67
67: ; preds = %64
%68 = and i64 %65, 9223372036854775296
%69 = add nsw i64 %68, -8
%70 = lshr exact i64 %69, 3
br label %71
71: ; preds = %71, %67
%72 = phi i64 [ 0, %67 ], [ %97, %71 ]
%73 = phi <4 x i32> [ zeroinitializer, %67 ], [ %95, %71 ]
%74 = phi <4 x i32> [ zeroinitializer, %67 ], [ %96, %71 ]
%75 = phi i64 [ 0, %67 ], [ %98, %71 ]
%76 = getelementptr inbounds i8, i8* %62, i64 %72
%77 = bitcast i8* %76 to <4 x i8>*
%78 = load <4 x i8>, <4 x i8>* %77
%79 = getelementptr inbounds i8, i8* %76, i64 4
%80 = bitcast i8* %79 to <4 x i8>*
%81 = load <4 x i8>, <4 x i8>* %80
%82 = zext <4 x i8> %78 to <4 x i32>
%83 = zext <4 x i8> %81 to <4 x i32>
%84 = add <4 x i32> %73, %82
%85 = add <4 x i32> %74, %83
%86 = or i64 %72, 8
%87 = getelementptr inbounds i8, i8* %62, i64 %86
%88 = bitcast i8* %87 to <4 x i8>*
%89 = load <4 x i8>, <4 x i8>* %88
%90 = getelementptr inbounds i8, i8* %87, i64 4
%91 = bitcast i8* %90 to <4 x i8>*
%92 = load <4 x i8>, <4 x i8>* %91
%93 = zext <4 x i8> %89 to <4 x i32>
%94 = zext <4 x i8> %92 to <4 x i32>
%95 = add <4 x i32> %84, %93
%96 = add <4 x i32> %85, %94
%97 = add nuw nsw i64 %72, 16
%98 = add nuw nsw i64 %75, 2
%99 = or i64 %75, 1
%100 = icmp eq i64 %99, %70
br i1 %100, label %101, label %71
101: ; preds = %71
%102 = add <4 x i32> %96, %95
%103 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %102)
%104 = icmp eq i64 %65, %68
br i1 %104, label %117, label %105
105: ; preds = %64, %101
%106 = phi i32 [ 0, %64 ], [ %103, %101 ]
%107 = phi i64 [ 0, %64 ], [ %68, %101 ]
br label %108
108: ; preds = %105, %108
%109 = phi i32 [ %114, %108 ], [ %106, %105 ]
%110 = phi i64 [ %115, %108 ], [ %107, %105 ]
%111 = getelementptr inbounds i8, i8* %62, i64 %110
%112 = load i8, i8* %111
%113 = zext i8 %112 to i32
%114 = add nuw nsw i32 %109, %113
%115 = add nuw nsw i64 %110, 1
%116 = icmp eq i64 %115, %65
br i1 %116, label %117, label %108
117: ; preds = %108, %101
%118 = phi i32 [ %103, %101 ], [ %114, %108 ]
%119 = and i32 %118, 255
%120 = icmp eq i32 %119, 0
br i1 %120, label %137, label %121
121: ; preds = %117
%122 = trunc i32 %118 to i8
%123 = sub i8 0, %122
%124 = zext i8 %123 to i32
%125 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i32 %124)
br i1 %14, label %135, label %126
126: ; preds = %121
%127 = tail call i32 @fclose(i32* %16)
%128 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%129 = getelementptr inbounds i8, i8* %62, i64 2
store i8 %50, i8* %129
%130 = add nsw i64 %53, -2
%131 = getelementptr inbounds i8, i8* %62, i64 %130
store i8 0, i8* %131
%132 = add nsw i64 %53, -1
%133 = getelementptr inbounds i8, i8* %62, i64 %132
store i8 %123, i8* %133
%134 = tail call i32 @fwrite(i8* %62, i64 %61, i32 1, i32* %128)
br label %139
135: ; preds = %121
%136 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.9, i64 0, i64 0))
br label %139
137: ; preds = %60, %117
%138 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %139
139: ; preds = %126, %135, %137
%140 = phi i32* [ %128, %126 ], [ %16, %135 ], [ %16, %137 ]
%141 = tail call i32 @free(i8* %62)
br label %142
142: ; preds = %139, %28
%143 = phi i32* [ %140, %139 ], [ %16, %28 ]
%144 = tail call i32 @fclose(i32* %143)
br label %145
145: ; preds = %142, %18
ret i32 0
}