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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int fread_wrapper(int /*<<< orphan*/ *, int, int /*<<< orphan*/ *, int *, long,
                  char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ strncpy(char *, char *, int);
int strtoul(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  uint32_t bin_offset = 0;
  uint32_t hex_offset = 0;
  uint32_t length = (1 << 30);
  int eof = 1;
  int segment = -1;
  int append = 0;
  int help = 0;
  int unnamed = 0;
  int add_length = 0;
  int word_mode = 0;
  int raw_mode = 0;
  char name_in[1024];
  char name_out[1024];
  char version[16];
  unsigned char buffer[64], b1, b2, ch;
  FILE *fi, *fo;
  if (argc == 1)
    help = 1;
  memset(version, 0, 16);
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '-') {
      switch (argv[i][1]) {
      case 'i':
        if (i != (argc - 1)) {
          bin_offset = strtoul(argv[i + 1], 0, 0);
          i++;
        } else {
          printf("-i option: no offset given.\n");
          exit(1);
        }
        break;
      case 'h':
        help = 1;
        break;
      case 'r':
        raw_mode = 1;
        break;
      case 'o':
        if (i != (argc - 1)) {
          hex_offset = strtoul(argv[i + 1], 0, 0);
          i++;
        } else {
          printf("-o option: no offset given.\n");
          exit(1);
        }
        break;
      case 'l':
        if (i != (argc - 1)) {
          length = strtoul(argv[i + 1], 0, 0);
          i++;
        } else {
          printf("-l option: no length given.\n");
          exit(1);
        }
        break;
      case 't':
        eof = 0;
        break;
      case 'a':
        append = 1;
        break;
      case 'v':
        if (i != (argc - 1)) {
          strncpy(version, argv[i + 1], 11);
          i++;
        } else {
          printf("-v option: no string given.\n");
          exit(1);
        }
        break;
      case 'w':
        word_mode = 1;
        break;
      case 'z':
        add_length = 1;
        break;
      case 'Z':
        add_length = 2;
        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 [-i <bin offset>] [-o <hex offset>] [-l <length>] "
            "\n\t\t[-h] [-t] [-z/Z] [-a] <infile> <outfile>\n",
            argv[0]);
    fprintf(stderr, "\t-h shows this help.\n");
    fprintf(stderr, "\t-t omits the end record.\n");
    fprintf(stderr, "\t-z adds file length word in little endian.\n");
    fprintf(stderr, "\t-Z adds file length word in big endian.\n");
    fprintf(stderr, "\t-w selects word mode (outputs 4 bytes per line, and "
                    "divides address by 4).\n");
    fprintf(stderr, "\t-a appends to the existing hex file.\n");
    return 1;
  }
  fi = fopen(name_in, "rb");
  if (!fi) {
    fprintf(stderr, "Can't open '%s' as input.\n", name_in);
    exit(-1);
  }
  fo = fopen(name_out, (append) ? "at" : "wt");
  if (!fo) {
    fprintf(stderr, "Can't open '%s' as output.\n", name_out);
    exit(-1);
  }
  long file_size = 0;
  if (add_length) {
    fseek(fi, 0L, SEEK_END);
    file_size = ftell(fi);
  }
  fseek(fi, bin_offset, SEEK_SET);
  int bytes_in_segment;
  int bytes_read;
  int bytes_to_read;
  int seg_flag = 0;
  int line_length = (word_mode) ? 4 : 32;
  while (length && !feof(fi)) {
    if (raw_mode) {
      if (fread(buffer, 1, 1, fi) > 0) {
        fprintf(fo, "%02x\n", *buffer);
      }
      length--;
      continue;
    }
    bytes_in_segment = 65536 - (hex_offset & 0xFFFF);
    if ((bytes_in_segment == 65536) || (segment == -1)) {
      segment = (hex_offset >> 16);
      b1 = (segment & 0xFF);
      b2 = (segment >> 8) & 0xFF;
      ch = 0xFA - b1 - b2;
      seg_flag = 1;
    }
    bytes_to_read =
        (bytes_in_segment > line_length) ? line_length : bytes_in_segment;
    bytes_read = fread_wrapper((uint8_t *)buffer, bytes_to_read, fi,
                               &add_length, file_size, version);
    if (bytes_read) {
      if (seg_flag) {
        fprintf(fo, ":02000004%04X%02X\n", segment, ch);
        seg_flag = 0;
      }
      int offset_out = (hex_offset & 0xFFFF) >> ((word_mode) ? 2 : 0);
      fprintf(fo, ":%02X%04X00", bytes_read, offset_out);
      b1 = (offset_out & 0xFF);
      b2 = (offset_out >> 8) & 0xFF;
      ch = 0 + bytes_read + b1 + b2;
      for (i = 0; i < bytes_read; i++) {
        fprintf(fo, "%02X", buffer[i]);
        ch += buffer[i];
      }
      ch = ~ch + 1;
      fprintf(fo, "%02X\n", ch);
    }
    hex_offset += bytes_read;
    length -= bytes_read;
  }
  if (eof && !raw_mode) {
    fprintf(fo, ":00000001FF\n");
  }
  fclose(fo);
  fclose(fi);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x40000000,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1247 <main+0x77>
movl   $0x1,-0x30(%rbp)
lea    -0x850(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1555 <main+0x385>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    14a7 <main+0x2d7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl 0x1(%rax),%eax
add    $0xffffffa6,%eax
mov    %eax,%ecx
mov    %rcx,-0x8d0(%rbp)
sub    $0x20,%eax
ja     147e <main+0x2ae>
mov    -0x8d0(%rbp),%rax
lea    0xd48(%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     12fd <main+0x12d>
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   10d0 <strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1315 <main+0x145>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    14a2 <main+0x2d2>
movl   $0x1,-0x30(%rbp)
jmp    14a2 <main+0x2d2>
movl   $0x1,-0x40(%rbp)
jmp    14a2 <main+0x2d2>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     136e <main+0x19e>
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   10d0 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1386 <main+0x1b6>
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    14a2 <main+0x2d2>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     13c7 <main+0x1f7>
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   10d0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13df <main+0x20f>
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    14a2 <main+0x2d2>
movl   $0x0,-0x24(%rbp)
jmp    14a2 <main+0x2d2>
movl   $0x1,-0x2c(%rbp)
jmp    14a2 <main+0x2d2>
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     143d <main+0x26d>
lea    -0x850(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0xb,%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1455 <main+0x285>
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    14a2 <main+0x2d2>
movl   $0x1,-0x3c(%rbp)
jmp    14a2 <main+0x2d2>
movl   $0x1,-0x38(%rbp)
jmp    14a2 <main+0x2d2>
movl   $0x2,-0x38(%rbp)
jmp    14a2 <main+0x2d2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
jmp    1542 <main+0x372>
mov    -0x34(%rbp),%eax
mov    %eax,-0x8d4(%rbp)
test   %eax,%eax
je     14d1 <main+0x301>
jmp    14bd <main+0x2ed>
mov    -0x8d4(%rbp),%eax
sub    $0x1,%eax
je     14f3 <main+0x323>
jmp    1515 <main+0x345>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
jmp    1539 <main+0x369>
lea    -0x840(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x400,%edx
call   1030 <strncpy@plt>
jmp    1539 <main+0x369>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbea(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1547 <main+0x377>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1261 <main+0x91>
cmpl   $0x0,-0x30(%rbp)
je     161a <main+0x44a>
mov    0x2a72(%rip),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xbb5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a53(%rip),%rax
mov    (%rax),%rdi
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a3b(%rip),%rax
mov    (%rax),%rdi
lea    0xc04(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a23(%rip),%rax
mov    (%rax),%rdi
lea    0xc07(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2a0b(%rip),%rax
mov    (%rax),%rdi
lea    0xc1c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x29f3(%rip),%rax
mov    (%rax),%rdi
lea    0xc2e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x29db(%rip),%rax
mov    (%rax),%rdi
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a89 <main+0x8b9>
lea    -0x440(%rbp),%rdi
lea    0xc69(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x8a0(%rbp)
cmpq   $0x0,-0x8a0(%rbp)
jne    166b <main+0x49b>
mov    0x298f(%rip),%rax
mov    (%rax),%rdi
lea    -0x440(%rbp),%rdx
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    -0x840(%rbp),%rdi
mov    -0x2c(%rbp),%ecx
lea    0xc36(%rip),%rsi
lea    0xc2c(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x8a8(%rbp)
cmpq   $0x0,-0x8a8(%rbp)
jne    16cd <main+0x4fd>
mov    0x292d(%rip),%rax
mov    (%rax),%rdi
lea    -0x840(%rbp),%rdx
lea    0xbf9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
movq   $0x0,-0x8b0(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     170c <main+0x53c>
mov    -0x8a0(%rbp),%rdi
mov    0x28f8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x8a0(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x8b0(%rbp)
mov    -0x8a0(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    0x28b3(%rip),%rax
mov    (%rax),%edx
call   10b0 <fseek@plt>
movl   $0x0,-0x8c0(%rbp)
mov    -0x3c(%rbp),%edx
mov    $0x20,%eax
mov    $0x4,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x8c4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x20(%rbp)
mov    %al,-0x8d5(%rbp)
je     1773 <main+0x5a3>
mov    -0x8a0(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x8d5(%rbp)
mov    -0x8d5(%rbp),%al
test   $0x1,%al
jne    1786 <main+0x5b6>
jmp    1a41 <main+0x871>
cmpl   $0x0,-0x40(%rbp)
je     17de <main+0x60e>
lea    -0x890(%rbp),%rdi
mov    -0x8a0(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x0,%rax
jle    17d0 <main+0x600>
mov    -0x8a8(%rbp),%rdi
movzbl -0x890(%rbp),%edx
lea    0xb08(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1747 <main+0x577>
mov    -0x1c(%rbp),%ecx
and    $0xffff,%ecx
mov    $0x10000,%eax
sub    %ecx,%eax
mov    %eax,-0x8b4(%rbp)
cmpl   $0x10000,-0x8b4(%rbp)
je     180e <main+0x63e>
cmpl   $0xffffffff,-0x28(%rbp)
jne    185d <main+0x68d>
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x891(%rbp)
mov    -0x28(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x892(%rbp)
movzbl -0x891(%rbp),%ecx
mov    $0xfa,%eax
sub    %ecx,%eax
movzbl -0x892(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0x893(%rbp)
movl   $0x1,-0x8c0(%rbp)
mov    -0x8b4(%rbp),%eax
cmp    -0x8c4(%rbp),%eax
jle    1880 <main+0x6b0>
mov    -0x8c4(%rbp),%eax
mov    %eax,-0x8dc(%rbp)
jmp    188c <main+0x6bc>
mov    -0x8b4(%rbp),%eax
mov    %eax,-0x8dc(%rbp)
mov    -0x8dc(%rbp),%eax
mov    %eax,-0x8bc(%rbp)
lea    -0x890(%rbp),%rdi
mov    -0x8bc(%rbp),%esi
mov    -0x8a0(%rbp),%rdx
mov    -0x8b0(%rbp),%r8
lea    -0x850(%rbp),%r9
lea    -0x38(%rbp),%rcx
call   10f0 <fread_wrapper@plt>
mov    %eax,-0x8b8(%rbp)
cmpl   $0x0,-0x8b8(%rbp)
je     1a22 <main+0x852>
cmpl   $0x0,-0x8c0(%rbp)
je     190c <main+0x73c>
mov    -0x8a8(%rbp),%rdi
mov    -0x28(%rbp),%edx
movzbl -0x893(%rbp),%ecx
lea    0x9dc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x8c0(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xffff,%eax
mov    -0x3c(%rbp),%esi
xor    %ecx,%ecx
mov    $0x2,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
sar    %cl,%eax
mov    %eax,-0x8c8(%rbp)
mov    -0x8a8(%rbp),%rdi
mov    -0x8b8(%rbp),%edx
mov    -0x8c8(%rbp),%ecx
lea    0x9a4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8c8(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x891(%rbp)
mov    -0x8c8(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x892(%rbp)
mov    -0x8b8(%rbp),%eax
add    $0x0,%eax
movzbl -0x891(%rbp),%ecx
add    %ecx,%eax
movzbl -0x892(%rbp),%ecx
add    %ecx,%eax
mov    %al,-0x893(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8b8(%rbp),%eax
jge    19f3 <main+0x823>
mov    -0x8a8(%rbp),%rdi
movslq -0x14(%rbp),%rax
movzbl -0x890(%rbp,%rax,1),%edx
ff
lea    0x933(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movslq -0x14(%rbp),%rax
movzbl -0x890(%rbp,%rax,1),%ecx
ff
movzbl -0x893(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x893(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    199a <main+0x7ca>
movzbl -0x893(%rbp),%eax
xor    $0xffffffff,%eax
add    $0x1,%eax
mov    %al,-0x893(%rbp)
mov    -0x8a8(%rbp),%rdi
movzbl -0x893(%rbp),%edx
lea    0x8c9(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8b8(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8b8(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
jmp    1747 <main+0x577>
cmpl   $0x0,-0x24(%rbp)
je     1a6a <main+0x89a>
cmpl   $0x0,-0x40(%rbp)
jne    1a6a <main+0x89a>
mov    -0x8a8(%rbp),%rdi
lea    0x898(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8a8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x8a0(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x898,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x0,0x34(%rsp)
xor    %r13d,%r13d
cmp    $0x1,%edi
sete   %r13b
lea    0x40(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
cmp    $0x2,%ebx
jl     13ff <main+0x20f>
lea    -0x1(%rbx),%eax
mov    %eax,0x18(%rsp)
movl   $0x40000000,0x10(%rsp)
40
mov    $0x1,%r14d
movl   $0x0,0x28(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x1,0x30(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x1c(%rsp)
xor    %r15d,%r15d
mov    %r13d,%r12d
movl   $0x0,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r14d,%rax
mov    0x0(%rbp,%rax,8),%rsi
cmpb   $0x2d,(%rsi)
jne    12e0 <main+0xf0>
movsbl 0x1(%rsi),%ecx
add    $0xffffffa6,%ecx
cmp    $0x20,%ecx
ja     1801 <main+0x611>
mov    $0x1,%r13d
lea    0xd46(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
movl   $0x2,0x34(%rsp)
movl   $0x2,0x28(%rsp)
jmp    130d <main+0x11d>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x490(%rsp),%rdi
test   %r15d,%r15d
je     12ff <main+0x10f>
cmp    $0x1,%r15d
jne    17e9 <main+0x5f9>
lea    0x90(%rsp),%rdi
mov    $0x400,%edx
call   1030 <strncpy@plt>
add    $0x1,%r15d
mov    %r12d,%r13d
add    $0x1,%r14d
mov    %r13d,%r12d
cmp    %ebx,%r14d
jl     1290 <main+0xa0>
jmp    143f <main+0x24f>
movl   $0x1,0xc(%rsp)
jmp    130d <main+0x11d>
cmp    0x18(%rsp),%r14d
je     1819 <main+0x629>
add    $0x1,%r14d
mov    0x8(%rbp,%rax,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,0x14(%rsp)
jmp    130d <main+0x11d>
cmp    0x18(%rsp),%r14d
je     1822 <main+0x632>
add    $0x1,%r14d
mov    0x8(%rbp,%rax,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,0x10(%rsp)
jmp    130d <main+0x11d>
cmp    0x18(%rsp),%r14d
je     182b <main+0x63b>
add    $0x1,%r14d
mov    0x8(%rbp,%rax,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <strtoul@plt>
mov    %eax,0x20(%rsp)
jmp    130d <main+0x11d>
movl   $0x1,0x24(%rsp)
jmp    130d <main+0x11d>
movl   $0x0,0x30(%rsp)
jmp    130d <main+0x11d>
cmp    0x18(%rsp),%r14d
je     1834 <main+0x644>
add    $0x1,%r14d
mov    0x8(%rbp,%rax,8),%rsi
lea    0x40(%rsp),%rdi
mov    $0xb,%edx
call   1030 <strncpy@plt>
jmp    130d <main+0x11d>
movl   $0x1,0x1c(%rsp)
jmp    130d <main+0x11d>
movl   $0x1,0x34(%rsp)
movl   $0x1,0x28(%rsp)
jmp    130d <main+0x11d>
movl   $0x0,0x28(%rsp)
movl   $0x40000000,0x10(%rsp)
40
movl   $0x1,0x30(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x1c(%rsp)
movl   $0x0,0x24(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x14(%rsp)
test   %r13d,%r13d
je     1504 <main+0x314>
mov    0x2b89(%rip),%rbx
mov    (%rbx),%rdi
mov    0x0(%rbp),%rdx
lea    0xc5b(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    (%rbx),%rcx
lea    0xcb3(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xcb0(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xcb2(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xcc6(%rip),%rdi
mov    $0x29,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xcd7(%rip),%rdi
mov    $0x4c,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    (%rbx),%rcx
lea    0xd0b(%rip),%rdi
mov    $0x26,%esi
mov    $0x1,%edx
call   1100 <fwrite@plt>
mov    $0x1,%eax
jmp    17d7 <main+0x5e7>
lea    0xd12(%rip),%rsi
lea    0x490(%rsp),%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
je     184a <main+0x65a>
mov    %rax,%rbx
cmpl   $0x0,0xc(%rsp)
lea    0xd0e(%rip),%rax
lea    0xd04(%rip),%rsi
cmove  %rax,%rsi
lea    0x90(%rsp),%rdi
call   10d0 <fopen@plt>
test   %rax,%rax
mov    0x10(%rsp),%r15d
je     1865 <main+0x675>
mov    %rax,%r12
cmpl   $0x0,0x28(%rsp)
je     157d <main+0x38d>
mov    0x2a81(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %rbx,%rdi
call   10a0 <ftell@plt>
jmp    157f <main+0x38f>
xor    %eax,%eax
mov    %rax,0x28(%rsp)
mov    0x2a45(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
call   10c0 <fseek@plt>
mov    0x1c(%rsp),%ecx
test   %ecx,%ecx
mov    $0x20,%eax
mov    $0x4,%edx
cmove  %eax,%edx
mov    %edx,0x18(%rsp)
test   %r15d,%r15d
je     179e <main+0x5ae>
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
add    %eax,%eax
mov    %eax,0x1c(%rsp)
mov    $0xffffffff,%eax
lea    0x50(%rsp),%r13
movl   $0x0,0xc(%rsp)
mov    %eax,0x10(%rsp)
mov    %r15d,%ebp
jmp    15f9 <main+0x409>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
je     17c5 <main+0x5d5>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    179e <main+0x5ae>
cmpl   $0x0,0x24(%rsp)
je     1642 <main+0x452>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jle    15f0 <main+0x400>
movzbl 0x50(%rsp),%edx
mov    %r12,%rdi
lea    0xc24(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    15f0 <main+0x400>
mov    0x20(%rsp),%edx
movzwl %dx,%eax
mov    $0x10000,%esi
sub    %eax,%esi
mov    %eax,0x3c(%rsp)
test   %eax,%eax
sete   %al
mov    0x10(%rsp),%ebp
cmp    $0xffffffff,%ebp
sete   %cl
or     %al,%cl
mov    %edx,%edi
sar    $0x10,%edi
mov    %edx,%eax
shr    $0x18,%eax
add    %edi,%eax
mov    $0xfa,%dl
sub    %al,%dl
movzbl %dl,%eax
movzbl %r14b,%r14d
test   %cl,%cl
cmovne %eax,%r14d
cmove  %ebp,%edi
mov    %edi,0x14(%rsp)
mov    $0x1,%eax
mov    0xc(%rsp),%ebp
cmovne %eax,%ebp
mov    0x18(%rsp),%eax
cmp    %eax,%esi
cmova  %eax,%esi
mov    %r13,%rdi
mov    %rbx,%rdx
lea    0x34(%rsp),%rcx
mov    0x28(%rsp),%r8
lea    0x40(%rsp),%r9
call   1110 <fread_wrapper@plt>
test   %eax,%eax
je     1789 <main+0x599>
mov    %eax,0x38(%rsp)
test   %ebp,%ebp
je     16e1 <main+0x4f1>
movzbl %r14b,%ecx
mov    %r12,%rdi
lea    0xb8d(%rip),%rsi
mov    0x14(%rsp),%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15d,0x10(%rsp)
mov    0x1c(%rsp),%ecx
mov    0x3c(%rsp),%r15d
shr    %cl,%r15d
mov    %r12,%rdi
lea    0xb7a(%rip),%rsi
mov    0x38(%rsp),%ebp
mov    %ebp,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %r15d,%r14d
shr    $0x8,%r14d
add    %r15d,%r14d
add    %ebp,%r14d
test   %ebp,%ebp
jle    1759 <main+0x569>
mov    %ebp,%ebp
xor    %r15d,%r15d
lea    0xb59(%rip),%r13
nopl   0x0(%rax)
movzbl 0x50(%rsp,%r15,1),%edx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
movzbl 0x50(%rsp,%r15,1),%eax
movzbl %r14b,%r14d
add    %eax,%r14d
add    $0x1,%r15
cmp    %r15,%rbp
jne    1730 <main+0x540>
neg    %r14b
movzbl %r14b,%edx
movl   $0x0,0xc(%rsp)
mov    %r12,%rdi
lea    0xafe(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x10(%rsp),%r15d
lea    0x50(%rsp),%r13
mov    0x38(%rsp),%eax
jmp    178d <main+0x59d>
mov    %ebp,0xc(%rsp)
add    %eax,0x20(%rsp)
sub    %eax,%r15d
mov    0x14(%rsp),%eax
jne    15d8 <main+0x3e8>
cmpl   $0x0,0x30(%rsp)
je     17c5 <main+0x5d5>
cmpl   $0x0,0x24(%rsp)
jne    17c5 <main+0x5d5>
lea    0xad4(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1100 <fwrite@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x898,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8ae(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
lea    0x87c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
lea    0xac8(%rip),%rdi
jmp    183b <main+0x64b>
lea    0xa87(%rip),%rdi
jmp    183b <main+0x64b>
lea    0xa9a(%rip),%rdi
jmp    183b <main+0x64b>
lea    0xa59(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2787(%rip),%rax
mov    (%rax),%rdi
lea    0x9c5(%rip),%rsi
lea    0x490(%rsp),%rdx
jmp    187e <main+0x68e>
mov    0x276c(%rip),%rax
mov    (%rax),%rdi
lea    0x9cb(%rip),%rsi
lea    0x90(%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"-i option: no offset given.\0A\00"
@.str.1 = [29 x i8] c"-o option: no offset given.\0A\00"
@.str.2 = [29 x i8] c"-l option: no length given.\0A\00"
@.str.3 = [29 x i8] c"-v option: no string given.\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* null
@.str.6 = [105 x i8] c"Usage: %s [-i <bin offset>] [-o <hex offset>] [-l <length>] \0A\09\09[-h] [-t] [-z/Z] [-a] <infile> <outfile>\0A\00"
@.str.7 = [22 x i8] c"\09-h shows this help.\0A\00"
@.str.8 = [27 x i8] c"\09-t omits the end record.\0A\00"
@.str.9 = [45 x i8] c"\09-z adds file length word in little endian.\0A\00"
@.str.10 = [42 x i8] c"\09-Z adds file length word in big endian.\0A\00"
@.str.11 = [77 x i8] c"\09-w selects word mode (outputs 4 bytes per line, and divides address by 4).\0A\00"
@.str.12 = [39 x i8] c"\09-a appends to the existing hex file.\0A\00"
@.str.13 = [3 x i8] c"rb\00"
@.str.14 = [27 x i8] c"Can't open '%s' as input.\0A\00"
@.str.15 = [3 x i8] c"at\00"
@.str.16 = [3 x i8] c"wt\00"
@.str.17 = [28 x i8] c"Can't open '%s' as output.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.18 = [6 x i8] c"%02x\0A\00"
@.str.19 = [19 x i8] c":02000004%04X%02X\0A\00"
@.str.20 = [12 x i8] c":%02X%04X00\00"
@.str.21 = [5 x i8] c"%02X\00"
@.str.22 = [6 x i8] c"%02X\0A\00"
@.str.23 = [13 x i8] c":00000001FF\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 i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [1024 x i8]
%19 = alloca [1024 x i8]
%20 = alloca [16 x i8]
%21 = alloca [64 x i8]
%22 = alloca i8
%23 = alloca i8
%24 = alloca i8
%25 = alloca i32*
%26 = alloca i32*
%27 = alloca i64
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
%33 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1073741824, i32* %9
store i32 1, i32* %10
store i32 -1, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %2
store i32 1, i32* %13
br label %37
37: ; preds = %36, %2
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%39 = call i32 @memset(i8* %38, i32 0, i32 16)
store i32 1, i32* %6
br label %40
40: ; preds = %186, %37
%41 = load i32, i32* %6
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %189
44: ; preds = %40
%45 = load i8**, i8*** %5
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = getelementptr inbounds i8, i8* %49, i64 0
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 45
br i1 %53, label %54, label %156
54: ; preds = %44
%55 = load i8**, i8*** %5
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
switch i32 %62, label %147 [
i32 105, label %63
i32 104, label %82
i32 114, label %83
i32 111, label %84
i32 108, label %103
i32 116, label %122
i32 97, label %123
i32 118, label %124
i32 119, label %144
i32 122, label %145
i32 90, label %146
]
63: ; preds = %54
%64 = load i32, i32* %6
%65 = load i32, i32* %4
%66 = sub nsw i32 %65, 1
%67 = icmp ne i32 %64, %66
br i1 %67, label %68, label %78
68: ; preds = %63
%69 = load i8**, i8*** %5
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %69, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 @strtoul(i8* %74, i32 0, i32 0)
store i32 %75, i32* %7
%76 = load i32, i32* %6
%77 = add nsw i32 %76, 1
store i32 %77, i32* %6
br label %81
78: ; preds = %63
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %68
br label %155
82: ; preds = %54
store i32 1, i32* %13
br label %155
83: ; preds = %54
store i32 1, i32* %17
br label %155
84: ; preds = %54
%85 = load i32, i32* %6
%86 = load i32, i32* %4
%87 = sub nsw i32 %86, 1
%88 = icmp ne i32 %85, %87
br i1 %88, label %89, label %99
89: ; preds = %84
%90 = load i8**, i8*** %5
%91 = load i32, i32* %6
%92 = add nsw i32 %91, 1
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %90, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 @strtoul(i8* %95, i32 0, i32 0)
store i32 %96, i32* %8
%97 = load i32, i32* %6
%98 = add nsw i32 %97, 1
store i32 %98, i32* %6
br label %102
99: ; preds = %84
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %89
br label %155
103: ; preds = %54
%104 = load i32, i32* %6
%105 = load i32, i32* %4
%106 = sub nsw i32 %105, 1
%107 = icmp ne i32 %104, %106
br i1 %107, label %108, label %118
108: ; preds = %103
%109 = load i8**, i8*** %5
%110 = load i32, i32* %6
%111 = add nsw i32 %110, 1
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8*, i8** %109, i64 %112
%114 = load i8*, i8** %113
%115 = call i32 @strtoul(i8* %114, i32 0, i32 0)
store i32 %115, i32* %9
%116 = load i32, i32* %6
%117 = add nsw i32 %116, 1
store i32 %117, i32* %6
br label %121
118: ; preds = %103
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %108
br label %155
122: ; preds = %54
store i32 0, i32* %10
br label %155
123: ; preds = %54
store i32 1, i32* %12
br label %155
124: ; preds = %54
%125 = load i32, i32* %6
%126 = load i32, i32* %4
%127 = sub nsw i32 %126, 1
%128 = icmp ne i32 %125, %127
br i1 %128, label %129, label %140
129: ; preds = %124
%130 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%131 = load i8**, i8*** %5
%132 = load i32, i32* %6
%133 = add nsw i32 %132, 1
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i8*, i8** %131, i64 %134
%136 = load i8*, i8** %135
%137 = call i32 @strncpy(i8* %130, i8* %136, i32 11)
%138 = load i32, i32* %6
%139 = add nsw i32 %138, 1
store i32 %139, i32* %6
br label %143
140: ; preds = %124
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %129
br label %155
144: ; preds = %54
store i32 1, i32* %16
br label %155
145: ; preds = %54
store i32 1, i32* %15
br label %155
146: ; preds = %54
store i32 2, i32* %15
br label %155
147: ; preds = %54
%148 = load i8**, i8*** %5
%149 = load i32, i32* %6
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds i8*, i8** %148, i64 %150
%152 = load i8*, i8** %151
%153 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %152)
%154 = call i32 @exit(i32 2)
unreachable
155: ; preds = %146, %145, %144, %143, %123, %122, %121, %102, %83, %82, %81
br label %185
156: ; preds = %44
%157 = load i32, i32* %14
switch i32 %157, label %174 [
i32 0, label %158
i32 1, label %166
]
158: ; preds = %156
%159 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%160 = load i8**, i8*** %5
%161 = load i32, i32* %6
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds i8*, i8** %160, i64 %162
%164 = load i8*, i8** %163
%165 = call i32 @strncpy(i8* %159, i8* %164, i32 1024)
br label %182
166: ; preds = %156
%167 = getelementptr inbounds [1024 x i8], [1024 x i8]* %19, i64 0, i64 0
%168 = load i8**, i8*** %5
%169 = load i32, i32* %6
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i8*, i8** %168, i64 %170
%172 = load i8*, i8** %171
%173 = call i32 @strncpy(i8* %167, i8* %172, i32 1024)
br label %182
174: ; preds = %156
%175 = load i8**, i8*** %5
%176 = load i32, i32* %6
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i8*, i8** %175, i64 %177
%179 = load i8*, i8** %178
%180 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %179)
%181 = call i32 @exit(i32 3)
unreachable
182: ; preds = %166, %158
%183 = load i32, i32* %14
%184 = add nsw i32 %183, 1
store i32 %184, i32* %14
br label %185
185: ; preds = %182, %155
br label %186
186: ; preds = %185
%187 = load i32, i32* %6
%188 = add nsw i32 %187, 1
store i32 %188, i32* %6
br label %40
189: ; preds = %40
%190 = load i32, i32* %13
%191 = icmp ne i32 %190, 0
br i1 %191, label %192, label %210
192: ; preds = %189
%193 = load i32*, i32** @stderr
%194 = load i8**, i8*** %5
%195 = getelementptr inbounds i8*, i8** %194, i64 0
%196 = load i8*, i8** %195
%197 = call i32 (i32*, i8*, ...) @fprintf(i32* %193, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.6, i64 0, i64 0), i8* %196)
%198 = load i32*, i32** @stderr
%199 = call i32 (i32*, i8*, ...) @fprintf(i32* %198, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%200 = load i32*, i32** @stderr
%201 = call i32 (i32*, i8*, ...) @fprintf(i32* %200, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%202 = load i32*, i32** @stderr
%203 = call i32 (i32*, i8*, ...) @fprintf(i32* %202, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0))
%204 = load i32*, i32** @stderr
%205 = call i32 (i32*, i8*, ...) @fprintf(i32* %204, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0))
%206 = load i32*, i32** @stderr
%207 = call i32 (i32*, i8*, ...) @fprintf(i32* %206, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.11, i64 0, i64 0))
%208 = load i32*, i32** @stderr
%209 = call i32 (i32*, i8*, ...) @fprintf(i32* %208, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %416
210: ; preds = %189
%211 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%212 = call i32* @fopen(i8* %211, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
store i32* %212, i32** %25
%213 = load i32*, i32** %25
%214 = icmp ne i32* %213, null
br i1 %214, label %220, label %215
215: ; preds = %210
%216 = load i32*, i32** @stderr
%217 = getelementptr inbounds [1024 x i8], [1024 x i8]* %18, i64 0, i64 0
%218 = call i32 (i32*, i8*, ...) @fprintf(i32* %216, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %217)
%219 = call i32 @exit(i32 -1)
unreachable
220: ; preds = %210
%221 = getelementptr inbounds [1024 x i8], [1024 x i8]* %19, i64 0, i64 0
%222 = load i32, i32* %12
%223 = icmp ne i32 %222, 0
%224 = zext i1 %223 to i64
%225 = select i1 %223, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0)
%226 = call i32* @fopen(i8* %221, i8* %225)
store i32* %226, i32** %26
%227 = load i32*, i32** %26
%228 = icmp ne i32* %227, null
br i1 %228, label %234, label %229
229: ; preds = %220
%230 = load i32*, i32** @stderr
%231 = getelementptr inbounds [1024 x i8], [1024 x i8]* %19, i64 0, i64 0
%232 = call i32 (i32*, i8*, ...) @fprintf(i32* %230, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0), i8* %231)
%233 = call i32 @exit(i32 -1)
unreachable
234: ; preds = %220
store i64 0, i64* %27
%235 = load i32, i32* %15
%236 = icmp ne i32 %235, 0
br i1 %236, label %237, label %243
237: ; preds = %234
%238 = load i32*, i32** %25
%239 = load i32, i32* @SEEK_END
%240 = call i32 @fseek(i32* %238, i32 0, i32 %239)
%241 = load i32*, i32** %25
%242 = call i64 @ftell(i32* %241)
store i64 %242, i64* %27
br label %243
243: ; preds = %237, %234
%244 = load i32*, i32** %25
%245 = load i32, i32* %7
%246 = load i32, i32* @SEEK_SET
%247 = call i32 @fseek(i32* %244, i32 %245, i32 %246)
store i32 0, i32* %31
%248 = load i32, i32* %16
%249 = icmp ne i32 %248, 0
%250 = zext i1 %249 to i64
%251 = select i1 %249, i32 4, i32 32
store i32 %251, i32* %32
br label %252
252: ; preds = %395, %276, %243
%253 = load i32, i32* %9
%254 = icmp ne i32 %253, 0
br i1 %254, label %255, label %260
255: ; preds = %252
%256 = load i32*, i32** %25
%257 = call i32 @feof(i32* %256)
%258 = icmp ne i32 %257, 0
%259 = xor i1 %258, true
br label %260
260: ; preds = %255, %252
%261 = phi i1 [ false, %252 ], [ %259, %255 ]
br i1 %261, label %262, label %402
262: ; preds = %260
%263 = load i32, i32* %17
%264 = icmp ne i32 %263, 0
br i1 %264, label %265, label %279
265: ; preds = %262
%266 = getelementptr inbounds [64 x i8], [64 x i8]* %21, i64 0, i64 0
%267 = load i32*, i32** %25
%268 = call i64 @fread(i8* %266, i32 1, i32 1, i32* %267)
%269 = icmp sgt i64 %268, 0
br i1 %269, label %270, label %276
270: ; preds = %265
%271 = load i32*, i32** %26
%272 = getelementptr inbounds [64 x i8], [64 x i8]* %21, i64 0, i64 0
%273 = load i8, i8* %272
%274 = zext i8 %273 to i32
%275 = call i32 (i32*, i8*, ...) @fprintf(i32* %271, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0), i32 %274)
br label %276
276: ; preds = %270, %265
%277 = load i32, i32* %9
%278 = add nsw i32 %277, -1
store i32 %278, i32* %9
br label %252
279: ; preds = %262
%280 = load i32, i32* %8
%281 = and i32 %280, 65535
%282 = sub nsw i32 65536, %281
store i32 %282, i32* %28
%283 = load i32, i32* %28
%284 = icmp eq i32 %283, 65536
br i1 %284, label %288, label %285
285: ; preds = %279
%286 = load i32, i32* %11
%287 = icmp eq i32 %286, -1
br i1 %287, label %288, label %305
288: ; preds = %285, %279
%289 = load i32, i32* %8
%290 = ashr i32 %289, 16
store i32 %290, i32* %11
%291 = load i32, i32* %11
%292 = and i32 %291, 255
%293 = trunc i32 %292 to i8
store i8 %293, i8* %22
%294 = load i32, i32* %11
%295 = ashr i32 %294, 8
%296 = and i32 %295, 255
%297 = trunc i32 %296 to i8
store i8 %297, i8* %23
%298 = load i8, i8* %22
%299 = zext i8 %298 to i32
%300 = sub nsw i32 250, %299
%301 = load i8, i8* %23
%302 = zext i8 %301 to i32
%303 = sub nsw i32 %300, %302
%304 = trunc i32 %303 to i8
store i8 %304, i8* %24
store i32 1, i32* %31
br label %305
305: ; preds = %288, %285
%306 = load i32, i32* %28
%307 = load i32, i32* %32
%308 = icmp sgt i32 %306, %307
br i1 %308, label %309, label %311
309: ; preds = %305
%310 = load i32, i32* %32
br label %313
311: ; preds = %305
%312 = load i32, i32* %28
br label %313
313: ; preds = %311, %309
%314 = phi i32 [ %310, %309 ], [ %312, %311 ]
store i32 %314, i32* %30
%315 = getelementptr inbounds [64 x i8], [64 x i8]* %21, i64 0, i64 0
%316 = bitcast i8* %315 to i32*
%317 = load i32, i32* %30
%318 = load i32*, i32** %25
%319 = load i64, i64* %27
%320 = getelementptr inbounds [16 x i8], [16 x i8]* %20, i64 0, i64 0
%321 = call i32 @fread_wrapper(i32* %316, i32 %317, i32* %318, i32* %15, i64 %319, i8* %320)
store i32 %321, i32* %29
%322 = load i32, i32* %29
%323 = icmp ne i32 %322, 0
br i1 %323, label %324, label %395
324: ; preds = %313
%325 = load i32, i32* %31
%326 = icmp ne i32 %325, 0
br i1 %326, label %327, label %333
327: ; preds = %324
%328 = load i32*, i32** %26
%329 = load i32, i32* %11
%330 = load i8, i8* %24
%331 = zext i8 %330 to i32
%332 = call i32 (i32*, i8*, ...) @fprintf(i32* %328, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i32 %329, i32 %331)
store i32 0, i32* %31
br label %333
333: ; preds = %327, %324
%334 = load i32, i32* %8
%335 = and i32 %334, 65535
%336 = load i32, i32* %16
%337 = icmp ne i32 %336, 0
%338 = zext i1 %337 to i64
%339 = select i1 %337, i32 2, i32 0
%340 = ashr i32 %335, %339
store i32 %340, i32* %33
%341 = load i32*, i32** %26
%342 = load i32, i32* %29
%343 = load i32, i32* %33
%344 = call i32 (i32*, i8*, ...) @fprintf(i32* %341, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.20, i64 0, i64 0), i32 %342, i32 %343)
%345 = load i32, i32* %33
%346 = and i32 %345, 255
%347 = trunc i32 %346 to i8
store i8 %347, i8* %22
%348 = load i32, i32* %33
%349 = ashr i32 %348, 8
%350 = and i32 %349, 255
%351 = trunc i32 %350 to i8
store i8 %351, i8* %23
%352 = load i32, i32* %29
%353 = add nsw i32 0, %352
%354 = load i8, i8* %22
%355 = zext i8 %354 to i32
%356 = add nsw i32 %353, %355
%357 = load i8, i8* %23
%358 = zext i8 %357 to i32
%359 = add nsw i32 %356, %358
%360 = trunc i32 %359 to i8
store i8 %360, i8* %24
store i32 0, i32* %6
br label %361
361: ; preds = %382, %333
%362 = load i32, i32* %6
%363 = load i32, i32* %29
%364 = icmp slt i32 %362, %363
br i1 %364, label %365, label %385
365: ; preds = %361
%366 = load i32*, i32** %26
%367 = load i32, i32* %6
%368 = sext i32 %367 to i64
%369 = getelementptr inbounds [64 x i8], [64 x i8]* %21, i64 0, i64 %368
%370 = load i8, i8* %369
%371 = zext i8 %370 to i32
%372 = call i32 (i32*, i8*, ...) @fprintf(i32* %366, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0), i32 %371)
%373 = load i32, i32* %6
%374 = sext i32 %373 to i64
%375 = getelementptr inbounds [64 x i8], [64 x i8]* %21, i64 0, i64 %374
%376 = load i8, i8* %375
%377 = zext i8 %376 to i32
%378 = load i8, i8* %24
%379 = zext i8 %378 to i32
%380 = add nsw i32 %379, %377
%381 = trunc i32 %380 to i8
store i8 %381, i8* %24
br label %382
382: ; preds = %365
%383 = load i32, i32* %6
%384 = add nsw i32 %383, 1
store i32 %384, i32* %6
br label %361
385: ; preds = %361
%386 = load i8, i8* %24
%387 = zext i8 %386 to i32
%388 = xor i32 %387, -1
%389 = add nsw i32 %388, 1
%390 = trunc i32 %389 to i8
store i8 %390, i8* %24
%391 = load i32*, i32** %26
%392 = load i8, i8* %24
%393 = zext i8 %392 to i32
%394 = call i32 (i32*, i8*, ...) @fprintf(i32* %391, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i32 %393)
br label %395
395: ; preds = %385, %313
%396 = load i32, i32* %29
%397 = load i32, i32* %8
%398 = add nsw i32 %397, %396
store i32 %398, i32* %8
%399 = load i32, i32* %29
%400 = load i32, i32* %9
%401 = sub nsw i32 %400, %399
store i32 %401, i32* %9
br label %252
402: ; preds = %260
%403 = load i32, i32* %10
%404 = icmp ne i32 %403, 0
br i1 %404, label %405, label %411
405: ; preds = %402
%406 = load i32, i32* %17
%407 = icmp ne i32 %406, 0
br i1 %407, label %411, label %408
408: ; preds = %405
%409 = load i32*, i32** %26
%410 = call i32 (i32*, i8*, ...) @fprintf(i32* %409, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.23, i64 0, i64 0))
br label %411
411: ; preds = %408, %405, %402
%412 = load i32*, i32** %26
%413 = call i32 @fclose(i32* %412)
%414 = load i32*, i32** %25
%415 = call i32 @fclose(i32* %414)
store i32 0, i32* %3
br label %416
416: ; preds = %411, %192
%417 = load i32, i32* %3
ret i32 %417
}

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* null
@.str.6 = [105 x i8] c"Usage: %s [-i <bin offset>] [-o <hex offset>] [-l <length>] \0A\09\09[-h] [-t] [-z/Z] [-a] <infile> <outfile>\0A\00"
@.str.7 = [22 x i8] c"\09-h shows this help.\0A\00"
@.str.8 = [27 x i8] c"\09-t omits the end record.\0A\00"
@.str.9 = [45 x i8] c"\09-z adds file length word in little endian.\0A\00"
@.str.10 = [42 x i8] c"\09-Z adds file length word in big endian.\0A\00"
@.str.11 = [77 x i8] c"\09-w selects word mode (outputs 4 bytes per line, and divides address by 4).\0A\00"
@.str.12 = [39 x i8] c"\09-a appends to the existing hex file.\0A\00"
@.str.13 = [3 x i8] c"rb\00"
@.str.14 = [27 x i8] c"Can't open '%s' as input.\0A\00"
@.str.15 = [3 x i8] c"at\00"
@.str.16 = [3 x i8] c"wt\00"
@.str.17 = [28 x i8] c"Can't open '%s' as output.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.18 = [6 x i8] c"%02x\0A\00"
@.str.19 = [19 x i8] c":02000004%04X%02X\0A\00"
@.str.20 = [12 x i8] c":%02X%04X00\00"
@.str.21 = [5 x i8] c"%02X\00"
@.str.22 = [6 x i8] c"%02X\0A\00"
@.str.23 = [13 x i8] c":00000001FF\0A\00"
@str = [28 x i8] c"-v option: no string given.\00"
@str.24 = [28 x i8] c"-l option: no length given.\00"
@str.25 = [28 x i8] c"-o option: no offset given.\00"
@str.26 = [28 x i8] c"-i option: no offset given.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [16 x i8]
%7 = alloca [64 x i8]
%8 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%13 = icmp eq i32 %0, 1
%14 = zext i1 %13 to i32
%15 = call i32 @memset(i8* %11, i32 0, i32 16)
%16 = icmp sgt i32 %0, 1
br i1 %16, label %17, label %116
17: ; preds = %2
%18 = add nsw i32 %0, -1
br label %19
19: ; preds = %17, %102
%20 = phi i32 [ 0, %17 ], [ %103, %102 ]
%21 = phi i32 [ 1, %17 ], [ %114, %102 ]
%22 = phi i32 [ 0, %17 ], [ %112, %102 ]
%23 = phi i32 [ 0, %17 ], [ %111, %102 ]
%24 = phi i32 [ 1073741824, %17 ], [ %110, %102 ]
%25 = phi i32 [ 1, %17 ], [ %109, %102 ]
%26 = phi i32 [ 0, %17 ], [ %108, %102 ]
%27 = phi i32 [ 0, %17 ], [ %107, %102 ]
%28 = phi i32 [ 0, %17 ], [ %106, %102 ]
%29 = phi i32 [ %14, %17 ], [ %105, %102 ]
%30 = phi i32 [ 0, %17 ], [ %104, %102 ]
%31 = sext i32 %21 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 45
br i1 %35, label %36, label %93
36: ; preds = %19
%37 = getelementptr inbounds i8, i8* %33, i64 1
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
switch i32 %39, label %90 [
i32 105, label %40
i32 104, label %102
i32 114, label %51
i32 111, label %52
i32 108, label %63
i32 116, label %74
i32 97, label %75
i32 118, label %76
i32 119, label %87
i32 122, label %88
i32 90, label %89
]
40: ; preds = %36
%41 = icmp eq i32 %21, %18
br i1 %41, label %48, label %42
42: ; preds = %40
%43 = add nsw i32 %21, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %1, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @strtoul(i8* %46, i32 0, i32 0)
br label %102
48: ; preds = %40
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.26, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %36
br label %102
52: ; preds = %36
%53 = icmp eq i32 %21, %18
br i1 %53, label %60, label %54
54: ; preds = %52
%55 = add nsw i32 %21, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8*, i8** %1, i64 %56
%58 = load i8*, i8** %57
%59 = call i32 @strtoul(i8* %58, i32 0, i32 0)
br label %102
60: ; preds = %52
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.25, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %36
%64 = icmp eq i32 %21, %18
br i1 %64, label %71, label %65
65: ; preds = %63
%66 = add nsw i32 %21, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %1, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @strtoul(i8* %69, i32 0, i32 0)
br label %102
71: ; preds = %63
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.24, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %36
br label %102
75: ; preds = %36
br label %102
76: ; preds = %36
%77 = icmp eq i32 %21, %18
br i1 %77, label %84, label %78
78: ; preds = %76
%79 = add nsw i32 %21, 1
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i8*, i8** %1, i64 %80
%82 = load i8*, i8** %81
%83 = call i32 @strncpy(i8* %11, i8* %82, i32 11)
br label %102
84: ; preds = %76
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %36
br label %102
88: ; preds = %36
store i32 1, i32* %3
br label %102
89: ; preds = %36
store i32 2, i32* %3
br label %102
90: ; preds = %36
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%92 = call i32 @exit(i32 2)
unreachable
93: ; preds = %19
switch i32 %28, label %95 [
i32 0, label %98
i32 1, label %94
]
94: ; preds = %93
br label %98
95: ; preds = %93
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%97 = call i32 @exit(i32 3)
unreachable
98: ; preds = %93, %94
%99 = phi i8* [ %10, %94 ], [ %9, %93 ]
%100 = call i32 @strncpy(i8* %99, i8* %33, i32 1024)
%101 = add nuw nsw i32 %28, 1
br label %102
102: ; preds = %36, %98, %89, %88, %87, %78, %75, %74, %65, %54, %51, %42
%103 = phi i32 [ 2, %89 ], [ 1, %88 ], [ %20, %87 ], [ %20, %78 ], [ %20, %75 ], [ %20, %74 ], [ %20, %65 ], [ %20, %54 ], [ %20, %51 ], [ %20, %42 ], [ %20, %98 ], [ %20, %36 ]
%104 = phi i32 [ %30, %89 ], [ %30, %88 ], [ %30, %87 ], [ %30, %78 ], [ 1, %75 ], [ %30, %74 ], [ %30, %65 ], [ %30, %54 ], [ %30, %51 ], [ %30, %42 ], [ %30, %98 ], [ %30, %36 ]
%105 = phi i32 [ %29, %89 ], [ %29, %88 ], [ %29, %87 ], [ %29, %78 ], [ %29, %75 ], [ %29, %74 ], [ %29, %65 ], [ %29, %54 ], [ %29, %51 ], [ %29, %42 ], [ %29, %98 ], [ 1, %36 ]
%106 = phi i32 [ %28, %89 ], [ %28, %88 ], [ %28, %87 ], [ %28, %78 ], [ %28, %75 ], [ %28, %74 ], [ %28, %65 ], [ %28, %54 ], [ %28, %51 ], [ %28, %42 ], [ %101, %98 ], [ %28, %36 ]
%107 = phi i32 [ %27, %89 ], [ %27, %88 ], [ 1, %87 ], [ %27, %78 ], [ %27, %75 ], [ %27, %74 ], [ %27, %65 ], [ %27, %54 ], [ %27, %51 ], [ %27, %42 ], [ %27, %98 ], [ %27, %36 ]
%108 = phi i32 [ %26, %89 ], [ %26, %88 ], [ %26, %87 ], [ %26, %78 ], [ %26, %75 ], [ %26, %74 ], [ %26, %65 ], [ %26, %54 ], [ 1, %51 ], [ %26, %42 ], [ %26, %98 ], [ %26, %36 ]
%109 = phi i32 [ %25, %89 ], [ %25, %88 ], [ %25, %87 ], [ %25, %78 ], [ %25, %75 ], [ 0, %74 ], [ %25, %65 ], [ %25, %54 ], [ %25, %51 ], [ %25, %42 ], [ %25, %98 ], [ %25, %36 ]
%110 = phi i32 [ %24, %89 ], [ %24, %88 ], [ %24, %87 ], [ %24, %78 ], [ %24, %75 ], [ %24, %74 ], [ %70, %65 ], [ %24, %54 ], [ %24, %51 ], [ %24, %42 ], [ %24, %98 ], [ %24, %36 ]
%111 = phi i32 [ %23, %89 ], [ %23, %88 ], [ %23, %87 ], [ %23, %78 ], [ %23, %75 ], [ %23, %74 ], [ %23, %65 ], [ %59, %54 ], [ %23, %51 ], [ %23, %42 ], [ %23, %98 ], [ %23, %36 ]
%112 = phi i32 [ %22, %89 ], [ %22, %88 ], [ %22, %87 ], [ %22, %78 ], [ %22, %75 ], [ %22, %74 ], [ %22, %65 ], [ %22, %54 ], [ %22, %51 ], [ %47, %42 ], [ %22, %98 ], [ %22, %36 ]
%113 = phi i32 [ %21, %89 ], [ %21, %88 ], [ %21, %87 ], [ %79, %78 ], [ %21, %75 ], [ %21, %74 ], [ %66, %65 ], [ %55, %54 ], [ %21, %51 ], [ %43, %42 ], [ %21, %98 ], [ %21, %36 ]
%114 = add nsw i32 %113, 1
%115 = icmp slt i32 %114, %0
br i1 %115, label %19, label %116
116: ; preds = %102, %2
%117 = phi i32 [ 0, %2 ], [ %103, %102 ]
%118 = phi i32 [ 0, %2 ], [ %104, %102 ]
%119 = phi i32 [ %14, %2 ], [ %105, %102 ]
%120 = phi i32 [ 0, %2 ], [ %107, %102 ]
%121 = phi i32 [ 0, %2 ], [ %108, %102 ]
%122 = phi i32 [ 1, %2 ], [ %109, %102 ]
%123 = phi i32 [ 1073741824, %2 ], [ %110, %102 ]
%124 = phi i32 [ 0, %2 ], [ %111, %102 ]
%125 = phi i32 [ 0, %2 ], [ %112, %102 ]
%126 = icmp eq i32 %119, 0
br i1 %126, label %143, label %127
127: ; preds = %116
%128 = load i32*, i32** @stderr
%129 = load i8*, i8** %1
%130 = call i32 (i32*, i8*, ...) @fprintf(i32* %128, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.6, i64 0, i64 0), i8* %129)
%131 = load i32*, i32** @stderr
%132 = call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i64 21, i64 1, i32* %131)
%133 = load i32*, i32** @stderr
%134 = call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 26, i64 1, i32* %133)
%135 = load i32*, i32** @stderr
%136 = call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0), i64 44, i64 1, i32* %135)
%137 = load i32*, i32** @stderr
%138 = call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i64 41, i64 1, i32* %137)
%139 = load i32*, i32** @stderr
%140 = call i64 @fwrite(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.11, i64 0, i64 0), i64 76, i64 1, i32* %139)
%141 = load i32*, i32** @stderr
%142 = call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.12, i64 0, i64 0), i64 38, i64 1, i32* %141)
br label %263
143: ; preds = %116
%144 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%145 = icmp eq i32* %144, null
br i1 %145, label %146, label %150
146: ; preds = %143
%147 = load i32*, i32** @stderr
%148 = call i32 (i32*, i8*, ...) @fprintf(i32* %147, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %9)
%149 = call i32 @exit(i32 -1)
unreachable
150: ; preds = %143
%151 = icmp eq i32 %118, 0
%152 = select i1 %151, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.15, i64 0, i64 0)
%153 = call i32* @fopen(i8* %10, i8* %152)
%154 = icmp eq i32* %153, null
br i1 %154, label %155, label %159
155: ; preds = %150
%156 = load i32*, i32** @stderr
%157 = call i32 (i32*, i8*, ...) @fprintf(i32* %156, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0), i8* %10)
%158 = call i32 @exit(i32 -1)
unreachable
159: ; preds = %150
%160 = icmp eq i32 %117, 0
br i1 %160, label %165, label %161
161: ; preds = %159
%162 = load i32, i32* @SEEK_END
%163 = call i32 @fseek(i32* %144, i32 0, i32 %162)
%164 = call i64 @ftell(i32* %144)
br label %165
165: ; preds = %161, %159
%166 = phi i64 [ %164, %161 ], [ 0, %159 ]
%167 = load i32, i32* @SEEK_SET
%168 = call i32 @fseek(i32* %144, i32 %125, i32 %167)
%169 = icmp eq i32 %120, 0
%170 = select i1 %169, i32 32, i32 4
%171 = icmp eq i32 %123, 0
br i1 %171, label %254, label %172
172: ; preds = %165
%173 = icmp eq i32 %121, 0
%174 = bitcast [64 x i8]* %7 to i32*
%175 = select i1 %169, i32 0, i32 2
br label %176
176: ; preds = %172, %248
%177 = phi i32 [ 0, %172 ], [ %250, %248 ]
%178 = phi i32 [ %124, %172 ], [ %251, %248 ]
%179 = phi i32 [ %123, %172 ], [ %252, %248 ]
%180 = phi i32 [ -1, %172 ], [ %209, %248 ]
%181 = phi i8 [ undef, %172 ], [ %249, %248 ]
br label %182
182: ; preds = %176, %194
%183 = phi i32 [ %179, %176 ], [ %195, %194 ]
%184 = call i32 @feof(i32* %144)
%185 = icmp eq i32 %184, 0
br i1 %185, label %186, label %254
186: ; preds = %182
br i1 %173, label %197, label %187
187: ; preds = %186
%188 = call i64 @fread(i8* %12, i32 1, i32 1, i32* %144)
%189 = icmp sgt i64 %188, 0
br i1 %189, label %190, label %194
190: ; preds = %187
%191 = load i8, i8* %12
%192 = zext i8 %191 to i32
%193 = call i32 (i32*, i8*, ...) @fprintf(i32* %153, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0), i32 %192)
br label %194
194: ; preds = %190, %187
%195 = add nsw i32 %183, -1
%196 = icmp eq i32 %195, 0
br i1 %196, label %260, label %182
197: ; preds = %186
%198 = and i32 %178, 65535
%199 = sub nuw nsw i32 65536, %198
%200 = icmp eq i32 %198, 0
%201 = icmp eq i32 %180, -1
%202 = select i1 %200, i1 true, i1 %201
%203 = ashr i32 %178, 16
%204 = lshr i32 %178, 24
%205 = add nsw i32 %203, %204
%206 = trunc i32 %205 to i8
%207 = sub i8 -6, %206
%208 = select i1 %202, i8 %207, i8 %181
%209 = select i1 %202, i32 %203, i32 %180
%210 = select i1 %202, i32 1, i32 %177
%211 = icmp ugt i32 %199, %170
%212 = select i1 %211, i32 %170, i32 %199
%213 = call i32 @fread_wrapper(i32* %174, i32 %212, i32* %144, i32* %3, i64 %166, i8* %11)
%214 = icmp eq i32 %213, 0
br i1 %214, label %248, label %215
215: ; preds = %197
%216 = icmp eq i32 %210, 0
br i1 %216, label %220, label %217
217: ; preds = %215
%218 = zext i8 %208 to i32
%219 = call i32 (i32*, i8*, ...) @fprintf(i32* %153, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0), i32 %209, i32 %218)
br label %220
220: ; preds = %217, %215
%221 = lshr i32 %198, %175
%222 = call i32 (i32*, i8*, ...) @fprintf(i32* %153, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.20, i64 0, i64 0), i32 %213, i32 %221)
%223 = lshr i32 %221, 8
%224 = add nuw nsw i32 %223, %221
%225 = add i32 %224, %213
%226 = icmp sgt i32 %213, 0
br i1 %226, label %227, label %242
227: ; preds = %220
%228 = zext i32 %213 to i64
br label %229
229: ; preds = %227, %229
%230 = phi i64 [ 0, %227 ], [ %240, %229 ]
%231 = phi i32 [ %225, %227 ], [ %239, %229 ]
%232 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %230
%233 = load i8, i8* %232
%234 = zext i8 %233 to i32
%235 = call i32 (i32*, i8*, ...) @fprintf(i32* %153, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i64 0, i64 0), i32 %234)
%236 = load i8, i8* %232
%237 = zext i8 %236 to i32
%238 = and i32 %231, 255
%239 = add nuw nsw i32 %238, %237
%240 = add nuw nsw i64 %230, 1
%241 = icmp eq i64 %240, %228
br i1 %241, label %242, label %229
242: ; preds = %229, %220
%243 = phi i32 [ %225, %220 ], [ %239, %229 ]
%244 = trunc i32 %243 to i8
%245 = sub i8 0, %244
%246 = zext i8 %245 to i32
%247 = call i32 (i32*, i8*, ...) @fprintf(i32* %153, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i32 %246)
br label %248
248: ; preds = %242, %197
%249 = phi i8 [ %245, %242 ], [ %208, %197 ]
%250 = phi i32 [ 0, %242 ], [ %210, %197 ]
%251 = add nsw i32 %213, %178
%252 = sub nsw i32 %179, %213
%253 = icmp eq i32 %252, 0
br i1 %253, label %254, label %176
254: ; preds = %248, %182, %165
%255 = icmp eq i32 %122, 0
%256 = icmp ne i32 %121, 0
%257 = select i1 %255, i1 true, i1 %256
br i1 %257, label %260, label %258
258: ; preds = %254
%259 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.23, i64 0, i64 0), i64 12, i64 1, i32* %153)
br label %260
260: ; preds = %194, %258, %254
%261 = call i32 @fclose(i32* %153)
%262 = call i32 @fclose(i32* %144)
br label %263
263: ; preds = %260, %127
%264 = phi i32 [ 1, %127 ], [ 0, %260 ]
ret i32 %264
}