#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 uint8_t;
typedef int uint32_t;
struct stat {
  int st_size;
};
typedef int /*<<< orphan*/ ch_buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fillup_ch(int *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int optind;
int /*<<< orphan*/ parse_options(int, char **, int *, char const **, int *,
                                 int *, int *);
int /*<<< orphan*/ print_usage(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int main(int argc, char *argv[]) {
  const char *input_filename = NULL;
  const char *output_filename = NULL;
  char *filename = NULL;
  FILE *ifd = NULL;
  FILE *ofd = NULL;
  struct stat sinfo;
  uint32_t location = 0x0;
  int raw = 0;
  int sign = 0;
  int verbose = 0;
  uint32_t len;
  uint32_t word;
  uint8_t byte;
  int i;
  uint8_t ch_buffer[512];
  parse_options(argc, argv, &location, &output_filename, &raw, &sign, &verbose);
  if (optind < argc) {
    input_filename = argv[optind];
  } else {
    print_usage(argv[0], stderr, 1);
  }
  if (NULL == output_filename) {
    filename = malloc(strlen(input_filename) + 4);
    if (NULL != filename) {
      strcpy(filename, input_filename);
      strcat(filename, ".img");
    }
  } else {
    filename = malloc(strlen(output_filename));
    if (NULL != filename) {
      strcpy(filename, output_filename);
    }
  }
  if (NULL == filename) {
    fprintf(stderr, "Cannot allocate memory for file name");
    exit(1);
  }
  ofd = fopen(filename, "wb");
  if (NULL == ofd) {
    fprintf(stderr, "Cannot open %s\n", filename);
    free(filename);
    exit(1);
  }
  stat(input_filename, &sinfo);
  len = sinfo.st_size;
  if (verbose > 0) {
    fprintf(stdout, "%s -> %s\n", input_filename, filename);
  }
  fillup_ch(ch_buffer);
  ifd = fopen(input_filename, "rb");
  if (NULL == ifd) {
    fprintf(stderr, "Cannot open %s\n", input_filename);
    fclose(ofd);
    free(filename);
    exit(1);
  }
  if (raw > 0) {
    if (verbose > 0) {
      fprintf(stdout, "Making raw boot image\n");
    }
    fwrite(ch_buffer, 1, sizeof(ch_buffer), ofd);
  }
  if (sign > 0) {
    if (verbose > 0) {
      fprintf(stdout, "Adding GP Header: Size = 0x%X, Location = 0x%X\n", len,
              location);
    }
    fwrite(&len, 4, 1, ofd);
    fwrite(&location, 4, 1, ofd);
  }
  for (i = 0; i < len; i++) {
    fread(&byte, 1, 1, ifd);
    fwrite(&byte, 1, 1, ofd);
  }
  fclose(ifd);
  fclose(ofd);
  free(filename);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x44(%rbp),%rdx
lea    -0x20(%rbp),%rcx
lea    -0x48(%rbp),%r8
lea    -0x4c(%rbp),%r9
lea    -0x50(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <parse_options@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    129e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x2d5a(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    12b8 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1110 <print_usage@plt>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    130b <main+0x11b>
mov    -0x18(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,%rdi
add    $0x4,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     1306 <main+0x116>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xcff(%rip),%rsi
call   10e0 <strcat@plt>
jmp    133e <main+0x14e>
mov    -0x20(%rbp),%rdi
call   1080 <strlen@plt>
mov    %rax,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
je     1339 <main+0x149>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    133e <main+0x14e>
xor    %eax,%eax
cmp    -0x28(%rbp),%rax
jne    136b <main+0x17b>
mov    0x2c87(%rip),%rax
mov    (%rax),%edi
lea    0xcab(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xcb4(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    13b9 <main+0x1c9>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xc8e(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10b0 <stat@plt>
mov    -0x40(%rbp),%eax
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x50(%rbp)
jle    13f5 <main+0x205>
mov    0x2bf3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xc4f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x860(%rbp),%rdi
call   10a0 <fillup_ch@plt>
mov    -0x18(%rbp),%rdi
lea    0xc3b(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    1458 <main+0x268>
mov    0x2bb0(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xbf8(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x48(%rbp)
jle    149d <main+0x2ad>
cmpl   $0x0,-0x50(%rbp)
jle    1483 <main+0x293>
mov    0x2b5d(%rip),%rax
mov    (%rax),%edi
lea    0xbce(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x860(%rbp),%rdi
mov    -0x38(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1100 <fwrite@plt>
cmpl   $0x0,-0x4c(%rbp)
jle    14fc <main+0x30c>
cmpl   $0x0,-0x50(%rbp)
jle    14ce <main+0x2de>
mov    0x2b18(%rip),%rax
mov    (%rax),%edi
mov    -0x54(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    0xb9a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x38(%rbp),%rcx
lea    -0x54(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    -0x38(%rbp),%rcx
lea    -0x44(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
movl   $0x0,-0x60(%rbp)
mov    -0x60(%rbp),%eax
cmp    -0x54(%rbp),%eax
jge    1545 <main+0x355>
mov    -0x30(%rbp),%rcx
lea    -0x5c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
mov    -0x38(%rbp),%rcx
lea    -0x5c(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1100 <fwrite@plt>
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1503 <main+0x313>
mov    -0x30(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x28(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x18(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,(%rsp)
lea    0x10(%rsp),%rdx
lea    0x28(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x18(%rsp),%r9
call   1060 <parse_options@plt>
mov    0x2d80(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1275 <main+0x75>
mov    (%rbx,%rax,8),%r15
jmp    128e <main+0x8e>
mov    (%rbx),%rdi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1120 <print_usage@plt>
xor    %r15d,%r15d
mov    0x28(%rsp),%rbx
test   %rbx,%rbx
je     12c1 <main+0xc1>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %rax,%rdi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1473 <main+0x273>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    12f8 <main+0xf8>
mov    %r15,%rdi
call   1080 <strlen@plt>
lea    0x4(%rax),%rdi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1473 <main+0x273>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xd10(%rip),%rsi
mov    %r14,%rdi
call   10f0 <strcat@plt>
lea    0xd2b(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1494 <main+0x294>
mov    %rax,%r12
lea    0x20(%rsp),%rsi
mov    %r15,%rdi
call   10c0 <stat@plt>
mov    0x20(%rsp),%ebp
mov    %ebp,0x14(%rsp)
cmpl   $0x0,0xc(%rsp)
jle    134c <main+0x14c>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0x30(%rsp),%rdi
call   10b0 <fillup_ch@plt>
lea    0xcea(%rip),%rsi
mov    %r15,%rdi
call   10e0 <fopen@plt>
test   %rax,%rax
je     14b0 <main+0x2b0>
mov    %rax,%r13
cmpl   $0x0,0x1c(%rsp)
jle    13ad <main+0x1ad>
cmpl   $0x0,0xc(%rsp)
jle    1396 <main+0x196>
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
lea    0xcbb(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %r12,%rcx
call   1110 <fwrite@plt>
cmpl   $0x0,0x18(%rsp)
jle    140a <main+0x20a>
cmpl   $0x0,0xc(%rsp)
jle    13d8 <main+0x1d8>
mov    0x2c0e(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%ecx
lea    0xc92(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0x14(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1110 <fwrite@plt>
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1110 <fwrite@plt>
mov    0x14(%rsp),%ebp
test   %ebp,%ebp
jle    1447 <main+0x247>
lea    0x24(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1050 <fread@plt>
movsbl 0x24(%rsp),%edi
mov    %r12,%rsi
call   1090 <fputc@plt>
add    $0xffffffff,%ebp
jne    1420 <main+0x220>
mov    %r13,%rdi
call   1070 <fclose@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b5e(%rip),%rax
mov    (%rax),%edi
lea    0xb82(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
lea    0xb89(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    14d2 <main+0x2d2>
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
lea    0xb6d(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@optind = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c".img\00"
@.str.1 = [37 x i8] c"Cannot allocate memory for file name\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [16 x i8] c"Cannot open %s\0A\00"
@stdout = global i32 0
@.str.4 = [10 x i8] c"%s -> %s\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [23 x i8] c"Making raw boot image\0A\00"
@.str.7 = [48 x i8] c"Adding GP Header: Size = 0x%X, Location = 0x%X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca %struct.stat
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca [512 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @parse_options(i32 %21, i8** %22, i32* %12, i8** %7, i32* %13, i32* %14, i32* %15)
%24 = load i32, i32* @optind
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = load i32, i32* @optind
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
store i8* %32, i8** %6
br label %39
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i32, i32* @stderr
%38 = call i32 @print_usage(i8* %36, i32 %37, i32 1)
br label %39
39: ; preds = %33, %27
%40 = load i8*, i8** %7
%41 = icmp eq i8* null, %40
br i1 %41, label %42, label %56
42: ; preds = %39
%43 = load i8*, i8** %6
%44 = call i64 @strlen(i8* %43)
%45 = add nsw i64 %44, 4
%46 = call i8* @malloc(i64 %45)
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = icmp ne i8* null, %47
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i8*, i8** %8
%51 = load i8*, i8** %6
%52 = call i32 @strcpy(i8* %50, i8* %51)
%53 = load i8*, i8** %8
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %49, %42
br label %67
56: ; preds = %39
%57 = load i8*, i8** %7
%58 = call i64 @strlen(i8* %57)
%59 = call i8* @malloc(i64 %58)
store i8* %59, i8** %8
%60 = load i8*, i8** %8
%61 = icmp ne i8* null, %60
br i1 %61, label %62, label %66
62: ; preds = %56
%63 = load i8*, i8** %8
%64 = load i8*, i8** %7
%65 = call i32 @strcpy(i8* %63, i8* %64)
br label %66
66: ; preds = %62, %56
br label %67
67: ; preds = %66, %55
%68 = load i8*, i8** %8
%69 = icmp eq i8* null, %68
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %67
%75 = load i8*, i8** %8
%76 = call i32* @fopen(i8* %75, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %76, i32** %10
%77 = load i32*, i32** %10
%78 = icmp eq i32* null, %77
br i1 %78, label %79, label %86
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %8
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = load i8*, i8** %8
%84 = call i32 @free(i8* %83)
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %74
%87 = load i8*, i8** %6
%88 = call i32 @stat(i8* %87, %struct.stat* %11)
%89 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%90 = load i32, i32* %89
store i32 %90, i32* %16
%91 = load i32, i32* %15
%92 = icmp sgt i32 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %86
%94 = load i32, i32* @stdout
%95 = load i8*, i8** %6
%96 = load i8*, i8** %8
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %95, i8* %96)
br label %98
98: ; preds = %93, %86
%99 = getelementptr inbounds [512 x i32], [512 x i32]* %20, i64 0, i64 0
%100 = call i32 @fillup_ch(i32* %99)
%101 = load i8*, i8** %6
%102 = call i32* @fopen(i8* %101, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %102, i32** %9
%103 = load i32*, i32** %9
%104 = icmp eq i32* null, %103
br i1 %104, label %105, label %114
105: ; preds = %98
%106 = load i32, i32* @stderr
%107 = load i8*, i8** %6
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %107)
%109 = load i32*, i32** %10
%110 = call i32 @fclose(i32* %109)
%111 = load i8*, i8** %8
%112 = call i32 @free(i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %98
%115 = load i32, i32* %13
%116 = icmp sgt i32 %115, 0
br i1 %116, label %117, label %127
117: ; preds = %114
%118 = load i32, i32* %15
%119 = icmp sgt i32 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %117
%121 = load i32, i32* @stdout
%122 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %123
123: ; preds = %120, %117
%124 = getelementptr inbounds [512 x i32], [512 x i32]* %20, i64 0, i64 0
%125 = load i32*, i32** %10
%126 = call i32 @fwrite(i32* %124, i32 1, i32 2048, i32* %125)
br label %127
127: ; preds = %123, %114
%128 = load i32, i32* %14
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %143
130: ; preds = %127
%131 = load i32, i32* %15
%132 = icmp sgt i32 %131, 0
br i1 %132, label %133, label %138
133: ; preds = %130
%134 = load i32, i32* @stdout
%135 = load i32, i32* %16
%136 = load i32, i32* %12
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i32 %135, i32 %136)
br label %138
138: ; preds = %133, %130
%139 = load i32*, i32** %10
%140 = call i32 @fwrite(i32* %16, i32 4, i32 1, i32* %139)
%141 = load i32*, i32** %10
%142 = call i32 @fwrite(i32* %12, i32 4, i32 1, i32* %141)
br label %143
143: ; preds = %138, %127
store i32 0, i32* %19
br label %144
144: ; preds = %153, %143
%145 = load i32, i32* %19
%146 = load i32, i32* %16
%147 = icmp slt i32 %145, %146
br i1 %147, label %148, label %156
148: ; preds = %144
%149 = load i32*, i32** %9
%150 = call i32 @fread(i32* %18, i32 1, i32 1, i32* %149)
%151 = load i32*, i32** %10
%152 = call i32 @fwrite(i32* %18, i32 1, i32 1, i32* %151)
br label %153
153: ; preds = %148
%154 = load i32, i32* %19
%155 = add nsw i32 %154, 1
store i32 %155, i32* %19
br label %144
156: ; preds = %144
%157 = load i32*, i32** %9
%158 = call i32 @fclose(i32* %157)
%159 = load i32*, i32** %10
%160 = call i32 @fclose(i32* %159)
%161 = load i8*, i8** %8
%162 = call i32 @free(i8* %161)
%163 = load i32, i32* %3
ret i32 %163
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@optind = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c".img\00"
@.str.1 = [37 x i8] c"Cannot allocate memory for file name\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [16 x i8] c"Cannot open %s\0A\00"
@stdout = global i32 0
@.str.4 = [10 x i8] c"%s -> %s\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@.str.6 = [23 x i8] c"Making raw boot image\0A\00"
@.str.7 = [48 x i8] c"Adding GP Header: Size = 0x%X, Location = 0x%X\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [512 x i32]
%12 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%13 = bitcast %struct.stat* %4 to i8*
%14 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%15 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%16 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%17 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%18 = bitcast i32* %9 to i8*
%19 = bitcast i32* %10 to i8*
%20 = bitcast [512 x i32]* %11 to i8*
%21 = call i32 @parse_options(i32 %0, i8** %1, i32* %5, i8** %3, i32* %6, i32* %7, i32* %8)
%22 = load i32, i32* @optind
%23 = icmp slt i32 %22, %0
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
br label %32
28: ; preds = %2
%29 = load i8*, i8** %1
%30 = load i32, i32* @stderr
%31 = call i32 @print_usage(i8* %29, i32 %30, i32 1)
br label %32
32: ; preds = %28, %24
%33 = phi i8* [ %27, %24 ], [ null, %28 ]
%34 = load i8*, i8** %3
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = call i64 @strlen(i8* dereferenceable(1) %33)
%38 = add nsw i64 %37, 4
%39 = call i8* @malloc(i64 %38)
%40 = icmp eq i8* %39, null
br i1 %40, label %50, label %41
41: ; preds = %36
%42 = call i32 @strcpy(i8* %39, i8* %33)
%43 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %54
44: ; preds = %32
%45 = call i64 @strlen(i8* %34)
%46 = call i8* @malloc(i64 %45)
%47 = icmp eq i8* %46, null
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @strcpy(i8* %46, i8* %34)
br label %54
50: ; preds = %36, %44
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %41, %48
%55 = phi i8* [ %39, %41 ], [ %46, %48 ]
%56 = call i32* @fopen(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%61 = call i32 @free(i8* %55)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54
%64 = call i32 @stat(i8* %33, %struct.stat* %4)
%65 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%66 = load i32, i32* %65
store i32 %66, i32* %9
%67 = load i32, i32* %8
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = load i32, i32* @stdout
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %55)
br label %72
72: ; preds = %69, %63
%73 = getelementptr inbounds [512 x i32], [512 x i32]* %11, i64 0, i64 0
%74 = call i32 @fillup_ch(i32* %73)
%75 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %83
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%80 = call i32 @fclose(i32* %56)
%81 = call i32 @free(i8* %55)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %72
%84 = load i32, i32* %6
%85 = icmp sgt i32 %84, 0
br i1 %85, label %86, label %94
86: ; preds = %83
%87 = load i32, i32* %8
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* @stdout
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %92
92: ; preds = %89, %86
%93 = call i32 @fwrite(i32* %73, i32 1, i32 2048, i32* %56)
br label %94
94: ; preds = %92, %83
%95 = load i32, i32* %7
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %108
97: ; preds = %94
%98 = load i32, i32* %8
%99 = icmp sgt i32 %98, 0
br i1 %99, label %100, label %104
100: ; preds = %97
%101 = load i32, i32* @stdout
%102 = load i32, i32* %5
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0), i32 %66, i32 %102)
br label %104
104: ; preds = %100, %97
%105 = call i32 @fwrite(i32* %9, i32 4, i32 1, i32* %56)
%106 = call i32 @fwrite(i32* %5, i32 4, i32 1, i32* %56)
%107 = load i32, i32* %9
br label %108
108: ; preds = %104, %94
%109 = phi i32 [ %107, %104 ], [ %66, %94 ]
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %108, %111
%112 = phi i32 [ %117, %111 ], [ 0, %108 ]
%113 = call i32 @fread(i32* %10, i32 1, i32 1, i32* %75)
%114 = load i8, i8* %19
%115 = sext i8 %114 to i32
%116 = call i32 @fputc(i32 %115, i32* %56)
%117 = add nuw nsw i32 %112, 1
%118 = icmp eq i32 %117, %109
br i1 %118, label %119, label %111
119: ; preds = %111, %108
%120 = call i32 @fclose(i32* %75)
%121 = call i32 @fclose(i32* %56)
%122 = call i32 @free(i8* %55)
ret i32 0
}