#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 /*<<< 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 << 21);
  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;
  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;
      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);
  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   $0x200000,-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)
cmpl   $0x1,-0x8(%rbp)
jne    1222 <main+0x62>
movl   $0x1,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    147e <main+0x2be>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    13d0 <main+0x210>
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,-0x860(%rbp)
sub    $0xd,%eax
ja     13a7 <main+0x1e7>
mov    -0x860(%rbp),%rax
lea    0xd80(%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     12c5 <main+0x105>
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    12dd <main+0x11d>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13cb <main+0x20b>
movl   $0x1,-0x28(%rbp)
jmp    13cb <main+0x20b>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1331 <main+0x171>
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    1349 <main+0x189>
lea    0xd1d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13cb <main+0x20b>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     138a <main+0x1ca>
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    13a2 <main+0x1e2>
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    13cb <main+0x20b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    146b <main+0x2ab>
mov    -0x30(%rbp),%eax
mov    %eax,-0x864(%rbp)
test   %eax,%eax
je     13fa <main+0x23a>
jmp    13e6 <main+0x226>
mov    -0x864(%rbp),%eax
sub    $0x1,%eax
je     141c <main+0x25c>
jmp    143e <main+0x27e>
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    1462 <main+0x2a2>
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    1462 <main+0x2a2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc5c(%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    1470 <main+0x2b0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1229 <main+0x69>
cmpl   $0x0,-0x28(%rbp)
je     14c9 <main+0x309>
mov    0x2b51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc28(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    0xc55(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1625 <main+0x465>
lea    -0x440(%rbp),%rdi
lea    0xc4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x850(%rbp)
cmpq   $0x0,-0x850(%rbp)
jne    1519 <main+0x359>
mov    0x2ae8(%rip),%rax
mov    (%rax),%edi
lea    -0x440(%rbp),%rdx
lea    0xc1b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    -0x840(%rbp),%rdi
lea    0xc17(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x858(%rbp)
cmpq   $0x0,-0x858(%rbp)
jne    1569 <main+0x3a9>
mov    0x2a98(%rip),%rax
mov    (%rax),%edi
lea    -0x840(%rbp),%rdx
lea    0xbe9(%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    -0x850(%rbp),%rdi
mov    -0x848(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1090 <read_hex_file@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     15dc <main+0x41c>
mov    -0x848(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x858(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
jmp    15fa <main+0x43a>
mov    -0x848(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x858(%rbp),%rcx
mov    $0x1,%esi
call   10e0 <fwrite@plt>
mov    -0x848(%rbp),%rdi
call   1030 <free@plt>
mov    -0x858(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x850(%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    $0x828,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x1,%edi
sete   %al
jle    1331 <main+0x161>
mov    %edi,%r13d
lea    -0x1(%r13),%ecx
mov    %ecx,0x4(%rsp)
mov    $0x200000,%ecx
mov    %rcx,0x18(%rsp)
mov    $0xff,%ecx
mov    %rcx,0x8(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
mov    $0x1,%ebp
lea    0xddc(%rip),%r15
movl   $0x0,(%rsp)
xor    %r12d,%r12d
mov    %eax,%r14d
jmp    1265 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x20(%rsp),%rdi
mov    $0x400,%edx
call   1040 <strncpy@plt>
add    $0x1,%r12d
mov    %r14d,%eax
add    $0x1,%ebp
mov    %eax,%r14d
cmp    %r13d,%ebp
jge    1353 <main+0x183>
movslq %ebp,%rcx
mov    (%rbx,%rcx,8),%rsi
cmpb   $0x2d,(%rsi)
jne    12c0 <main+0xf0>
movsbl 0x1(%rsi),%edx
add    $0xffffff9a,%edx
cmp    $0xd,%edx
ja     145e <main+0x28e>
mov    $0x1,%eax
movslq (%r15,%rdx,4),%rdx
add    %r15,%rdx
jmp    *%rdx
cmp    0x4(%rsp),%ebp
je     1476 <main+0x2a6>
add    $0x1,%ebp
mov    0x8(%rbx,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x8(%rsp)
jmp    1253 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x420(%rsp),%rdi
test   %r12d,%r12d
je     1245 <main+0x75>
cmp    $0x1,%r12d
je     1240 <main+0x70>
jmp    1446 <main+0x276>
cmp    0x4(%rsp),%ebp
je     147f <main+0x2af>
add    $0x1,%ebp
mov    0x8(%rbx,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x10(%rsp)
jmp    1253 <main+0x83>
cmp    0x4(%rsp),%ebp
je     1488 <main+0x2b8>
add    $0x1,%ebp
mov    0x8(%rbx,%rcx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10d0 <strtoul@plt>
mov    %rax,0x18(%rsp)
movl   $0x1,(%rsp)
jmp    1253 <main+0x83>
movl   $0x0,(%rsp)
mov    $0xff,%ecx
mov    %rcx,0x8(%rsp)
mov    $0x200000,%ecx
mov    %rcx,0x18(%rsp)
xor    %ecx,%ecx
mov    %rcx,0x10(%rsp)
test   %eax,%eax
je     138d <main+0x1bd>
mov    0x2c82(%rip),%rbp
mov    0x0(%rbp),%edi
mov    (%rbx),%rdx
lea    0xd01(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xd34(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%eax
jmp    1434 <main+0x264>
lea    0xd32(%rip),%rsi
lea    0x420(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     149e <main+0x2ce>
mov    %rax,%r13
lea    0xd2f(%rip),%rsi
lea    0x20(%rsp),%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     14b8 <main+0x2e8>
mov    %rax,%r15
mov    0x18(%rsp),%rbx
lea    0x40(%rbx),%r14d
mov    %r14d,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbp
movzbl 0x8(%rsp),%esi
mov    %rax,%rdi
mov    %r14d,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rdx
mov    %ebx,%ecx
call   10a0 <read_hex_file@plt>
lea    0x1(%rax),%edx
cmpl   $0x0,(%rsp)
cmovne %ebx,%edx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   10f0 <fwrite@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r13,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc05(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
lea    0xbd3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    0xc85(%rip),%rdi
jmp    148f <main+0x2bf>
lea    0xcb8(%rip),%rdi
jmp    148f <main+0x2bf>
lea    0xc95(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
lea    0xc1a(%rip),%rsi
lea    0x420(%rsp),%rdx
jmp    14cd <main+0x2fd>
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
lea    0xc1e(%rip),%rsi
lea    0x20(%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 = [26 x i8] c"Unknown option %s given.\0A\00"
@.str.4 = [26 x i8] c"Superfluous argument %s.\0A\00"
@stderr = global i32 0
@.str.5 = [68 x i8] c"Usage: %s [-o <bin offset>] [-s <size>] \0A\09\09[-h] <infile> <outfile>\0A\00"
@.str.6 = [22 x i8] c"\09-h shows this help.\0A\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [27 x i8] c"Can't open '%s' as input.\0A\00"
@.str.9 = [3 x i8] c"wb\00"
@.str.10 = [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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 2097152, 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
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 1, i32* %11
br label %23
23: ; preds = %22, %2
store i32 1, i32* %6
br label %24
24: ; preds = %147, %23
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %150
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 45
br i1 %37, label %38, label %117
38: ; preds = %28
%39 = load i8**, i8*** %5
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
switch i32 %46, label %108 [
i32 111, label %47
i32 104, label %67
i32 115, label %68
i32 102, label %88
]
47: ; preds = %38
%48 = load i32, i32* %6
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = icmp ne i32 %48, %50
br i1 %51, label %52, label %63
52: ; preds = %47
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %53, i64 %56
%58 = load i8*, i8** %57
%59 = call i8* @strtoul(i8* %58, i32 0, i32 0)
%60 = ptrtoint i8* %59 to i32
store i32 %60, i32* %7
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %66
63: ; preds = %47
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %52
br label %116
67: ; preds = %38
store i32 1, i32* %11
br label %116
68: ; preds = %38
%69 = load i32, i32* %6
%70 = load i32, i32* %4
%71 = sub nsw i32 %70, 1
%72 = icmp ne i32 %69, %71
br i1 %72, label %73, label %84
73: ; preds = %68
%74 = load i8**, i8*** %5
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8*, i8** %74, i64 %77
%79 = load i8*, i8** %78
%80 = call i8* @strtoul(i8* %79, i32 0, i32 0)
%81 = ptrtoint i8* %80 to i32
store i32 %81, i32* %8
store i32 1, i32* %14
%82 = load i32, i32* %6
%83 = add nsw i32 %82, 1
store i32 %83, i32* %6
br label %87
84: ; preds = %68
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %73
br label %116
88: ; preds = %38
%89 = load i32, i32* %6
%90 = load i32, i32* %4
%91 = sub nsw i32 %90, 1
%92 = icmp ne i32 %89, %91
br i1 %92, label %93, label %104
93: ; preds = %88
%94 = load i8**, i8*** %5
%95 = load i32, i32* %6
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
%100 = call i8* @strtoul(i8* %99, i32 0, i32 0)
%101 = ptrtoint i8* %100 to i32
store i32 %101, i32* %12
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
store i32 %103, i32* %6
br label %107
104: ; preds = %88
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %93
br label %116
108: ; preds = %38
%109 = load i8**, i8*** %5
%110 = load i32, i32* %6
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8*, i8** %109, i64 %111
%113 = load i8*, i8** %112
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %113)
%115 = call i32 @exit(i32 2)
unreachable
116: ; preds = %107, %87, %67, %66
br label %146
117: ; preds = %28
%118 = load i32, i32* %13
switch i32 %118, label %135 [
i32 0, label %119
i32 1, label %127
]
119: ; preds = %117
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%121 = load i8**, i8*** %5
%122 = load i32, i32* %6
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds i8*, i8** %121, i64 %123
%125 = load i8*, i8** %124
%126 = call i32 @strncpy(i8* %120, i8* %125, i32 1024)
br label %143
127: ; preds = %117
%128 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%129 = load i8**, i8*** %5
%130 = load i32, i32* %6
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i8*, i8** %129, i64 %131
%133 = load i8*, i8** %132
%134 = call i32 @strncpy(i8* %128, i8* %133, i32 1024)
br label %143
135: ; preds = %117
%136 = load i8**, i8*** %5
%137 = load i32, i32* %6
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i8*, i8** %136, i64 %138
%140 = load i8*, i8** %139
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %140)
%142 = call i32 @exit(i32 3)
unreachable
143: ; preds = %127, %119
%144 = load i32, i32* %13
%145 = add nsw i32 %144, 1
store i32 %145, i32* %13
br label %146
146: ; preds = %143, %116
br label %147
147: ; preds = %146
%148 = load i32, i32* %6
%149 = add nsw i32 %148, 1
store i32 %149, i32* %6
br label %24
150: ; preds = %24
%151 = load i32, i32* %11
%152 = icmp ne i32 %151, 0
br i1 %152, label %153, label %161
153: ; preds = %150
%154 = load i32, i32* @stderr
%155 = load i8**, i8*** %5
%156 = getelementptr inbounds i8*, i8** %155, i64 0
%157 = load i8*, i8** %156
%158 = call i32 (i32, i8*, ...) @fprintf(i32 %154, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.5, i64 0, i64 0), i8* %157)
%159 = load i32, i32* @stderr
%160 = call i32 (i32, i8*, ...) @fprintf(i32 %159, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %216
161: ; preds = %150
%162 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%163 = call i32* @fopen(i8* %162, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %163, i32** %18
%164 = load i32*, i32** %18
%165 = icmp ne i32* %164, null
br i1 %165, label %171, label %166
166: ; preds = %161
%167 = load i32, i32* @stderr
%168 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%169 = call i32 (i32, i8*, ...) @fprintf(i32 %167, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %168)
%170 = call i32 @exit(i32 -1)
unreachable
171: ; preds = %161
%172 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%173 = call i32* @fopen(i8* %172, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
store i32* %173, i32** %19
%174 = load i32*, i32** %19
%175 = icmp ne i32* %174, null
br i1 %175, label %181, label %176
176: ; preds = %171
%177 = load i32, i32* @stderr
%178 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %177, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i8* %178)
%180 = call i32 @exit(i32 -1)
unreachable
181: ; preds = %171
%182 = load i32, i32* %8
%183 = add nsw i32 %182, 64
%184 = call i8* @malloc(i32 %183)
store i8* %184, i8** %17
%185 = load i8*, i8** %17
%186 = load i32, i32* %12
%187 = and i32 %186, 255
%188 = load i32, i32* %8
%189 = add nsw i32 %188, 64
%190 = call i32 @memset(i8* %185, i32 %187, i32 %189)
%191 = load i32*, i32** %18
%192 = load i8*, i8** %17
%193 = load i32, i32* %7
%194 = load i32, i32* %8
%195 = call i32 @read_hex_file(i32* %191, i8* %192, i32 %193, i32 %194)
store i32 %195, i32* %9
%196 = load i32, i32* %14
%197 = icmp ne i32 %196, 0
br i1 %197, label %198, label %203
198: ; preds = %181
%199 = load i8*, i8** %17
%200 = load i32, i32* %8
%201 = load i32*, i32** %19
%202 = call i32 @fwrite(i8* %199, i32 1, i32 %200, i32* %201)
br label %209
203: ; preds = %181
%204 = load i8*, i8** %17
%205 = load i32, i32* %9
%206 = add nsw i32 %205, 1
%207 = load i32*, i32** %19
%208 = call i32 @fwrite(i8* %204, i32 1, i32 %206, i32* %207)
br label %209
209: ; preds = %203, %198
%210 = load i8*, i8** %17
%211 = call i32 @free(i8* %210)
%212 = load i32*, i32** %19
%213 = call i32 @fclose(i32* %212)
%214 = load i32*, i32** %18
%215 = call i32 @fclose(i32* %214)
store i32 0, i32* %3
br label %216
216: ; preds = %209, %153
%217 = load i32, i32* %3
ret i32 %217
}

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