#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
typedef int uint32_t;
struct stat {
  int st_size;
};
struct TYPE_4__ {
  int *e_ident;
  int /*<<< orphan*/ e_phnum;
  int /*<<< orphan*/ e_phoff;
};
struct TYPE_3__ {
  int /*<<< orphan*/ p_offset;
  int /*<<< orphan*/ p_memsz;
  int /*<<< orphan*/ p_filesz;
  int /*<<< orphan*/ p_vaddr;
  int /*<<< orphan*/ p_paddr;
};
typedef int /*<<< orphan*/ FILE;
typedef TYPE_1__ Elf32_Phdr;
typedef TYPE_2__ Elf32_Ehdr;

/* Variables and functions */
size_t EI_CLASS;
size_t EI_DATA;
size_t EI_MAG0;
size_t EI_MAG1;
size_t EI_MAG2;
size_t EI_MAG3;
float ELFCLASS32;
float ELFDATA2MSB;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
void *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int ntohl(int /*<<< orphan*/);
size_t ntohs(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  uint32_t romaddr;
  char *elffile = argv[1];
  char *romfile = argv[2];
  int elffd;
  FILE *romfd;
  void *elfmmap;
  int err;
  struct stat fstats;
  if (argc != 3) {
    printf("argv[1] should be a path to an ELF file\n");
    printf("argv[2] should be a path to an output ROM file\n");
    exit(-1);
  }
  elffd = open(elffile, O_RDONLY);
  if (elffd < 0) {
    perror("open elffile");
    exit(-1);
  }
  romfd = fopen(romfile, "w");
  if (elffd < 0) {
    perror("open romfile");
    exit(-1);
  }
  fprintf(romfd, "@0000_0000\n");
  err = fstat(elffd, &fstats);
  if (err < 0) {
    perror("stat");
    exit(-1);
  }
  elfmmap = mmap(NULL, fstats.st_size, PROT_READ, MAP_PRIVATE, elffd, 0);
  if (elfmmap == MAP_FAILED) {
    perror("mmap");
    exit(-1);
  }
  Elf32_Ehdr *ehdr = elfmmap;
  size_t pnum;
  if (fstats.st_size < sizeof(*ehdr)) {
    printf("ELF File too small\n");
    exit(-1);
  }
  if (ehdr->e_ident[EI_MAG0] != 0x7f || ehdr->e_ident[EI_MAG1] != 'E' ||
      ehdr->e_ident[EI_MAG2] != 'L' || ehdr->e_ident[EI_MAG3] != 'F' ||
      ehdr->e_ident[EI_CLASS] != ELFCLASS32 ||
      ehdr->e_ident[EI_DATA] != ELFDATA2MSB) {
    printf("Invalid ELF\n");
    exit(-1);
  }
  if (fstats.st_size <
      sizeof(Elf32_Phdr) * ntohs(ehdr->e_phnum) + ntohl(ehdr->e_phoff)) {
    printf("ELF File too small\n");
    exit(-1);
  }
  for (romaddr = 0; romaddr < (64 * 1024); romaddr += 4) {
    for (pnum = 0; pnum < ntohs(ehdr->e_phnum); pnum++) {
      Elf32_Phdr *phdr = (Elf32_Phdr *)(elfmmap + (ntohl(ehdr->e_phoff) +
                                                   sizeof(Elf32_Phdr) * pnum));
      uint32_t paddr = ntohl(phdr->p_paddr);
      uint32_t vaddr = ntohl(phdr->p_vaddr);
      uint32_t filesz = ntohl(phdr->p_filesz);
      uint32_t memsz = ntohl(phdr->p_memsz);
      uint32_t offset = ntohl(phdr->p_offset);
      if ((paddr - 0x100000) != romaddr)
        continue;
      printf("PHDR paddr@%zu paddr=0x%08x vaddr=0x%08x filesz=%u memsz=%u\n",
             pnum, paddr, vaddr, filesz, memsz);
      {
        uint8_t *ptr;
        uint32_t i;
        ptr = (uint8_t *)elfmmap;
        ptr = &ptr[offset];
        for (i = 0; i < filesz; i += 4, ptr += 4, romaddr += 4)
          fprintf(romfd, "%02x%02x_%02x%02x\n", ptr[0], ptr[1], ptr[2], ptr[3]);
      }
    }
    if (pnum >= ntohs(ehdr->e_phnum))
      fprintf(romfd, "%02x%02x_%02x%02x\n", 0, 0, 0, 0);
  }
  if (romaddr > (64 * 1024))
    fprintf(stderr, "ROM may exceed size limit of %dk\n", 64);
  munmap(elfmmap, fstats.st_size);
  close(elffd);
  fclose(romfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1231 <main+0x61>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1266 <main+0x96>
lea    0xe02(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x28(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    129a <main+0xca>
lea    0xddd(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %eax,%edi
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   10f0 <fstat@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    12dd <main+0x10d>
lea    0xdb3(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x48(%rbp),%esi
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
mov    0x2ca8(%rip),%rax
mov    (%rax),%ecx
mov    -0x2c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    0x2c7f(%rip),%rcx
cmp    (%rcx),%rax
jne    1330 <main+0x160>
lea    0xd65(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
movslq -0x48(%rbp),%rax
cmp    $0x10,%rax
jae    135e <main+0x18e>
lea    0xd3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2c6c(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x7f,(%rax,%rcx,4)
jne    1427 <main+0x257>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2c19(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x45,(%rax,%rcx,4)
jne    1427 <main+0x257>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2c2e(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x4c,(%rax,%rcx,4)
jne    1427 <main+0x257>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2beb(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x46,(%rax,%rcx,4)
jne    1427 <main+0x257>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2be0(%rip),%rcx
mov    (%rcx),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
mov    0x2ba1(%rip),%rax
ucomiss (%rax),%xmm0
jne    1427 <main+0x257>
jp     1427 <main+0x257>
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    0x2bc4(%rip),%rcx
mov    (%rcx),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
mov    0x2b6d(%rip),%rax
ucomiss (%rax),%xmm0
jne    1427 <main+0x257>
jp     1427 <main+0x257>
jmp    143f <main+0x26f>
lea    0xc71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movslq -0x48(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edi
call   1090 <ntohs@plt>
imul   $0x14,%rax,%rax
mov    %rax,-0x98(%rbp)
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%edi
call   10e0 <ntohl@plt>
mov    -0x98(%rbp),%rcx
mov    %eax,%edx
mov    -0x90(%rbp),%rax
movslq %edx,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    14a4 <main+0x2d4>
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x10000,-0x14(%rbp)
jge    169d <main+0x4cd>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edi
call   1090 <ntohs@plt>
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
cmp    %rcx,%rax
jae    1640 <main+0x470>
mov    -0x40(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
imul   $0x14,-0x58(%rbp),%rdx
add    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x64(%rbp)
mov    -0x60(%rbp),%rax
mov    0xc(%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x68(%rbp)
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
mov    0x4(%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x70(%rbp)
mov    -0x60(%rbp),%rax
mov    (%rax),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x74(%rbp)
mov    -0x64(%rbp),%eax
sub    $0x100000,%eax
cmp    -0x14(%rbp),%eax
je     157c <main+0x3ac>
jmp    162f <main+0x45f>
mov    -0x58(%rbp),%rsi
mov    -0x64(%rbp),%edx
mov    -0x68(%rbp),%ecx
mov    -0x6c(%rbp),%r8d
mov    -0x70(%rbp),%r9d
lea    0xb17(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
movslq -0x74(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    162a <main+0x45a>
mov    -0x38(%rbp),%rax
mov    %eax,%edi
mov    -0x80(%rbp),%rax
mov    (%rax),%edx
mov    -0x80(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x80(%rbp),%rax
mov    0xc(%rax),%r9d
lea    0xaef(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x84(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x84(%rbp)
mov    -0x80(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x80(%rbp)
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    15c1 <main+0x3f1>
jmp    162f <main+0x45f>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    14c0 <main+0x2f0>
mov    -0x58(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edi
call   1090 <ntohs@plt>
mov    %rax,%rcx
mov    -0xb0(%rbp),%rax
cmp    %rcx,%rax
jb     168a <main+0x4ba>
mov    -0x38(%rbp),%rax
mov    %eax,%edi
lea    0xa72(%rip),%rsi
xor    %r9d,%r9d
mov    %r9d,%edx
mov    %r9d,%ecx
mov    %r9d,%r8d
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    168f <main+0x4bf>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    14ab <main+0x2db>
cmpl   $0x10000,-0x14(%rbp)
jle    16c6 <main+0x4f6>
mov    0x28ff(%rip),%rax
mov    (%rax),%edi
lea    0xa42(%rip),%rsi
mov    $0x40,%edx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   1080 <munmap@plt>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
cmp    $0x3,%edi
jne    156a <main+0x38a>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rbx
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
test   %eax,%eax
js     158c <main+0x3ac>
mov    %eax,%ebp
lea    0xdef(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r12
lea    0xddf(%rip),%rsi
mov    %r12d,%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
call   1100 <fstat@plt>
test   %eax,%eax
js     1595 <main+0x3b5>
mov    0x18(%rsp),%ebx
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
mov    0x2d36(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %ebx,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    0x2d16(%rip),%rcx
mov    %rax,0x8(%rsp)
cmp    (%rcx),%rax
je     159e <main+0x3be>
cmp    $0xf,%ebx
jbe    1561 <main+0x381>
mov    %ebp,0x20(%rsp)
mov    0x8(%rsp),%rbp
mov    0x0(%rbp),%rax
mov    0x2d33(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x7f,(%rax,%rcx,4)
jne    1558 <main+0x378>
mov    0x2ce7(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x45,(%rax,%rcx,4)
jne    1558 <main+0x378>
mov    0x2d03(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x4c,(%rax,%rcx,4)
jne    1558 <main+0x378>
mov    0x2cc7(%rip),%rcx
mov    (%rcx),%rcx
cmpl   $0x46,(%rax,%rcx,4)
jne    1558 <main+0x378>
mov    0x2cc3(%rip),%rcx
mov    (%rcx),%rcx
cvtsi2ssl (%rax,%rcx,4),%xmm0
mov    0x2c84(%rip),%rcx
movss  (%rcx),%xmm1
ucomiss %xmm0,%xmm1
jne    1558 <main+0x378>
jp     1558 <main+0x378>
mov    0x2caa(%rip),%rcx
mov    (%rcx),%rcx
xorps  %xmm0,%xmm0
cvtsi2ssl (%rax,%rcx,4),%xmm0
mov    0x2c50(%rip),%rax
movss  (%rax),%xmm1
ucomiss %xmm0,%xmm1
jne    1558 <main+0x378>
jp     1558 <main+0x378>
mov    %ebx,0x1c(%rsp)
movslq %ebx,%rbx
mov    0x8(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %rbp,%rcx
lea    (%rax,%rax,4),%rbp
mov    0xc(%rcx),%edi
call   10f0 <ntohl@plt>
cltq
lea    (%rax,%rbp,4),%rax
cmp    %rbx,%rax
ja     1561 <main+0x381>
lea    0xceb(%rip),%r13
xor    %ebx,%ebx
mov    0x8(%rsp),%rbp
mov    %r12,0x10(%rsp)
jmp    13a2 <main+0x1c2>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rax
lea    0x4(%rax),%ebx
cmp    $0xfffc,%eax
jge    1506 <main+0x326>
mov    0x8(%rbp),%edi
call   10a0 <ntohs@plt>
test   %rax,%rax
je     14d0 <main+0x2f0>
mov    %ebx,%eax
mov    %rax,(%rsp)
xor    %r14d,%r14d
jmp    13e6 <main+0x206>
xchg   %ax,%ax
mov    0x10(%rsp),%r12
lea    0xc96(%rip),%r13
add    $0x1,%r14
mov    0x8(%rsp),%rbp
mov    0x8(%rbp),%edi
call   10a0 <ntohs@plt>
cmp    %rax,%r14
jae    14d9 <main+0x2f9>
mov    0xc(%rbp),%edi
call   10f0 <ntohl@plt>
cltq
lea    (%r14,%r14,4),%rcx
lea    (%rax,%rcx,4),%rbx
mov    0x10(%rbp,%rbx,1),%edi
call   10f0 <ntohl@plt>
mov    %eax,%r13d
mov    0xc(%rbp,%rbx,1),%edi
call   10f0 <ntohl@plt>
mov    %eax,0x24(%rsp)
mov    0x8(%rbp,%rbx,1),%edi
call   10f0 <ntohl@plt>
mov    %eax,%r15d
mov    0x4(%rbp,%rbx,1),%edi
call   10f0 <ntohl@plt>
mov    %eax,%r12d
mov    0x0(%rbp,%rbx,1),%edi
call   10f0 <ntohl@plt>
mov    %eax,%ebp
lea    -0x100000(%r13),%eax
cmp    (%rsp),%eax
jne    13c0 <main+0x1e0>
lea    0xbde(%rip),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    0x24(%rsp),%ecx
mov    %r15d,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
jle    13c0 <main+0x1e0>
movslq %ebp,%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rbx
xor    %ebp,%ebp
mov    0x10(%rsp),%r12
lea    0xbe1(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%edx
mov    0x4(%rbx,%rbp,4),%ecx
mov    0x8(%rbx,%rbp,4),%r8d
mov    0xc(%rbx,%rbp,4),%r9d
mov    %r12d,%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
add    $0x4,%rbp
cmp    %r15d,%ebp
jl     1490 <main+0x2b0>
mov    (%rsp),%rax
add    %ebp,%eax
mov    %rax,(%rsp)
jmp    13cc <main+0x1ec>
cs nopw 0x0(%rax,%rax,1)
xor    %r14d,%r14d
mov    %ebx,%eax
mov    %rax,(%rsp)
mov    0x8(%rbp),%edi
call   10a0 <ntohs@plt>
cmp    %rax,%r14
jb     1390 <main+0x1b0>
mov    %r12d,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1390 <main+0x1b0>
cmp    $0x10000,%ebx
je     152a <main+0x34a>
mov    0x2a9b(%rip),%rax
mov    (%rax),%edi
lea    0xb57(%rip),%rsi
mov    $0x40,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbp,%rdi
mov    0x1c(%rsp),%esi
call   1090 <munmap@plt>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb38(%rip),%rdi
jmp    157d <main+0x39d>
lea    0xb3b(%rip),%rdi
jmp    157d <main+0x39d>
lea    0xb45(%rip),%rdi
call   1030 <puts@plt>
lea    0xb61(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xa6d(%rip),%rdi
jmp    15a5 <main+0x3c5>
lea    0xa7f(%rip),%rdi
jmp    15a5 <main+0x3c5>
lea    0xa7b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.TYPE_4__ = type { i32*, i32, i32 }
%struct.TYPE_3__ = type { i32, i32, i32, i32, i32 }
@.str = [41 x i8] c"argv[1] should be a path to an ELF file\0A\00"
@.str.1 = [48 x i8] c"argv[2] should be a path to an output ROM file\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"open elffile\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [13 x i8] c"open romfile\00"
@.str.5 = [12 x i8] c"@0000_0000\0A\00"
@.str.6 = [5 x i8] c"stat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [5 x i8] c"mmap\00"
@.str.8 = [20 x i8] c"ELF File too small\0A\00"
@EI_MAG0 = global i64 0
@EI_MAG1 = global i64 0
@EI_MAG2 = global i64 0
@EI_MAG3 = global i64 0
@EI_CLASS = global i64 0
@ELFCLASS32 = global float 0.000000e+00
@EI_DATA = global i64 0
@ELFDATA2MSB = global float 0.000000e+00
@.str.9 = [13 x i8] c"Invalid ELF\0A\00"
@.str.10 = [61 x i8] c"PHDR paddr@%zu paddr=0x%08x vaddr=0x%08x filesz=%u memsz=%u\0A\00"
@.str.11 = [19 x i8] c"%02x%02x_%02x%02x\0A\00"
@stderr = global i32 0
@.str.12 = [34 x i8] c"ROM may exceed size limit of %dk\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.stat
%14 = alloca %struct.TYPE_4__*
%15 = alloca i64
%16 = alloca %struct.TYPE_3__*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32*
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
store i8* %29, i8** %8
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 3
br i1 %31, label %32, label %36
32: ; preds = %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %2
%37 = load i8*, i8** %7
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %36
%46 = load i8*, i8** %8
%47 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %47, i32** %10
%48 = load i32, i32* %9
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %45
%51 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 -1)
unreachable
53: ; preds = %45
%54 = load i32*, i32** %10
%55 = ptrtoint i32* %54 to i32
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* %9
%58 = call i32 @fstat(i32 %57, %struct.stat* %13)
store i32 %58, i32* %12
%59 = load i32, i32* %12
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %53
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %53
%65 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%66 = load i32, i32* %65
%67 = load i32, i32* @PROT_READ
%68 = load i32, i32* @MAP_PRIVATE
%69 = load i32, i32* %9
%70 = call i8* @mmap(i32* null, i32 %66, i32 %67, i32 %68, i32 %69, i32 0)
store i8* %70, i8** %11
%71 = load i8*, i8** %11
%72 = load i8*, i8** @MAP_FAILED
%73 = icmp eq i8* %71, %72
br i1 %73, label %74, label %77
74: ; preds = %64
%75 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%76 = call i32 @exit(i32 -1)
unreachable
77: ; preds = %64
%78 = load i8*, i8** %11
%79 = bitcast i8* %78 to %struct.TYPE_4__*
store %struct.TYPE_4__* %79, %struct.TYPE_4__** %14
%80 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%81 = load i32, i32* %80
%82 = sext i32 %81 to i64
%83 = icmp ult i64 %82, 16
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%86 = call i32 @exit(i32 -1)
unreachable
87: ; preds = %77
%88 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%89 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %88, i32 0, i32 0
%90 = load i32*, i32** %89
%91 = load i64, i64* @EI_MAG0
%92 = getelementptr inbounds i32, i32* %90, i64 %91
%93 = load i32, i32* %92
%94 = icmp ne i32 %93, 127
br i1 %94, label %139, label %95
95: ; preds = %87
%96 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%97 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %96, i32 0, i32 0
%98 = load i32*, i32** %97
%99 = load i64, i64* @EI_MAG1
%100 = getelementptr inbounds i32, i32* %98, i64 %99
%101 = load i32, i32* %100
%102 = icmp ne i32 %101, 69
br i1 %102, label %139, label %103
103: ; preds = %95
%104 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%105 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %104, i32 0, i32 0
%106 = load i32*, i32** %105
%107 = load i64, i64* @EI_MAG2
%108 = getelementptr inbounds i32, i32* %106, i64 %107
%109 = load i32, i32* %108
%110 = icmp ne i32 %109, 76
br i1 %110, label %139, label %111
111: ; preds = %103
%112 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%113 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %112, i32 0, i32 0
%114 = load i32*, i32** %113
%115 = load i64, i64* @EI_MAG3
%116 = getelementptr inbounds i32, i32* %114, i64 %115
%117 = load i32, i32* %116
%118 = icmp ne i32 %117, 70
br i1 %118, label %139, label %119
119: ; preds = %111
%120 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%121 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %120, i32 0, i32 0
%122 = load i32*, i32** %121
%123 = load i64, i64* @EI_CLASS
%124 = getelementptr inbounds i32, i32* %122, i64 %123
%125 = load i32, i32* %124
%126 = sitofp i32 %125 to float
%127 = load float, float* @ELFCLASS32
%128 = fcmp une float %126, %127
br i1 %128, label %139, label %129
129: ; preds = %119
%130 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%131 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %130, i32 0, i32 0
%132 = load i32*, i32** %131
%133 = load i64, i64* @EI_DATA
%134 = getelementptr inbounds i32, i32* %132, i64 %133
%135 = load i32, i32* %134
%136 = sitofp i32 %135 to float
%137 = load float, float* @ELFDATA2MSB
%138 = fcmp une float %136, %137
br i1 %138, label %139, label %142
139: ; preds = %129, %119, %111, %103, %95, %87
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%141 = call i32 @exit(i32 -1)
unreachable
142: ; preds = %129
%143 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%144 = load i32, i32* %143
%145 = sext i32 %144 to i64
%146 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%147 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %146, i32 0, i32 1
%148 = load i32, i32* %147
%149 = call i64 @ntohs(i32 %148)
%150 = mul i64 20, %149
%151 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%152 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %151, i32 0, i32 2
%153 = load i32, i32* %152
%154 = call i32 @ntohl(i32 %153)
%155 = sext i32 %154 to i64
%156 = add i64 %150, %155
%157 = icmp ult i64 %145, %156
br i1 %157, label %158, label %161
158: ; preds = %142
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%160 = call i32 @exit(i32 -1)
unreachable
161: ; preds = %142
store i32 0, i32* %6
br label %162
162: ; preds = %266, %161
%163 = load i32, i32* %6
%164 = icmp slt i32 %163, 65536
br i1 %164, label %165, label %269
165: ; preds = %162
store i64 0, i64* %15
br label %166
166: ; preds = %251, %165
%167 = load i64, i64* %15
%168 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%169 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %168, i32 0, i32 1
%170 = load i32, i32* %169
%171 = call i64 @ntohs(i32 %170)
%172 = icmp ult i64 %167, %171
br i1 %172, label %173, label %254
173: ; preds = %166
%174 = load i8*, i8** %11
%175 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%176 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %175, i32 0, i32 2
%177 = load i32, i32* %176
%178 = call i32 @ntohl(i32 %177)
%179 = sext i32 %178 to i64
%180 = load i64, i64* %15
%181 = mul i64 20, %180
%182 = add i64 %179, %181
%183 = getelementptr i8, i8* %174, i64 %182
%184 = bitcast i8* %183 to %struct.TYPE_3__*
store %struct.TYPE_3__* %184, %struct.TYPE_3__** %16
%185 = load %struct.TYPE_3__*, %struct.TYPE_3__** %16
%186 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %185, i32 0, i32 4
%187 = load i32, i32* %186
%188 = call i32 @ntohl(i32 %187)
store i32 %188, i32* %17
%189 = load %struct.TYPE_3__*, %struct.TYPE_3__** %16
%190 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %189, i32 0, i32 3
%191 = load i32, i32* %190
%192 = call i32 @ntohl(i32 %191)
store i32 %192, i32* %18
%193 = load %struct.TYPE_3__*, %struct.TYPE_3__** %16
%194 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %193, i32 0, i32 2
%195 = load i32, i32* %194
%196 = call i32 @ntohl(i32 %195)
store i32 %196, i32* %19
%197 = load %struct.TYPE_3__*, %struct.TYPE_3__** %16
%198 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %197, i32 0, i32 1
%199 = load i32, i32* %198
%200 = call i32 @ntohl(i32 %199)
store i32 %200, i32* %20
%201 = load %struct.TYPE_3__*, %struct.TYPE_3__** %16
%202 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %201, i32 0, i32 0
%203 = load i32, i32* %202
%204 = call i32 @ntohl(i32 %203)
store i32 %204, i32* %21
%205 = load i32, i32* %17
%206 = sub nsw i32 %205, 1048576
%207 = load i32, i32* %6
%208 = icmp ne i32 %206, %207
br i1 %208, label %209, label %210
209: ; preds = %173
br label %251
210: ; preds = %173
%211 = load i64, i64* %15
%212 = load i32, i32* %17
%213 = load i32, i32* %18
%214 = load i32, i32* %19
%215 = load i32, i32* %20
%216 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.10, i64 0, i64 0), i64 %211, i32 %212, i32 %213, i32 %214, i32 %215)
%217 = load i8*, i8** %11
%218 = bitcast i8* %217 to i32*
store i32* %218, i32** %22
%219 = load i32*, i32** %22
%220 = load i32, i32* %21
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i32, i32* %219, i64 %221
store i32* %222, i32** %22
store i32 0, i32* %23
br label %223
223: ; preds = %243, %210
%224 = load i32, i32* %23
%225 = load i32, i32* %19
%226 = icmp slt i32 %224, %225
br i1 %226, label %227, label %250
227: ; preds = %223
%228 = load i32*, i32** %10
%229 = ptrtoint i32* %228 to i32
%230 = load i32*, i32** %22
%231 = getelementptr inbounds i32, i32* %230, i64 0
%232 = load i32, i32* %231
%233 = load i32*, i32** %22
%234 = getelementptr inbounds i32, i32* %233, i64 1
%235 = load i32, i32* %234
%236 = load i32*, i32** %22
%237 = getelementptr inbounds i32, i32* %236, i64 2
%238 = load i32, i32* %237
%239 = load i32*, i32** %22
%240 = getelementptr inbounds i32, i32* %239, i64 3
%241 = load i32, i32* %240
%242 = call i32 (i32, i8*, ...) @fprintf(i32 %229, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %232, i32 %235, i32 %238, i32 %241)
br label %243
243: ; preds = %227
%244 = load i32, i32* %23
%245 = add nsw i32 %244, 4
store i32 %245, i32* %23
%246 = load i32*, i32** %22
%247 = getelementptr inbounds i32, i32* %246, i64 4
store i32* %247, i32** %22
%248 = load i32, i32* %6
%249 = add nsw i32 %248, 4
store i32 %249, i32* %6
br label %223
250: ; preds = %223
br label %251
251: ; preds = %250, %209
%252 = load i64, i64* %15
%253 = add i64 %252, 1
store i64 %253, i64* %15
br label %166
254: ; preds = %166
%255 = load i64, i64* %15
%256 = load %struct.TYPE_4__*, %struct.TYPE_4__** %14
%257 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %256, i32 0, i32 1
%258 = load i32, i32* %257
%259 = call i64 @ntohs(i32 %258)
%260 = icmp uge i64 %255, %259
br i1 %260, label %261, label %265
261: ; preds = %254
%262 = load i32*, i32** %10
%263 = ptrtoint i32* %262 to i32
%264 = call i32 (i32, i8*, ...) @fprintf(i32 %263, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 0, i32 0, i32 0, i32 0)
br label %265
265: ; preds = %261, %254
br label %266
266: ; preds = %265
%267 = load i32, i32* %6
%268 = add nsw i32 %267, 4
store i32 %268, i32* %6
br label %162
269: ; preds = %162
%270 = load i32, i32* %6
%271 = icmp sgt i32 %270, 65536
br i1 %271, label %272, label %275
272: ; preds = %269
%273 = load i32, i32* @stderr
%274 = call i32 (i32, i8*, ...) @fprintf(i32 %273, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i32 64)
br label %275
275: ; preds = %272, %269
%276 = load i8*, i8** %11
%277 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%278 = load i32, i32* %277
%279 = call i32 @munmap(i8* %276, i32 %278)
%280 = load i32, i32* %9
%281 = call i32 @close(i32 %280)
%282 = load i32*, i32** %10
%283 = call i32 @fclose(i32* %282)
%284 = load i32, i32* %3
ret i32 %284
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@.str.2 = [13 x i8] c"open elffile\00"
@.str.3 = [2 x i8] c"w\00"
@.str.5 = [12 x i8] c"@0000_0000\0A\00"
@.str.6 = [5 x i8] c"stat\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [5 x i8] c"mmap\00"
@EI_MAG0 = global i64 0
@EI_MAG1 = global i64 0
@EI_MAG2 = global i64 0
@EI_MAG3 = global i64 0
@EI_CLASS = global i64 0
@ELFCLASS32 = global float 0.000000e+00
@EI_DATA = global i64 0
@ELFDATA2MSB = global float 0.000000e+00
@.str.10 = [61 x i8] c"PHDR paddr@%zu paddr=0x%08x vaddr=0x%08x filesz=%u memsz=%u\0A\00"
@.str.11 = [19 x i8] c"%02x%02x_%02x%02x\0A\00"
@stderr = global i32 0
@.str.12 = [34 x i8] c"ROM may exceed size limit of %dk\0A\00"
@str.13 = [12 x i8] c"Invalid ELF\00"
@str.14 = [19 x i8] c"ELF File too small\00"
@str.15 = [40 x i8] c"argv[1] should be a path to an ELF file\00"
@str.16 = [47 x i8] c"argv[2] should be a path to an output ROM file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = bitcast %struct.stat* %3 to i8*
%9 = icmp eq i32 %0, 3
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.15, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.16, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %5, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %14
%22 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = ptrtoint i32* %22 to i64
%24 = trunc i64 %23 to i32
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @fstat(i32 %16, %struct.stat* %3)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %21
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = load i32, i32* @PROT_READ
%35 = load i32, i32* @MAP_PRIVATE
%36 = tail call i8* @mmap(i32* null, i32 %33, i32 %34, i32 %35, i32 %16, i32 0)
%37 = load i8*, i8** @MAP_FAILED
%38 = icmp eq i8* %36, %37
br i1 %38, label %39, label %42
39: ; preds = %31
%40 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%41 = tail call i32 @exit(i32 -1)
unreachable
42: ; preds = %31
%43 = sext i32 %33 to i64
%44 = icmp ult i32 %33, 16
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%47 = tail call i32 @exit(i32 -1)
unreachable
48: ; preds = %42
%49 = bitcast i8* %36 to i32**
%50 = load i32*, i32** %49
%51 = load i64, i64* @EI_MAG0
%52 = getelementptr inbounds i32, i32* %50, i64 %51
%53 = load i32, i32* %52
%54 = icmp eq i32 %53, 127
br i1 %54, label %55, label %84
55: ; preds = %48
%56 = load i64, i64* @EI_MAG1
%57 = getelementptr inbounds i32, i32* %50, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 69
br i1 %59, label %60, label %84
60: ; preds = %55
%61 = load i64, i64* @EI_MAG2
%62 = getelementptr inbounds i32, i32* %50, i64 %61
%63 = load i32, i32* %62
%64 = icmp eq i32 %63, 76
br i1 %64, label %65, label %84
65: ; preds = %60
%66 = load i64, i64* @EI_MAG3
%67 = getelementptr inbounds i32, i32* %50, i64 %66
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, 70
br i1 %69, label %70, label %84
70: ; preds = %65
%71 = load i64, i64* @EI_CLASS
%72 = getelementptr inbounds i32, i32* %50, i64 %71
%73 = load i32, i32* %72
%74 = sitofp i32 %73 to float
%75 = load float, float* @ELFCLASS32
%76 = fcmp une float %75, %74
br i1 %76, label %84, label %77
77: ; preds = %70
%78 = load i64, i64* @EI_DATA
%79 = getelementptr inbounds i32, i32* %50, i64 %78
%80 = load i32, i32* %79
%81 = sitofp i32 %80 to float
%82 = load float, float* @ELFDATA2MSB
%83 = fcmp une float %82, %81
br i1 %83, label %84, label %87
84: ; preds = %77, %70, %65, %60, %55, %48
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%86 = tail call i32 @exit(i32 -1)
unreachable
87: ; preds = %77
%88 = getelementptr inbounds i8, i8* %36, i64 8
%89 = bitcast i8* %88 to i32*
%90 = load i32, i32* %89
%91 = tail call i64 @ntohs(i32 %90)
%92 = mul i64 %91, 20
%93 = getelementptr inbounds i8, i8* %36, i64 12
%94 = bitcast i8* %93 to i32*
%95 = load i32, i32* %94
%96 = tail call i32 @ntohl(i32 %95)
%97 = sext i32 %96 to i64
%98 = add i64 %92, %97
%99 = icmp ugt i64 %98, %43
br i1 %99, label %102, label %100
100: ; preds = %87
%101 = bitcast i8* %36 to i32*
br label %105
102: ; preds = %87
%103 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.14, i64 0, i64 0))
%104 = tail call i32 @exit(i32 -1)
unreachable
105: ; preds = %100, %176
%106 = phi i32 [ 0, %100 ], [ %177, %176 ]
%107 = load i32, i32* %89
%108 = tail call i64 @ntohs(i32 %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %168, label %110
110: ; preds = %105, %162
%111 = phi i32 [ %163, %162 ], [ %106, %105 ]
%112 = phi i64 [ %164, %162 ], [ 0, %105 ]
%113 = load i32, i32* %94
%114 = tail call i32 @ntohl(i32 %113)
%115 = sext i32 %114 to i64
%116 = mul i64 %112, 20
%117 = add i64 %116, %115
%118 = getelementptr i8, i8* %36, i64 %117
%119 = getelementptr inbounds i8, i8* %118, i64 16
%120 = bitcast i8* %119 to i32*
%121 = load i32, i32* %120
%122 = tail call i32 @ntohl(i32 %121)
%123 = getelementptr inbounds i8, i8* %118, i64 12
%124 = bitcast i8* %123 to i32*
%125 = load i32, i32* %124
%126 = tail call i32 @ntohl(i32 %125)
%127 = getelementptr inbounds i8, i8* %118, i64 8
%128 = bitcast i8* %127 to i32*
%129 = load i32, i32* %128
%130 = tail call i32 @ntohl(i32 %129)
%131 = getelementptr inbounds i8, i8* %118, i64 4
%132 = bitcast i8* %131 to i32*
%133 = load i32, i32* %132
%134 = tail call i32 @ntohl(i32 %133)
%135 = bitcast i8* %118 to i32*
%136 = load i32, i32* %135
%137 = tail call i32 @ntohl(i32 %136)
%138 = add nsw i32 %122, -1048576
%139 = icmp eq i32 %138, %111
br i1 %139, label %140, label %162
140: ; preds = %110
%141 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.10, i64 0, i64 0), i64 %112, i32 %122, i32 %126, i32 %130, i32 %134)
%142 = icmp sgt i32 %130, 0
br i1 %142, label %143, label %162
143: ; preds = %140
%144 = sext i32 %137 to i64
%145 = getelementptr inbounds i32, i32* %101, i64 %144
br label %146
146: ; preds = %143, %146
%147 = phi i32 [ %158, %146 ], [ 0, %143 ]
%148 = phi i32* [ %159, %146 ], [ %145, %143 ]
%149 = phi i32 [ %160, %146 ], [ %111, %143 ]
%150 = load i32, i32* %148
%151 = getelementptr inbounds i32, i32* %148, i64 1
%152 = load i32, i32* %151
%153 = getelementptr inbounds i32, i32* %148, i64 2
%154 = load i32, i32* %153
%155 = getelementptr inbounds i32, i32* %148, i64 3
%156 = load i32, i32* %155
%157 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 %150, i32 %152, i32 %154, i32 %156)
%158 = add nuw nsw i32 %147, 4
%159 = getelementptr inbounds i32, i32* %148, i64 4
%160 = add nsw i32 %149, 4
%161 = icmp slt i32 %158, %130
br i1 %161, label %146, label %162
162: ; preds = %146, %140, %110
%163 = phi i32 [ %111, %110 ], [ %111, %140 ], [ %160, %146 ]
%164 = add nuw i64 %112, 1
%165 = load i32, i32* %89
%166 = tail call i64 @ntohs(i32 %165)
%167 = icmp ult i64 %164, %166
br i1 %167, label %110, label %168
168: ; preds = %162, %105
%169 = phi i64 [ 0, %105 ], [ %164, %162 ]
%170 = phi i32 [ %106, %105 ], [ %163, %162 ]
%171 = load i32, i32* %89
%172 = tail call i64 @ntohs(i32 %171)
%173 = icmp ult i64 %169, %172
br i1 %173, label %176, label %174
174: ; preds = %168
%175 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0), i32 0, i32 0, i32 0, i32 0)
br label %176
176: ; preds = %168, %174
%177 = add nsw i32 %170, 4
%178 = icmp slt i32 %170, 65532
br i1 %178, label %105, label %179
179: ; preds = %176
%180 = icmp eq i32 %177, 65536
br i1 %180, label %184, label %181
181: ; preds = %179
%182 = load i32, i32* @stderr
%183 = tail call i32 (i32, i8*, ...) @fprintf(i32 %182, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.12, i64 0, i64 0), i32 64)
br label %184
184: ; preds = %181, %179
%185 = tail call i32 @munmap(i8* %36, i32 %33)
%186 = tail call i32 @close(i32 %16)
%187 = tail call i32 @fclose(i32* %22)
ret i32 0
}