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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read_hex_file(int /*<<< orphan*/ *, unsigned char *, int, int, int,
                  int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
void *strtoul(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  uint32_t bin_offset = 0;
  uint32_t size = (1 << 23);
  uint32_t highest = 0;
  int segment = -1;
  int help = 0;
  int fill = 0xFF;
  int unnamed = 0;
  int size_set = 0;
  char name_in[1024];
  char name_out[1024];
  unsigned char *buffer;
  int records = 0;
  FILE *fi, *fo;
  if (argc == 1)
    help = 1;
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '-') {
      switch (argv[i][1]) {
      case 'o':
        if (i != (argc - 1)) {
          bin_offset = strtoul(argv[i + 1], 0, 0);
          i++;
        } else {
          printf("-o option: no offset given.\n");
          exit(1);
        }
        break;
      case 'h':
        help = 1;
        break;
      case 's':
        if (i != (argc - 1)) {
          size = strtoul(argv[i + 1], 0, 0);
          size_set = 1;
          i++;
        } else {
          printf("-s option: no size given.\n");
          exit(1);
        }
        break;
      case 'f':
        if (i != (argc - 1)) {
          fill = strtoul(argv[i + 1], 0, 0);
          i++;
        } else {
          printf("-f option: no fill uint8_t given.\n");
          exit(1);
        }
        break;
      case 'r':
        printf("Enabled generating record structs\n");
        records = 1;
        break;
      default:
        printf("Unknown option %s given.\n", argv[i]);
        exit(2);
      }
    } else {
      switch (unnamed) {
      case 0:
        strncpy(name_in, argv[i], 1024);
        break;
      case 1:
        strncpy(name_out, argv[i], 1024);
        break;
      default:
        printf("Superfluous argument %s.\n", argv[i]);
        exit(3);
      }
      unnamed++;
    }
  }
  if (help) {
    fprintf(stderr,
            "Usage: %s [-o <bin offset>] [-s <size>] \n\t\t[-h] <infile> "
            "<outfile>\n",
            argv[0]);
    fprintf(stderr, "\t-h shows this help.\n");
    return 1;
  }
  fi = fopen(name_in, "r");
  if (!fi) {
    fprintf(stderr, "Can't open '%s' as input.\n", name_in);
    exit(-1);
  }
  fo = fopen(name_out, "wb");
  if (!fo) {
    fprintf(stderr, "Can't open '%s' as output.\n", name_out);
    exit(-1);
  }
  buffer = malloc(size + 64);
  memset(buffer, (fill & 0xFF), size + 64);
  highest = read_hex_file(fi, buffer, bin_offset, size, records, fo);
  if (!records) {
    if (size_set) {
      fwrite(buffer, 1, size, fo);
    } else {
      fwrite(buffer, 1, highest + 1, fo);
    }
  }
  free(buffer);
  fclose(fo);
  fclose(fi);
  return 0;
}


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)
movl   $0x0,-0x18(%rbp)
movl   $0x800000,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0xff,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x84c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    122c <main+0x6c>
movl   $0x1,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14a5 <main+0x2e5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    13f7 <main+0x237>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x868(%rbp)
sub    $0xd,%eax
ja     13ce <main+0x20e>
mov    -0x868(%rbp),%rax
lea    0xd76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     12cf <main+0x10f>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12e7 <main+0x127>
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13f2 <main+0x232>
movl   $0x1,-0x28(%rbp)
jmp    13f2 <main+0x232>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     133b <main+0x17b>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1353 <main+0x193>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13f2 <main+0x232>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1394 <main+0x1d4>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13ac <main+0x1ec>
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13f2 <main+0x232>
lea    0xcdb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x84c(%rbp)
jmp    13f2 <main+0x232>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    1492 <main+0x2d2>
mov    -0x30(%rbp),%eax
mov    %eax,-0x86c(%rbp)
test   %eax,%eax
je     1421 <main+0x261>
jmp    140d <main+0x24d>
mov    -0x86c(%rbp),%eax
sub    $0x1,%eax
je     1443 <main+0x283>
jmp    1465 <main+0x2a5>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x400,%edx
call   1040 <strncpy@plt>
jmp    1489 <main+0x2c9>
lea    -0x840(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x400,%edx
call   1040 <strncpy@plt>
jmp    1489 <main+0x2c9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1497 <main+0x2d7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1233 <main+0x73>
cmpl   $0x0,-0x28(%rbp)
je     14f0 <main+0x330>
mov    0x2b2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc24(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b0c(%rip),%rax
mov    (%rax),%edi
lea    0xc51(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    166c <main+0x4ac>
lea    -0x440(%rbp),%rdi
lea    0xc46(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x858(%rbp)
cmpq   $0x0,-0x858(%rbp)
jne    1540 <main+0x380>
mov    0x2ac1(%rip),%rax
mov    (%rax),%edi
lea    -0x440(%rbp),%rdx
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    -0x840(%rbp),%rdi
lea    0xc13(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x860(%rbp)
cmpq   $0x0,-0x860(%rbp)
jne    1590 <main+0x3d0>
mov    0x2a71(%rip),%rax
mov    (%rax),%edi
lea    -0x840(%rbp),%rdx
lea    0xbe5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x1c(%rbp),%edi
add    $0x40,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x848(%rbp)
mov    -0x848(%rbp),%rdi
mov    -0x2c(%rbp),%esi
and    $0xff,%esi
mov    -0x1c(%rbp),%edx
add    $0x40,%edx
call   1070 <memset@plt>
mov    -0x858(%rbp),%rdi
mov    -0x848(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x84c(%rbp),%r8d
mov    -0x860(%rbp),%r9
call   1090 <read_hex_file@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x84c(%rbp)
jne    1641 <main+0x481>
cmpl   $0x0,-0x34(%rbp)
je     161e <main+0x45e>
mov    -0x848(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x860(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
jmp    163c <main+0x47c>
mov    -0x848(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x860(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
jmp    1641 <main+0x481>
mov    -0x848(%rbp),%rdi
call   1030 <free@plt>
mov    -0x860(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x858(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
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,%rbp
xor    %eax,%eax
cmp    $0x1,%edi
sete   %al
jle    134b <main+0x17b>
mov    %edi,%r12d
lea    -0x1(%r12),%ecx
mov    %ecx,0x14(%rsp)
mov    $0x800000,%ecx
mov    %rcx,0x28(%rsp)
mov    $0xff,%ecx
mov    %rcx,0x20(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x1,%ebx
lea    0xdda(%rip),%r15
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
movl   $0x0,0xc(%rsp)
xor    %r13d,%r13d
mov    %eax,%r14d
jmp    1265 <main+0x95>
nopl   (%rax)
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
call   1040 <strncpy@plt>
add    $0x1,%r13d
mov    %r14d,%eax
add    $0x1,%ebx
mov    %eax,%r14d
cmp    %r12d,%ebx
jge    1376 <main+0x1a6>
movslq %ebx,%rcx
mov    0x0(%rbp,%rcx,8),%rsi
cmpb   $0x2d,(%rsi)
jne    12c0 <main+0xf0>
movsbl 0x1(%rsi),%edx
add    $0xffffff9a,%edx
cmp    $0xd,%edx
ja     14b9 <main+0x2e9>
mov    $0x1,%eax
movslq (%r15,%rdx,4),%rdx
add    %r15,%rdx
jmp    *%rdx
cmp    0x14(%rsp),%ebx
je     1491 <main+0x2c1>
add    $0x1,%ebx
mov    0x8(%rbp,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x20(%rsp)
jmp    1253 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x430(%rsp),%rdi
test   %r13d,%r13d
je     1245 <main+0x75>
cmp    $0x1,%r13d
je     1240 <main+0x70>
jmp    1479 <main+0x2a9>
cmp    0x14(%rsp),%ebx
je     149a <main+0x2ca>
add    $0x1,%ebx
mov    0x8(%rbp,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x18(%rsp)
jmp    1253 <main+0x83>
lea    0xdf6(%rip),%rdi
call   1050 <puts@plt>
movl   $0x1,0x10(%rsp)
jmp    1253 <main+0x83>
cmp    0x14(%rsp),%ebx
je     14a3 <main+0x2d3>
add    $0x1,%ebx
mov    0x8(%rbp,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x28(%rsp)
movl   $0x1,0xc(%rsp)
jmp    1253 <main+0x83>
movl   $0x0,0xc(%rsp)
mov    $0xff,%ecx
mov    %rcx,0x20(%rsp)
mov    $0x800000,%ecx
mov    %rcx,0x28(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x18(%rsp)
movl   $0x0,0x10(%rsp)
test   %eax,%eax
je     13af <main+0x1df>
mov    0x2c5f(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%rbp),%rdx
lea    0xcde(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd12(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    1467 <main+0x297>
lea    0xd10(%rip),%rsi
lea    0x430(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     14d1 <main+0x301>
mov    %rax,%r15
lea    0xd0d(%rip),%rsi
lea    0x30(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
mov    0x28(%rsp),%rbx
je     14eb <main+0x31b>
mov    %rax,%r13
lea    0x40(%rbx),%r12d
mov    %r12d,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
movzbl 0x20(%rsp),%esi
mov    %rax,%rdi
mov    %r12d,%edx
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    0x18(%rsp),%rdx
mov    %ebx,%ecx
mov    0x10(%rsp),%ebp
mov    %ebp,%r8d
mov    %r13,%r9
call   10a0 <read_hex_file@plt>
test   %ebp,%ebp
jne    144d <main+0x27d>
add    $0x1,%eax
cmpl   $0x0,0xc(%rsp)
cmove  %eax,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r13,%rcx
call   10f0 <fwrite@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbd2(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
lea    0xc8c(%rip),%rdi
jmp    14aa <main+0x2da>
lea    0xcbf(%rip),%rdi
jmp    14aa <main+0x2da>
lea    0xc9c(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xb78(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    0x2b08(%rip),%rax
mov    (%rax),%edi
lea    0xbe7(%rip),%rsi
lea    0x430(%rsp),%rdx
jmp    1500 <main+0x330>
mov    0x2aee(%rip),%rax
mov    (%rax),%edi
lea    0xbeb(%rip),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"-o option: no offset given.\0A\00"
@.str.1 = [27 x i8] c"-s option: no size given.\0A\00"
@.str.2 = [35 x i8] c"-f option: no fill uint8_t given.\0A\00"
@.str.3 = [35 x i8] c"Enabled generating record structs\0A\00"
@.str.4 = [26 x i8] c"Unknown option %s given.\0A\00"
@.str.5 = [26 x i8] c"Superfluous argument %s.\0A\00"
@stderr = global i32 0
@.str.6 = [68 x i8] c"Usage: %s [-o <bin offset>] [-s <size>] \0A\09\09[-h] <infile> <outfile>\0A\00"
@.str.7 = [22 x i8] c"\09-h shows this help.\0A\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [27 x i8] c"Can't open '%s' as input.\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [28 x i8] c"Can't open '%s' as output.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [1024 x i8]
%16 = alloca [1024 x i8]
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32*
%20 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 8388608, i32* %8
store i32 0, i32* %9
store i32 -1, i32* %10
store i32 0, i32* %11
store i32 255, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %18
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 1, i32* %11
br label %24
24: ; preds = %23, %2
store i32 1, i32* %6
br label %25
25: ; preds = %150, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %153
29: ; preds = %25
%30 = load i8**, i8*** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 45
br i1 %38, label %39, label %120
39: ; preds = %29
%40 = load i8**, i8*** %5
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
switch i32 %47, label %111 [
i32 111, label %48
i32 104, label %68
i32 115, label %69
i32 102, label %89
i32 114, label %109
]
48: ; preds = %39
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = sub nsw i32 %50, 1
%52 = icmp ne i32 %49, %51
br i1 %52, label %53, label %64
53: ; preds = %48
%54 = load i8**, i8*** %5
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %54, i64 %57
%59 = load i8*, i8** %58
%60 = call i8* @strtoul(i8* %59, i32 0, i32 0)
%61 = ptrtoint i8* %60 to i32
store i32 %61, i32* %7
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 1
store i32 %63, i32* %6
br label %67
64: ; preds = %48
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %53
br label %119
68: ; preds = %39
store i32 1, i32* %11
br label %119
69: ; preds = %39
%70 = load i32, i32* %6
%71 = load i32, i32* %4
%72 = sub nsw i32 %71, 1
%73 = icmp ne i32 %70, %72
br i1 %73, label %74, label %85
74: ; preds = %69
%75 = load i8**, i8*** %5
%76 = load i32, i32* %6
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %75, i64 %78
%80 = load i8*, i8** %79
%81 = call i8* @strtoul(i8* %80, i32 0, i32 0)
%82 = ptrtoint i8* %81 to i32
store i32 %82, i32* %8
store i32 1, i32* %14
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %88
85: ; preds = %69
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %74
br label %119
89: ; preds = %39
%90 = load i32, i32* %6
%91 = load i32, i32* %4
%92 = sub nsw i32 %91, 1
%93 = icmp ne i32 %90, %92
br i1 %93, label %94, label %105
94: ; preds = %89
%95 = load i8**, i8*** %5
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8*, i8** %95, i64 %98
%100 = load i8*, i8** %99
%101 = call i8* @strtoul(i8* %100, i32 0, i32 0)
%102 = ptrtoint i8* %101 to i32
store i32 %102, i32* %12
%103 = load i32, i32* %6
%104 = add nsw i32 %103, 1
store i32 %104, i32* %6
br label %108
105: ; preds = %89
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %94
br label %119
109: ; preds = %39
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %18
br label %119
111: ; preds = %39
%112 = load i8**, i8*** %5
%113 = load i32, i32* %6
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i8*, i8** %112, i64 %114
%116 = load i8*, i8** %115
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %116)
%118 = call i32 @exit(i32 2)
unreachable
119: ; preds = %109, %108, %88, %68, %67
br label %149
120: ; preds = %29
%121 = load i32, i32* %13
switch i32 %121, label %138 [
i32 0, label %122
i32 1, label %130
]
122: ; preds = %120
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%124 = load i8**, i8*** %5
%125 = load i32, i32* %6
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i8*, i8** %124, i64 %126
%128 = load i8*, i8** %127
%129 = call i32 @strncpy(i8* %123, i8* %128, i32 1024)
br label %146
130: ; preds = %120
%131 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%132 = load i8**, i8*** %5
%133 = load i32, i32* %6
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8*, i8** %132, i64 %134
%136 = load i8*, i8** %135
%137 = call i32 @strncpy(i8* %131, i8* %136, i32 1024)
br label %146
138: ; preds = %120
%139 = load i8**, i8*** %5
%140 = load i32, i32* %6
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i8*, i8** %139, i64 %141
%143 = load i8*, i8** %142
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %143)
%145 = call i32 @exit(i32 3)
unreachable
146: ; preds = %130, %122
%147 = load i32, i32* %13
%148 = add nsw i32 %147, 1
store i32 %148, i32* %13
br label %149
149: ; preds = %146, %119
br label %150
150: ; preds = %149
%151 = load i32, i32* %6
%152 = add nsw i32 %151, 1
store i32 %152, i32* %6
br label %25
153: ; preds = %25
%154 = load i32, i32* %11
%155 = icmp ne i32 %154, 0
br i1 %155, label %156, label %164
156: ; preds = %153
%157 = load i32, i32* @stderr
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 0
%160 = load i8*, i8** %159
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.6, i64 0, i64 0), i8* %160)
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %225
164: ; preds = %153
%165 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%166 = call i32* @fopen(i8* %165, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %166, i32** %19
%167 = load i32*, i32** %19
%168 = icmp ne i32* %167, null
br i1 %168, label %174, label %169
169: ; preds = %164
%170 = load i32, i32* @stderr
%171 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%172 = call i32 (i32, i8*, ...) @fprintf(i32 %170, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %171)
%173 = call i32 @exit(i32 -1)
unreachable
174: ; preds = %164
%175 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%176 = call i32* @fopen(i8* %175, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
store i32* %176, i32** %20
%177 = load i32*, i32** %20
%178 = icmp ne i32* %177, null
br i1 %178, label %184, label %179
179: ; preds = %174
%180 = load i32, i32* @stderr
%181 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%182 = call i32 (i32, i8*, ...) @fprintf(i32 %180, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i8* %181)
%183 = call i32 @exit(i32 -1)
unreachable
184: ; preds = %174
%185 = load i32, i32* %8
%186 = add nsw i32 %185, 64
%187 = call i8* @malloc(i32 %186)
store i8* %187, i8** %17
%188 = load i8*, i8** %17
%189 = load i32, i32* %12
%190 = and i32 %189, 255
%191 = load i32, i32* %8
%192 = add nsw i32 %191, 64
%193 = call i32 @memset(i8* %188, i32 %190, i32 %192)
%194 = load i32*, i32** %19
%195 = load i8*, i8** %17
%196 = load i32, i32* %7
%197 = load i32, i32* %8
%198 = load i32, i32* %18
%199 = load i32*, i32** %20
%200 = call i32 @read_hex_file(i32* %194, i8* %195, i32 %196, i32 %197, i32 %198, i32* %199)
store i32 %200, i32* %9
%201 = load i32, i32* %18
%202 = icmp ne i32 %201, 0
br i1 %202, label %218, label %203
203: ; preds = %184
%204 = load i32, i32* %14
%205 = icmp ne i32 %204, 0
br i1 %205, label %206, label %211
206: ; preds = %203
%207 = load i8*, i8** %17
%208 = load i32, i32* %8
%209 = load i32*, i32** %20
%210 = call i32 @fwrite(i8* %207, i32 1, i32 %208, i32* %209)
br label %217
211: ; preds = %203
%212 = load i8*, i8** %17
%213 = load i32, i32* %9
%214 = add nsw i32 %213, 1
%215 = load i32*, i32** %20
%216 = call i32 @fwrite(i8* %212, i32 1, i32 %214, i32* %215)
br label %217
217: ; preds = %211, %206
br label %218
218: ; preds = %217, %184
%219 = load i8*, i8** %17
%220 = call i32 @free(i8* %219)
%221 = load i32*, i32** %20
%222 = call i32 @fclose(i32* %221)
%223 = load i32*, i32** %19
%224 = call i32 @fclose(i32* %223)
store i32 0, i32* %3
br label %225
225: ; preds = %218, %156
%226 = load i32, i32* %3
ret i32 %226
}

LLVM IR (-O2):
@.str.4 = [26 x i8] c"Unknown option %s given.\0A\00"
@.str.5 = [26 x i8] c"Superfluous argument %s.\0A\00"
@stderr = global i32 0
@.str.6 = [68 x i8] c"Usage: %s [-o <bin offset>] [-s <size>] \0A\09\09[-h] <infile> <outfile>\0A\00"
@.str.7 = [22 x i8] c"\09-h shows this help.\0A\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [27 x i8] c"Can't open '%s' as input.\0A\00"
@.str.10 = [3 x i8] c"wb\00"
@.str.11 = [28 x i8] c"Can't open '%s' as output.\0A\00"
@str = [34 x i8] c"Enabled generating record structs\00"
@str.12 = [34 x i8] c"-f option: no fill uint8_t given.\00"
@str.13 = [26 x i8] c"-s option: no size given.\00"
@str.14 = [28 x i8] c"-o option: no offset given.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 1
%8 = zext i1 %7 to i32
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %94
10: ; preds = %2
%11 = add nsw i32 %0, -1
br label %12
12: ; preds = %10, %83
%13 = phi i32 [ 1, %10 ], [ %92, %83 ]
%14 = phi i32 [ 0, %10 ], [ %90, %83 ]
%15 = phi i32 [ 0, %10 ], [ %89, %83 ]
%16 = phi i32 [ 0, %10 ], [ %88, %83 ]
%17 = phi i32 [ 0, %10 ], [ %87, %83 ]
%18 = phi i32 [ 255, %10 ], [ %86, %83 ]
%19 = phi i32 [ %8, %10 ], [ %85, %83 ]
%20 = phi i32 [ 8388608, %10 ], [ %84, %83 ]
%21 = sext i32 %13 to i64
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 45
br i1 %25, label %26, label %74
26: ; preds = %12
%27 = getelementptr inbounds i8, i8* %23, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %71 [
i32 111, label %30
i32 104, label %83
i32 115, label %43
i32 102, label %56
i32 114, label %69
]
30: ; preds = %26
%31 = icmp eq i32 %13, %11
br i1 %31, label %40, label %32
32: ; preds = %30
%33 = add nsw i32 %13, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = call i8* @strtoul(i8* %36, i32 0, i32 0)
%38 = ptrtoint i8* %37 to i64
%39 = trunc i64 %38 to i32
br label %83
40: ; preds = %30
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.14, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %26
%44 = icmp eq i32 %13, %11
br i1 %44, label %53, label %45
45: ; preds = %43
%46 = add nsw i32 %13, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = call i8* @strtoul(i8* %49, i32 0, i32 0)
%51 = ptrtoint i8* %50 to i64
%52 = trunc i64 %51 to i32
br label %83
53: ; preds = %43
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %26
%57 = icmp eq i32 %13, %11
br i1 %57, label %66, label %58
58: ; preds = %56
%59 = add nsw i32 %13, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %1, i64 %60
%62 = load i8*, i8** %61
%63 = call i8* @strtoul(i8* %62, i32 0, i32 0)
%64 = ptrtoint i8* %63 to i64
%65 = trunc i64 %64 to i32
br label %83
66: ; preds = %56
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.12, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %26
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %83
71: ; preds = %26
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%73 = call i32 @exit(i32 2)
unreachable
74: ; preds = %12
switch i32 %17, label %76 [
i32 0, label %79
i32 1, label %75
]
75: ; preds = %74
br label %79
76: ; preds = %74
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%78 = call i32 @exit(i32 3)
unreachable
79: ; preds = %74, %75
%80 = phi i8* [ %6, %75 ], [ %5, %74 ]
%81 = call i32 @strncpy(i8* %80, i8* %23, i32 1024)
%82 = add nuw nsw i32 %17, 1
br label %83
83: ; preds = %26, %79, %69, %58, %45, %32
%84 = phi i32 [ %20, %69 ], [ %20, %58 ], [ %52, %45 ], [ %20, %32 ], [ %20, %79 ], [ %20, %26 ]
%85 = phi i32 [ %19, %69 ], [ %19, %58 ], [ %19, %45 ], [ %19, %32 ], [ %19, %79 ], [ 1, %26 ]
%86 = phi i32 [ %18, %69 ], [ %65, %58 ], [ %18, %45 ], [ %18, %32 ], [ %18, %79 ], [ %18, %26 ]
%87 = phi i32 [ %17, %69 ], [ %17, %58 ], [ %17, %45 ], [ %17, %32 ], [ %82, %79 ], [ %17, %26 ]
%88 = phi i32 [ %16, %69 ], [ %16, %58 ], [ 1, %45 ], [ %16, %32 ], [ %16, %79 ], [ %16, %26 ]
%89 = phi i32 [ %15, %69 ], [ %15, %58 ], [ %15, %45 ], [ %39, %32 ], [ %15, %79 ], [ %15, %26 ]
%90 = phi i32 [ 1, %69 ], [ %14, %58 ], [ %14, %45 ], [ %14, %32 ], [ %14, %79 ], [ %14, %26 ]
%91 = phi i32 [ %13, %69 ], [ %59, %58 ], [ %46, %45 ], [ %33, %32 ], [ %13, %79 ], [ %13, %26 ]
%92 = add nsw i32 %91, 1
%93 = icmp slt i32 %92, %0
br i1 %93, label %12, label %94
94: ; preds = %83, %2
%95 = phi i32 [ 8388608, %2 ], [ %84, %83 ]
%96 = phi i32 [ %8, %2 ], [ %85, %83 ]
%97 = phi i32 [ 255, %2 ], [ %86, %83 ]
%98 = phi i32 [ 0, %2 ], [ %88, %83 ]
%99 = phi i32 [ 0, %2 ], [ %89, %83 ]
%100 = phi i32 [ 0, %2 ], [ %90, %83 ]
%101 = icmp eq i32 %96, 0
br i1 %101, label %108, label %102
102: ; preds = %94
%103 = load i32, i32* @stderr
%104 = load i8*, i8** %1
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.6, i64 0, i64 0), i8* %104)
%106 = load i32, i32* @stderr
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
br label %138
108: ; preds = %94
%109 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%110 = icmp eq i32* %109, null
br i1 %110, label %111, label %115
111: ; preds = %108
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %5)
%114 = call i32 @exit(i32 -1)
unreachable
115: ; preds = %108
%116 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%117 = icmp eq i32* %116, null
br i1 %117, label %118, label %122
118: ; preds = %115
%119 = load i32, i32* @stderr
%120 = call i32 (i32, i8*, ...) @fprintf(i32 %119, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.11, i64 0, i64 0), i8* %6)
%121 = call i32 @exit(i32 -1)
unreachable
122: ; preds = %115
%123 = add nsw i32 %95, 64
%124 = call i8* @malloc(i32 %123)
%125 = and i32 %97, 255
%126 = call i32 @memset(i8* %124, i32 %125, i32 %123)
%127 = call i32 @read_hex_file(i32* %109, i8* %124, i32 %99, i32 %95, i32 %100, i32* %116)
%128 = icmp eq i32 %100, 0
br i1 %128, label %129, label %134
129: ; preds = %122
%130 = icmp eq i32 %98, 0
%131 = add nsw i32 %127, 1
%132 = select i1 %130, i32 %131, i32 %95
%133 = call i32 @fwrite(i8* %124, i32 1, i32 %132, i32* %116)
br label %134
134: ; preds = %129, %122
%135 = call i32 @free(i8* %124)
%136 = call i32 @fclose(i32* %116)
%137 = call i32 @fclose(i32* %109)
br label %138
138: ; preds = %134, %102
%139 = phi i32 [ 1, %102 ], [ 0, %134 ]
ret i32 %139
}