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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
scalar_t__ close(int);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lseek(int, unsigned int, int /*<<< orphan*/);
int /*<<< orphan*/ memcmp(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
unsigned int write(int, char *, unsigned int);
int main(int argc, char **argv) {
  char buffer[1024], *q, *r;
  unsigned int i, j, k, start, end, offset;
  FILE *map;
  struct stat s;
  int image, tail;
  start = end = 0;
  if (stat(argv[3], &s) < 0)
    die(argv[3]);
  map = fopen(argv[2], "r");
  if (!map)
    die(argv[2]);
  while (fgets(buffer, 1024, map)) {
    if (!strcmp(buffer + 8, " T start\n") || !strcmp(buffer + 16, " T start\n"))
      start = strtoul(buffer, NULL, 16);
    else if (!strcmp(buffer + 8, " A end\n") ||
             !strcmp(buffer + 16, " A end\n"))
      end = strtoul(buffer, NULL, 16);
  }
  fclose(map);
  if (!start || !end) {
    fprintf(stderr, "Could not determine start and end from System.map\n");
    exit(1);
  }
  if ((image = open(argv[1], O_RDWR)) < 0)
    die(argv[1]);
  if (read(image, buffer, 512) != 512)
    die(argv[1]);
  if (!memcmp(buffer, "\177ELF", 4)) {
    unsigned int *p = (unsigned int *)(buffer + *(unsigned int *)(buffer + 28));
    i = p[1] + *(unsigned int *)(buffer + 24) - p[2];
    if (lseek(image, i, 0) < 0)
      die("lseek");
    if (read(image, buffer, 512) != 512)
      die(argv[1]);
    j = 0;
  } else if (*(unsigned int *)buffer == 0x01030107) {
    i = j = 32;
  } else {
    fprintf(stderr, "Not ELF nor a.out. Don't blame me.\n");
    exit(1);
  }
  k = i;
  i += ((*(unsigned short *)(buffer + j + 2)) << 2) - 512;
  if (lseek(image, i, 0) < 0)
    die("lseek");
  if (read(image, buffer, 1024) != 1024)
    die(argv[1]);
  for (q = buffer, r = q + 512; q < r; q += 4) {
    if (*q == 'H' && q[1] == 'd' && q[2] == 'r' && q[3] == 'S')
      break;
  }
  if (q == r) {
    fprintf(stderr, "Couldn't find headers signature in the kernel.\n");
    exit(1);
  }
  offset = i + (q - buffer) + 10;
  if (lseek(image, offset, 0) < 0)
    die("lseek");
  *(unsigned *)buffer = 0;
  *(unsigned *)(buffer + 4) = 0x01000000;
  *(unsigned *)(buffer + 8) = ((end + 32 + 4095) & ~4095);
  *(unsigned *)(buffer + 12) = s.st_size;
  if (write(image, buffer + 2, 14) != 14)
    die(argv[1]);
  if (lseek(image, k - start + ((end + 32 + 4095) & ~4095), 0) < 0)
    die("lseek");
  if ((tail = open(argv[3], O_RDONLY)) < 0)
    die(argv[3]);
  while ((i = read(tail, buffer, 1024)) > 0)
    if (write(image, buffer, i) != i)
      die(argv[1]);
  if (close(image) < 0)
    die("close");
  if (close(tail) < 0)
    die("close");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x434(%rbp)
movl   $0x0,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x448(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jge    1248 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xda9(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    127e <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <die@plt>
jmp    1283 <main+0x93>
lea    -0x410(%rbp),%rdi
mov    -0x440(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     136a <main+0x17a>
lea    -0x410(%rbp),%rdi
add    $0x8,%rdi
lea    0xd4b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     12e5 <main+0xf5>
lea    -0x410(%rbp),%rdi
add    $0x10,%rdi
lea    0xd2b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1305 <main+0x115>
lea    -0x410(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x430(%rbp)
jmp    1365 <main+0x175>
lea    -0x410(%rbp),%rdi
add    $0x8,%rdi
lea    0xcf5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     1345 <main+0x155>
lea    -0x410(%rbp),%rdi
add    $0x10,%rdi
lea    0xcd5(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1360 <main+0x170>
lea    -0x410(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x434(%rbp)
jmp    1365 <main+0x175>
jmp    1283 <main+0x93>
mov    -0x440(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x430(%rbp)
je     1390 <main+0x1a0>
cmpl   $0x0,-0x434(%rbp)
jne    13af <main+0x1bf>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
lea    0xc74(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2c2a(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x44c(%rbp)
cmp    $0x0,%eax
jge    13e1 <main+0x1f1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
je     1410 <main+0x220>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
lea    -0x410(%rbp),%rdi
lea    0xc29(%rip),%rsi
mov    $0x4,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%eax
jne    14cf <main+0x2df>
lea    -0x410(%rbp),%rax
mov    -0x3f4(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rax
mov    0x4(%rax),%eax
add    -0x3f8(%rbp),%eax
mov    -0x458(%rbp),%rcx
sub    0x8(%rcx),%eax
mov    %eax,-0x424(%rbp)
mov    -0x44c(%rbp),%edi
mov    -0x424(%rbp),%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1491 <main+0x2a1>
lea    0xbc0(%rip),%rdi
call   10f0 <die@plt>
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
je     14c0 <main+0x2d0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
movl   $0x0,-0x428(%rbp)
jmp    151c <main+0x32c>
cmpl   $0x1030107,-0x410(%rbp)
01 03 01
jne    14f8 <main+0x308>
movl   $0x20,-0x428(%rbp)
movl   $0x20,-0x424(%rbp)
jmp    1517 <main+0x327>
mov    0x2ad1(%rip),%rax
mov    (%rax),%edi
lea    0xb4a(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    151c <main+0x32c>
mov    -0x424(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x428(%rbp),%eax
movzwl -0x40e(%rbp,%rax,1),%eax
ff
shl    $0x2,%eax
sub    $0x200,%eax
add    -0x424(%rbp),%eax
mov    %eax,-0x424(%rbp)
mov    -0x44c(%rbp),%edi
mov    -0x424(%rbp),%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1573 <main+0x383>
lea    0xade(%rip),%rdi
call   10f0 <die@plt>
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0x400,%eax
je     15a2 <main+0x3b2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x420(%rbp)
mov    -0x418(%rbp),%rax
cmp    -0x420(%rbp),%rax
jae    1648 <main+0x458>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
jne    162c <main+0x43c>
mov    -0x418(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    162c <main+0x43c>
mov    -0x418(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x72,%eax
jne    162c <main+0x43c>
mov    -0x418(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x53,%eax
jne    162c <main+0x43c>
jmp    1648 <main+0x458>
jmp    1631 <main+0x441>
mov    -0x418(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x418(%rbp)
jmp    15c4 <main+0x3d4>
mov    -0x418(%rbp),%rax
cmp    -0x420(%rbp),%rax
jne    167b <main+0x48b>
mov    0x296d(%rip),%rax
mov    (%rax),%edi
lea    0xa0a(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x424(%rbp),%eax
mov    -0x418(%rbp),%rcx
lea    -0x410(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0xa,%rax
mov    %eax,-0x438(%rbp)
mov    -0x44c(%rbp),%edi
mov    -0x438(%rbp),%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    16c8 <main+0x4d8>
lea    0x989(%rip),%rdi
call   10f0 <die@plt>
movl   $0x0,-0x410(%rbp)
movl   $0x1000000,-0x40c(%rbp)
mov    -0x434(%rbp),%eax
add    $0x20,%eax
add    $0xfff,%eax
and    $0xfffff000,%eax
mov    %eax,-0x408(%rbp)
mov    -0x448(%rbp),%eax
mov    %eax,-0x404(%rbp)
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
add    $0x2,%rsi
mov    $0xe,%edx
call   1030 <write@plt>
cmp    $0xe,%eax
je     1732 <main+0x542>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
mov    -0x44c(%rbp),%edi
mov    -0x42c(%rbp),%esi
sub    -0x430(%rbp),%esi
mov    -0x434(%rbp),%eax
add    $0x20,%eax
add    $0xfff,%eax
and    $0xfffff000,%eax
add    %eax,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1776 <main+0x586>
lea    0x8db(%rip),%rdi
call   10f0 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x285b(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x450(%rbp)
cmp    $0x0,%eax
jge    17a8 <main+0x5b8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <die@plt>
jmp    17ad <main+0x5bd>
mov    -0x450(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jbe    1809 <main+0x619>
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <write@plt>
cmp    -0x424(%rbp),%eax
je     1804 <main+0x614>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
jmp    17ad <main+0x5bd>
mov    -0x44c(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    182a <main+0x63a>
lea    0x881(%rip),%rdi
call   10f0 <die@plt>
mov    -0x450(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    184b <main+0x65b>
lea    0x860(%rip),%rdi
call   10f0 <die@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%rbp
mov    0x18(%rsi),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jns    1210 <main+0x30>
mov    0x18(%rbp),%rdi
call   10e0 <die@plt>
mov    0x10(%rbp),%rdi
lea    0xde5(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1231 <main+0x51>
mov    0x10(%rbp),%rdi
call   10e0 <die@plt>
mov    %rbp,0x18(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     130a <main+0x12a>
lea    0x28(%rsp),%rbp
xor    %r13d,%r13d
lea    0xda2(%rip),%r14
lea    0x20(%rsp),%r15
movl   $0x0,0xc(%rsp)
jmp    1297 <main+0xb7>
nop
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1315 <main+0x135>
mov    $0xa,%edx
mov    %rbp,%rdi
mov    %r14,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
je     1270 <main+0x90>
mov    $0xa,%edx
lea    0x30(%rsp),%rdi
mov    %r14,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
je     1270 <main+0x90>
mov    $0x8,%edx
mov    %rbp,%rdi
lea    0xd3c(%rip),%r12
mov    %r12,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
je     12f2 <main+0x112>
mov    $0x8,%edx
lea    0x30(%rsp),%rdi
mov    %r12,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
jne    1282 <main+0xa2>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %eax,0xc(%rsp)
jmp    1282 <main+0xa2>
movl   $0x0,0xc(%rsp)
xor    %r13d,%r13d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r13,%rbx
test   %ebx,%ebx
mov    0xc(%rsp),%eax
je     15f8 <main+0x418>
test   %eax,%eax
je     15f8 <main+0x418>
mov    0x18(%rsp),%r13
mov    0x8(%r13),%rdi
mov    0x2ca4(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    135b <main+0x17b>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
je     137d <main+0x19d>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0xcc3(%rip),%rsi
lea    0x20(%rsp),%rdi
mov    $0x4,%edx
call   1080 <memcmp@plt>
test   %eax,%eax
je     13b2 <main+0x1d2>
cmpl   $0x1030107,0x20(%rsp)
01
jne    161c <main+0x43c>
mov    $0x20,%r12d
mov    $0x20,%eax
jmp    1407 <main+0x227>
mov    0x38(%rsp),%r12d
mov    0x3c(%rsp),%eax
add    0x24(%rsp,%rax,1),%r12d
sub    0x28(%rsp,%rax,1),%r12d
mov    %r15d,%edi
mov    %r12d,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    13e3 <main+0x203>
lea    0xc6e(%rip),%rdi
call   10e0 <die@plt>
lea    0x20(%rsp),%rsi
mov    %r15d,%edi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
je     1405 <main+0x225>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
xor    %eax,%eax
movzwl 0x22(%rsp,%rax,1),%eax
lea    (%r12,%rax,4),%r14d
add    $0xfffffe00,%r14d
mov    %r15d,%edi
mov    %r14d,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    1435 <main+0x255>
lea    0xc1c(%rip),%rdi
call   10e0 <die@plt>
lea    0x20(%rsp),%rbp
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0x400,%eax
je     145a <main+0x27a>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0x220(%rsp),%rax
jmp    1479 <main+0x299>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%rbp
cmp    %rax,%rbp
jae    1491 <main+0x2b1>
cmpb   $0x48,0x0(%rbp)
jne    1470 <main+0x290>
cmpb   $0x64,0x1(%rbp)
jne    1470 <main+0x290>
cmpb   $0x72,0x2(%rbp)
jne    1470 <main+0x290>
cmpb   $0x53,0x3(%rbp)
jne    1470 <main+0x290>
cmp    %rax,%rbp
je     160a <main+0x42a>
lea    0x20(%rsp),%rax
sub    %eax,%ebp
lea    (%r14,%rbp,1),%esi
add    $0xa,%esi
mov    %r15d,%edi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    14c3 <main+0x2e3>
lea    0xb8e(%rip),%rdi
call   10e0 <die@plt>
movabs $0x100000000000000,%rax
mov    %rax,0x20(%rsp)
mov    0xc(%rsp),%ebp
add    $0x101f,%ebp
and    $0xfffff000,%ebp
mov    %ebp,0x28(%rsp)
mov    0x10(%rsp),%eax
mov    %eax,0x2c(%rsp)
lea    0x22(%rsp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
cmp    $0xe,%eax
je     150e <main+0x32e>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
sub    %ebx,%ebp
add    %r12d,%ebp
mov    %r15d,%edi
mov    %ebp,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    1530 <main+0x350>
lea    0xb21(%rip),%rdi
call   10e0 <die@plt>
mov    0x18(%r13),%rdi
mov    0x2aa5(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    1552 <main+0x372>
mov    0x18(%r13),%rdi
call   10e0 <die@plt>
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
je     15b2 <main+0x3d2>
mov    %eax,%ebp
lea    0x20(%rsp),%rbx
jmp    1596 <main+0x3b6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
je     15b2 <main+0x3d2>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1580 <main+0x3a0>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
jmp    1580 <main+0x3a0>
mov    %r15d,%edi
call   1060 <close@plt>
test   %rax,%rax
jns    15cb <main+0x3eb>
lea    0xae0(%rip),%rdi
call   10e0 <die@plt>
mov    %r14d,%edi
call   1060 <close@plt>
test   %rax,%rax
jns    15e4 <main+0x404>
lea    0xac7(%rip),%rdi
call   10e0 <die@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x29d1(%rip),%rax
mov    (%rax),%edi
lea    0xa0c(%rip),%rsi
jmp    162c <main+0x44c>
mov    0x29bf(%rip),%rax
mov    (%rax),%edi
lea    0xa5c(%rip),%rsi
jmp    162c <main+0x44c>
mov    0x29ad(%rip),%rax
mov    (%rax),%edi
lea    0xa26(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c" T start\0A\00"
@.str.2 = [8 x i8] c" A end\0A\00"
@stderr = global i32 0
@.str.3 = [51 x i8] c"Could not determine start and end from System.map\0A\00"
@O_RDWR = global i32 0
@.str.4 = [5 x i8] c"\7FELF\00"
@.str.5 = [6 x i8] c"lseek\00"
@.str.6 = [36 x i8] c"Not ELF nor a.out. Don't blame me.\0A\00"
@.str.7 = [48 x i8] c"Couldn't find headers signature in the kernel.\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca %struct.stat
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
store i32 0, i32* %12
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i64 @stat(i8* %22, %struct.stat* %16)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = call i32 @die(i8* %28)
br label %30
30: ; preds = %25, %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %34, i32** %15
%35 = load i32*, i32** %15
%36 = icmp ne i32* %35, null
br i1 %36, label %42, label %37
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i32 @die(i8* %40)
br label %42
42: ; preds = %37, %30
br label %43
43: ; preds = %75, %42
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = load i32*, i32** %15
%46 = call i64 @fgets(i8* %44, i32 1024, i32* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %76
48: ; preds = %43
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = getelementptr inbounds i8, i8* %49, i64 8
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 16
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %53, %48
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%60 = call i32 @strtoul(i8* %59, i32* null, i32 16)
store i32 %60, i32* %12
br label %75
61: ; preds = %53
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = getelementptr inbounds i8, i8* %62, i64 8
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%68 = getelementptr inbounds i8, i8* %67, i64 16
%69 = call i32 @strcmp(i8* %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%70 = icmp ne i32 %69, 0
br i1 %70, label %74, label %71
71: ; preds = %66, %61
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%73 = call i32 @strtoul(i8* %72, i32* null, i32 16)
store i32 %73, i32* %13
br label %74
74: ; preds = %71, %66
br label %75
75: ; preds = %74, %58
br label %43
76: ; preds = %43
%77 = load i32*, i32** %15
%78 = call i32 @fclose(i32* %77)
%79 = load i32, i32* %12
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %76
%82 = load i32, i32* %13
%83 = icmp ne i32 %82, 0
br i1 %83, label %88, label %84
84: ; preds = %81, %76
%85 = load i32, i32* @stderr
%86 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %81
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = load i32, i32* @O_RDWR
%93 = call i32 @open(i8* %91, i32 %92)
store i32 %93, i32* %17
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %100
95: ; preds = %88
%96 = load i8**, i8*** %5
%97 = getelementptr inbounds i8*, i8** %96, i64 1
%98 = load i8*, i8** %97
%99 = call i32 @die(i8* %98)
br label %100
100: ; preds = %95, %88
%101 = load i32, i32* %17
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%103 = call i32 @read(i32 %101, i8* %102, i32 512)
%104 = icmp ne i32 %103, 512
br i1 %104, label %105, label %110
105: ; preds = %100
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 1
%108 = load i8*, i8** %107
%109 = call i32 @die(i8* %108)
br label %110
110: ; preds = %105, %100
%111 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%112 = call i32 @memcmp(i8* %111, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%113 = icmp ne i32 %112, 0
br i1 %113, label %152, label %114
114: ; preds = %110
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%117 = getelementptr inbounds i8, i8* %116, i64 28
%118 = bitcast i8* %117 to i32*
%119 = load i32, i32* %118
%120 = zext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %115, i64 %120
%122 = bitcast i8* %121 to i32*
store i32* %122, i32** %19
%123 = load i32*, i32** %19
%124 = getelementptr inbounds i32, i32* %123, i64 1
%125 = load i32, i32* %124
%126 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%127 = getelementptr inbounds i8, i8* %126, i64 24
%128 = bitcast i8* %127 to i32*
%129 = load i32, i32* %128
%130 = add i32 %125, %129
%131 = load i32*, i32** %19
%132 = getelementptr inbounds i32, i32* %131, i64 2
%133 = load i32, i32* %132
%134 = sub i32 %130, %133
store i32 %134, i32* %9
%135 = load i32, i32* %17
%136 = load i32, i32* %9
%137 = call i64 @lseek(i32 %135, i32 %136, i32 0)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %114
%140 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %141
141: ; preds = %139, %114
%142 = load i32, i32* %17
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%144 = call i32 @read(i32 %142, i8* %143, i32 512)
%145 = icmp ne i32 %144, 512
br i1 %145, label %146, label %151
146: ; preds = %141
%147 = load i8**, i8*** %5
%148 = getelementptr inbounds i8*, i8** %147, i64 1
%149 = load i8*, i8** %148
%150 = call i32 @die(i8* %149)
br label %151
151: ; preds = %146, %141
store i32 0, i32* %10
br label %163
152: ; preds = %110
%153 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%154 = bitcast i8* %153 to i32*
%155 = load i32, i32* %154
%156 = icmp eq i32 %155, 16974087
br i1 %156, label %157, label %158
157: ; preds = %152
store i32 32, i32* %10
store i32 32, i32* %9
br label %162
158: ; preds = %152
%159 = load i32, i32* @stderr
%160 = call i32 @fprintf(i32 %159, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%161 = call i32 @exit(i32 1)
unreachable
162: ; preds = %157
br label %163
163: ; preds = %162, %151
%164 = load i32, i32* %9
store i32 %164, i32* %11
%165 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%166 = load i32, i32* %10
%167 = zext i32 %166 to i64
%168 = getelementptr inbounds i8, i8* %165, i64 %167
%169 = getelementptr inbounds i8, i8* %168, i64 2
%170 = bitcast i8* %169 to i16*
%171 = load i16, i16* %170
%172 = zext i16 %171 to i32
%173 = shl i32 %172, 2
%174 = sub nsw i32 %173, 512
%175 = load i32, i32* %9
%176 = add i32 %175, %174
store i32 %176, i32* %9
%177 = load i32, i32* %17
%178 = load i32, i32* %9
%179 = call i64 @lseek(i32 %177, i32 %178, i32 0)
%180 = icmp slt i64 %179, 0
br i1 %180, label %181, label %183
181: ; preds = %163
%182 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %183
183: ; preds = %181, %163
%184 = load i32, i32* %17
%185 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%186 = call i32 @read(i32 %184, i8* %185, i32 1024)
%187 = icmp ne i32 %186, 1024
br i1 %187, label %188, label %193
188: ; preds = %183
%189 = load i8**, i8*** %5
%190 = getelementptr inbounds i8*, i8** %189, i64 1
%191 = load i8*, i8** %190
%192 = call i32 @die(i8* %191)
br label %193
193: ; preds = %188, %183
%194 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %194, i8** %7
%195 = load i8*, i8** %7
%196 = getelementptr inbounds i8, i8* %195, i64 512
store i8* %196, i8** %8
br label %197
197: ; preds = %226, %193
%198 = load i8*, i8** %7
%199 = load i8*, i8** %8
%200 = icmp ult i8* %198, %199
br i1 %200, label %201, label %229
201: ; preds = %197
%202 = load i8*, i8** %7
%203 = load i8, i8* %202
%204 = sext i8 %203 to i32
%205 = icmp eq i32 %204, 72
br i1 %205, label %206, label %225
206: ; preds = %201
%207 = load i8*, i8** %7
%208 = getelementptr inbounds i8, i8* %207, i64 1
%209 = load i8, i8* %208
%210 = sext i8 %209 to i32
%211 = icmp eq i32 %210, 100
br i1 %211, label %212, label %225
212: ; preds = %206
%213 = load i8*, i8** %7
%214 = getelementptr inbounds i8, i8* %213, i64 2
%215 = load i8, i8* %214
%216 = sext i8 %215 to i32
%217 = icmp eq i32 %216, 114
br i1 %217, label %218, label %225
218: ; preds = %212
%219 = load i8*, i8** %7
%220 = getelementptr inbounds i8, i8* %219, i64 3
%221 = load i8, i8* %220
%222 = sext i8 %221 to i32
%223 = icmp eq i32 %222, 83
br i1 %223, label %224, label %225
224: ; preds = %218
br label %229
225: ; preds = %218, %212, %206, %201
br label %226
226: ; preds = %225
%227 = load i8*, i8** %7
%228 = getelementptr inbounds i8, i8* %227, i64 4
store i8* %228, i8** %7
br label %197
229: ; preds = %224, %197
%230 = load i8*, i8** %7
%231 = load i8*, i8** %8
%232 = icmp eq i8* %230, %231
br i1 %232, label %233, label %237
233: ; preds = %229
%234 = load i32, i32* @stderr
%235 = call i32 @fprintf(i32 %234, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0))
%236 = call i32 @exit(i32 1)
unreachable
237: ; preds = %229
%238 = load i32, i32* %9
%239 = zext i32 %238 to i64
%240 = load i8*, i8** %7
%241 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%242 = ptrtoint i8* %240 to i64
%243 = ptrtoint i8* %241 to i64
%244 = sub i64 %242, %243
%245 = add nsw i64 %239, %244
%246 = add nsw i64 %245, 10
%247 = trunc i64 %246 to i32
store i32 %247, i32* %14
%248 = load i32, i32* %17
%249 = load i32, i32* %14
%250 = call i64 @lseek(i32 %248, i32 %249, i32 0)
%251 = icmp slt i64 %250, 0
br i1 %251, label %252, label %254
252: ; preds = %237
%253 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %254
254: ; preds = %252, %237
%255 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%256 = bitcast i8* %255 to i32*
store i32 0, i32* %256
%257 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%258 = getelementptr inbounds i8, i8* %257, i64 4
%259 = bitcast i8* %258 to i32*
store i32 16777216, i32* %259
%260 = load i32, i32* %13
%261 = add i32 %260, 32
%262 = add i32 %261, 4095
%263 = and i32 %262, -4096
%264 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%265 = getelementptr inbounds i8, i8* %264, i64 8
%266 = bitcast i8* %265 to i32*
store i32 %263, i32* %266
%267 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%268 = load i32, i32* %267
%269 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%270 = getelementptr inbounds i8, i8* %269, i64 12
%271 = bitcast i8* %270 to i32*
store i32 %268, i32* %271
%272 = load i32, i32* %17
%273 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%274 = getelementptr inbounds i8, i8* %273, i64 2
%275 = call i32 @write(i32 %272, i8* %274, i32 14)
%276 = icmp ne i32 %275, 14
br i1 %276, label %277, label %282
277: ; preds = %254
%278 = load i8**, i8*** %5
%279 = getelementptr inbounds i8*, i8** %278, i64 1
%280 = load i8*, i8** %279
%281 = call i32 @die(i8* %280)
br label %282
282: ; preds = %277, %254
%283 = load i32, i32* %17
%284 = load i32, i32* %11
%285 = load i32, i32* %12
%286 = sub i32 %284, %285
%287 = load i32, i32* %13
%288 = add i32 %287, 32
%289 = add i32 %288, 4095
%290 = and i32 %289, -4096
%291 = add i32 %286, %290
%292 = call i64 @lseek(i32 %283, i32 %291, i32 0)
%293 = icmp slt i64 %292, 0
br i1 %293, label %294, label %296
294: ; preds = %282
%295 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %296
296: ; preds = %294, %282
%297 = load i8**, i8*** %5
%298 = getelementptr inbounds i8*, i8** %297, i64 3
%299 = load i8*, i8** %298
%300 = load i32, i32* @O_RDONLY
%301 = call i32 @open(i8* %299, i32 %300)
store i32 %301, i32* %18
%302 = icmp slt i32 %301, 0
br i1 %302, label %303, label %308
303: ; preds = %296
%304 = load i8**, i8*** %5
%305 = getelementptr inbounds i8*, i8** %304, i64 3
%306 = load i8*, i8** %305
%307 = call i32 @die(i8* %306)
br label %308
308: ; preds = %303, %296
br label %309
309: ; preds = %326, %308
%310 = load i32, i32* %18
%311 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%312 = call i32 @read(i32 %310, i8* %311, i32 1024)
store i32 %312, i32* %9
%313 = icmp ugt i32 %312, 0
br i1 %313, label %314, label %327
314: ; preds = %309
%315 = load i32, i32* %17
%316 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%317 = load i32, i32* %9
%318 = call i32 @write(i32 %315, i8* %316, i32 %317)
%319 = load i32, i32* %9
%320 = icmp ne i32 %318, %319
br i1 %320, label %321, label %326
321: ; preds = %314
%322 = load i8**, i8*** %5
%323 = getelementptr inbounds i8*, i8** %322, i64 1
%324 = load i8*, i8** %323
%325 = call i32 @die(i8* %324)
br label %326
326: ; preds = %321, %314
br label %309
327: ; preds = %309
%328 = load i32, i32* %17
%329 = call i64 @close(i32 %328)
%330 = icmp slt i64 %329, 0
br i1 %330, label %331, label %333
331: ; preds = %327
%332 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %333
333: ; preds = %331, %327
%334 = load i32, i32* %18
%335 = call i64 @close(i32 %334)
%336 = icmp slt i64 %335, 0
br i1 %336, label %337, label %339
337: ; preds = %333
%338 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %339
339: ; preds = %337, %333
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c" T start\0A\00"
@.str.2 = [8 x i8] c" A end\0A\00"
@stderr = global i32 0
@.str.3 = [51 x i8] c"Could not determine start and end from System.map\0A\00"
@O_RDWR = global i32 0
@.str.4 = [5 x i8] c"\7FELF\00"
@.str.5 = [6 x i8] c"lseek\00"
@.str.6 = [36 x i8] c"Not ELF nor a.out. Don't blame me.\0A\00"
@.str.7 = [48 x i8] c"Couldn't find headers signature in the kernel.\0A\00"
@O_RDONLY = global i32 0
@.str.8 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 3
%8 = load i8*, i8** %7
%9 = call i64 @stat(i8* %8, %struct.stat* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %7
%13 = call i32 @die(i8* %12)
br label %14
14: ; preds = %11, %2
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = call i32 @die(i8* %20)
br label %22
22: ; preds = %19, %14
%23 = call i64 @fgets(i8* %5, i32 1024, i32* %17)
%24 = icmp eq i64 %23, 0
br i1 %24, label %51, label %25
25: ; preds = %22
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 16
br label %28
28: ; preds = %25, %46
%29 = phi i32 [ 0, %25 ], [ %48, %46 ]
%30 = phi i32 [ 0, %25 ], [ %47, %46 ]
%31 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 10)
%32 = icmp eq i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 10)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33, %28
%37 = call i32 @strtoul(i8* nocapture %5, i32* null, i32 16)
br label %46
38: ; preds = %33
%39 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 8)
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = call i32 bitcast (i32 (i8*, i8*, i32)* @memcmp to i32 (i8*, i8*, i64)*)(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 8)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41, %38
%45 = call i32 @strtoul(i8* nocapture %5, i32* null, i32 16)
br label %46
46: ; preds = %41, %44, %36
%47 = phi i32 [ %30, %41 ], [ %45, %44 ], [ %30, %36 ]
%48 = phi i32 [ %29, %41 ], [ %29, %44 ], [ %37, %36 ]
%49 = call i64 @fgets(i8* %5, i32 1024, i32* %17)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %28
51: ; preds = %46, %22
%52 = phi i32 [ 0, %22 ], [ %47, %46 ]
%53 = phi i32 [ 0, %22 ], [ %48, %46 ]
%54 = call i32 @fclose(i32* %17)
%55 = icmp ne i32 %53, 0
%56 = icmp ne i32 %52, 0
%57 = select i1 %55, i1 %56, i1 false
br i1 %57, label %62, label %58
58: ; preds = %51
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %51
%63 = getelementptr inbounds i8*, i8** %1, i64 1
%64 = load i8*, i8** %63
%65 = load i32, i32* @O_RDWR
%66 = call i32 @open(i8* %64, i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = load i8*, i8** %63
%70 = call i32 @die(i8* %69)
br label %71
71: ; preds = %68, %62
%72 = call i32 @read(i32 %66, i8* %5, i32 512)
%73 = icmp eq i32 %72, 512
br i1 %73, label %77, label %74
74: ; preds = %71
%75 = load i8*, i8** %63
%76 = call i32 @die(i8* %75)
br label %77
77: ; preds = %74, %71
%78 = call i32 @memcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %107
80: ; preds = %77
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 28
%82 = bitcast i8* %81 to i32*
%83 = load i32, i32* %82
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %84
%86 = getelementptr inbounds i8, i8* %85, i64 4
%87 = bitcast i8* %86 to i32*
%88 = load i32, i32* %87
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 24
%90 = bitcast i8* %89 to i32*
%91 = load i32, i32* %90
%92 = add i32 %91, %88
%93 = getelementptr inbounds i8, i8* %85, i64 8
%94 = bitcast i8* %93 to i32*
%95 = load i32, i32* %94
%96 = sub i32 %92, %95
%97 = call i64 @lseek(i32 %66, i32 %96, i32 0)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %101
99: ; preds = %80
%100 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %101
101: ; preds = %99, %80
%102 = call i32 @read(i32 %66, i8* %5, i32 512)
%103 = icmp eq i32 %102, 512
br i1 %103, label %115, label %104
104: ; preds = %101
%105 = load i8*, i8** %63
%106 = call i32 @die(i8* %105)
br label %115
107: ; preds = %77
%108 = bitcast [1024 x i8]* %3 to i32*
%109 = load i32, i32* %108
%110 = icmp eq i32 %109, 16974087
br i1 %110, label %115, label %111
111: ; preds = %107
%112 = load i32, i32* @stderr
%113 = call i32 @fprintf(i32 %112, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%114 = call i32 @exit(i32 1)
unreachable
115: ; preds = %107, %101, %104
%116 = phi i64 [ 0, %104 ], [ 0, %101 ], [ 32, %107 ]
%117 = phi i32 [ %96, %104 ], [ %96, %101 ], [ 32, %107 ]
%118 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %116
%119 = getelementptr inbounds i8, i8* %118, i64 2
%120 = bitcast i8* %119 to i16*
%121 = load i16, i16* %120
%122 = zext i16 %121 to i32
%123 = shl nuw nsw i32 %122, 2
%124 = add i32 %117, -512
%125 = add i32 %124, %123
%126 = call i64 @lseek(i32 %66, i32 %125, i32 0)
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %130
128: ; preds = %115
%129 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %130
130: ; preds = %128, %115
%131 = call i32 @read(i32 %66, i8* %5, i32 1024)
%132 = icmp eq i32 %131, 1024
br i1 %132, label %136, label %133
133: ; preds = %130
%134 = load i8*, i8** %63
%135 = call i32 @die(i8* %134)
br label %136
136: ; preds = %133, %130
%137 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 512
br label %138
138: ; preds = %136, %154
%139 = phi i8* [ %5, %136 ], [ %155, %154 ]
%140 = load i8, i8* %139
%141 = icmp eq i8 %140, 72
br i1 %141, label %142, label %154
142: ; preds = %138
%143 = getelementptr inbounds i8, i8* %139, i64 1
%144 = load i8, i8* %143
%145 = icmp eq i8 %144, 100
br i1 %145, label %146, label %154
146: ; preds = %142
%147 = getelementptr inbounds i8, i8* %139, i64 2
%148 = load i8, i8* %147
%149 = icmp eq i8 %148, 114
br i1 %149, label %150, label %154
150: ; preds = %146
%151 = getelementptr inbounds i8, i8* %139, i64 3
%152 = load i8, i8* %151
%153 = icmp eq i8 %152, 83
br i1 %153, label %157, label %154
154: ; preds = %138, %142, %146, %150
%155 = getelementptr inbounds i8, i8* %139, i64 4
%156 = icmp ult i8* %155, %137
br i1 %156, label %138, label %157
157: ; preds = %150, %154
%158 = phi i8* [ %139, %150 ], [ %155, %154 ]
%159 = icmp eq i8* %158, %137
br i1 %159, label %160, label %164
160: ; preds = %157
%161 = load i32, i32* @stderr
%162 = call i32 @fprintf(i32 %161, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.7, i64 0, i64 0))
%163 = call i32 @exit(i32 1)
unreachable
164: ; preds = %157
%165 = ptrtoint i8* %158 to i64
%166 = ptrtoint [1024 x i8]* %3 to i64
%167 = sub i64 %165, %166
%168 = trunc i64 %167 to i32
%169 = add i32 %125, 10
%170 = add i32 %169, %168
%171 = call i64 @lseek(i32 %66, i32 %170, i32 0)
%172 = icmp slt i64 %171, 0
br i1 %172, label %173, label %175
173: ; preds = %164
%174 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %175
175: ; preds = %173, %164
%176 = bitcast [1024 x i8]* %3 to i32*
store i32 0, i32* %176
%177 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 4
%178 = bitcast i8* %177 to i32*
store i32 16777216, i32* %178
%179 = add i32 %52, 4127
%180 = and i32 %179, -4096
%181 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 8
%182 = bitcast i8* %181 to i32*
store i32 %180, i32* %182
%183 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%184 = load i32, i32* %183
%185 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 12
%186 = bitcast i8* %185 to i32*
store i32 %184, i32* %186
%187 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
%188 = call i32 @write(i32 %66, i8* %187, i32 14)
%189 = icmp eq i32 %188, 14
br i1 %189, label %193, label %190
190: ; preds = %175
%191 = load i8*, i8** %63
%192 = call i32 @die(i8* %191)
br label %193
193: ; preds = %190, %175
%194 = sub i32 %180, %53
%195 = add i32 %194, %117
%196 = call i64 @lseek(i32 %66, i32 %195, i32 0)
%197 = icmp slt i64 %196, 0
br i1 %197, label %198, label %200
198: ; preds = %193
%199 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %200
200: ; preds = %198, %193
%201 = load i8*, i8** %7
%202 = load i32, i32* @O_RDONLY
%203 = call i32 @open(i8* %201, i32 %202)
%204 = icmp slt i32 %203, 0
br i1 %204, label %205, label %208
205: ; preds = %200
%206 = load i8*, i8** %7
%207 = call i32 @die(i8* %206)
br label %208
208: ; preds = %205, %200
%209 = call i32 @read(i32 %203, i8* %5, i32 1024)
%210 = icmp eq i32 %209, 0
br i1 %210, label %221, label %211
211: ; preds = %208, %218
%212 = phi i32 [ %219, %218 ], [ %209, %208 ]
%213 = call i32 @write(i32 %66, i8* %5, i32 %212)
%214 = icmp eq i32 %213, %212
br i1 %214, label %218, label %215
215: ; preds = %211
%216 = load i8*, i8** %63
%217 = call i32 @die(i8* %216)
br label %218
218: ; preds = %215, %211
%219 = call i32 @read(i32 %203, i8* %5, i32 1024)
%220 = icmp eq i32 %219, 0
br i1 %220, label %221, label %211
221: ; preds = %218, %208
%222 = call i64 @close(i32 %66)
%223 = icmp slt i64 %222, 0
br i1 %223, label %224, label %226
224: ; preds = %221
%225 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %226
226: ; preds = %224, %221
%227 = call i64 @close(i32 %203)
%228 = icmp slt i64 %227, 0
br i1 %228, label %229, label %231
229: ; preds = %226
%230 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
br label %231
231: ; preds = %229, %226
ret i32 0
}