#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;
  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 + 19, "_start\n"))
      start = strtoul(buffer + 8, NULL, 16);
    else if (!strcmp(buffer + 19, "_end\n"))
      end = strtoul(buffer + 8, NULL, 16);
  }
  fclose(map);
  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;
  if (j == 32 && buffer[40] == 'H' && buffer[41] == 'd' && buffer[42] == 'r' &&
      buffer[43] == 'S') {
    offset = 40 + 10;
  } else {
    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 + 8191) & ~8191);
  *(unsigned *)(buffer + 12) = s.st_size;
  if (write(image, buffer + 2, 14) != 14)
    die(argv[1]);
  if (lseek(image, 4, 0) < 0)
    die("lseek");
  *(unsigned *)buffer =
      ((end + 32 + 8191) & ~8191) - (start & ~0x3fffffUL) + s.st_size;
  *(unsigned *)(buffer + 4) = 0;
  *(unsigned *)(buffer + 8) = 0;
  if (write(image, buffer, 12) != 12)
    die(argv[1]);
  if (lseek(image, k - start + ((end + 32 + 8191) & ~8191), 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)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x448(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jge    1234 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdbd(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    126a <main+0x7a>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <die@plt>
jmp    126f <main+0x7f>
lea    -0x410(%rbp),%rdi
mov    -0x440(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     131e <main+0x12e>
lea    -0x410(%rbp),%rdi
add    $0x13,%rdi
lea    0xd5f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12d5 <main+0xe5>
lea    -0x410(%rbp),%rdi
add    $0x8,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x430(%rbp)
jmp    1319 <main+0x129>
lea    -0x410(%rbp),%rdi
add    $0x13,%rdi
lea    0xd23(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1314 <main+0x124>
lea    -0x410(%rbp),%rdi
add    $0x8,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %eax,-0x434(%rbp)
jmp    1319 <main+0x129>
jmp    126f <main+0x7f>
mov    -0x440(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x44c(%rbp)
cmp    $0x0,%eax
jge    135c <main+0x16c>
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     138b <main+0x19b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
lea    -0x410(%rbp),%rdi
lea    0xc77(%rip),%rsi
mov    $0x4,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%eax
jne    144a <main+0x25a>
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    140c <main+0x21c>
lea    0xc0e(%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     143b <main+0x24b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
movl   $0x0,-0x428(%rbp)
jmp    1497 <main+0x2a7>
cmpl   $0x1030107,-0x410(%rbp)
01 03 01
jne    1473 <main+0x283>
movl   $0x20,-0x428(%rbp)
movl   $0x20,-0x424(%rbp)
jmp    1492 <main+0x2a2>
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
lea    0xb98(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    1497 <main+0x2a7>
mov    -0x424(%rbp),%eax
mov    %eax,-0x42c(%rbp)
cmpl   $0x20,-0x428(%rbp)
jne    14ff <main+0x30f>
movsbl -0x3e8(%rbp),%eax
cmp    $0x48,%eax
jne    14ff <main+0x30f>
movsbl -0x3e7(%rbp),%eax
cmp    $0x64,%eax
jne    14ff <main+0x30f>
movsbl -0x3e6(%rbp),%eax
cmp    $0x72,%eax
jne    14ff <main+0x30f>
movsbl -0x3e5(%rbp),%eax
cmp    $0x53,%eax
jne    14ff <main+0x30f>
movl   $0x32,-0x438(%rbp)
jmp    1676 <main+0x486>
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    154a <main+0x35a>
lea    0xad0(%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     1579 <main+0x389>
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    161f <main+0x42f>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
jne    1603 <main+0x413>
mov    -0x418(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x64,%eax
jne    1603 <main+0x413>
mov    -0x418(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x72,%eax
jne    1603 <main+0x413>
mov    -0x418(%rbp),%rax
movsbl 0x3(%rax),%eax
cmp    $0x53,%eax
jne    1603 <main+0x413>
jmp    161f <main+0x42f>
jmp    1608 <main+0x418>
mov    -0x418(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x418(%rbp)
jmp    159b <main+0x3ab>
mov    -0x418(%rbp),%rax
cmp    -0x420(%rbp),%rax
jne    1652 <main+0x462>
mov    0x2996(%rip),%rax
mov    (%rax),%edi
lea    0x9fc(%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    169f <main+0x4af>
lea    0x97b(%rip),%rdi
call   10f0 <die@plt>
movl   $0x0,-0x410(%rbp)
movl   $0x1000000,-0x40c(%rbp)
mov    -0x434(%rbp),%eax
add    $0x20,%eax
add    $0x1fff,%eax
and    $0xffffe000,%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     1709 <main+0x519>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
mov    -0x44c(%rbp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1731 <main+0x541>
lea    0x8e9(%rip),%rdi
call   10f0 <die@plt>
mov    -0x434(%rbp),%eax
add    $0x20,%eax
add    $0x1fff,%eax
and    $0xffffe000,%eax
mov    %eax,%eax
mov    -0x430(%rbp),%ecx
and    $0xffffffffffc00000,%rcx
sub    %rcx,%rax
mov    -0x448(%rbp),%ecx
add    %rcx,%rax
mov    %eax,-0x410(%rbp)
movl   $0x0,-0x40c(%rbp)
movl   $0x0,-0x408(%rbp)
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0xc,%eax
je     17a6 <main+0x5b6>
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    $0x1fff,%eax
and    $0xffffe000,%eax
add    %eax,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    17ea <main+0x5fa>
lea    0x830(%rip),%rdi
call   10f0 <die@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x27e7(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x450(%rbp)
cmp    $0x0,%eax
jge    181c <main+0x62c>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <die@plt>
jmp    1821 <main+0x631>
mov    -0x450(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jbe    187d <main+0x68d>
mov    -0x44c(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x424(%rbp),%edx
call   1030 <write@plt>
cmp    -0x424(%rbp),%eax
je     1878 <main+0x688>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10f0 <die@plt>
jmp    1821 <main+0x631>
mov    -0x44c(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    189e <main+0x6ae>
lea    0x7d6(%rip),%rdi
call   10f0 <die@plt>
mov    -0x450(%rbp),%edi
call   1060 <close@plt>
cmp    $0x0,%rax
jge    18bf <main+0x6cf>
lea    0x7b5(%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    $0x418,%rsp
mov    %rsi,%rbx
mov    0x18(%rsi),%rdi
mov    %rsp,%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jns    120e <main+0x2e>
mov    0x18(%rbx),%rdi
call   10e0 <die@plt>
mov    0x10(%rbx),%rdi
lea    0xde7(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    122f <main+0x4f>
mov    0x10(%rbx),%rdi
call   10e0 <die@plt>
mov    %rbx,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12d8 <main+0xf8>
lea    0x23(%rsp),%rbx
lea    0xda7(%rip),%r15
lea    0x10(%rsp),%r14
lea    0xda3(%rip),%r13
jmp    1299 <main+0xb9>
nopl   0x0(%rax)
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %eax,%r12d
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12d8 <main+0xf8>
mov    $0x8,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
je     1270 <main+0x90>
mov    $0x6,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <memcmp@plt>
test   %eax,%eax
jne    1284 <main+0xa4>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %eax,0x4(%rsp)
jmp    1284 <main+0xa4>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%r13
mov    0x8(%r13),%rdi
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1307 <main+0x127>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
mov    %r12d,%ebp
je     132c <main+0x14c>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0xcdd(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   1080 <memcmp@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1367 <main+0x187>
cmpl   $0x1030107,0x10(%rsp)
01
jne    1628 <main+0x448>
mov    $0x20,%r12d
mov    $0x20,%eax
test   %ebx,%ebx
jne    13c0 <main+0x1e0>
jmp    13e5 <main+0x205>
mov    0x28(%rsp),%r12d
mov    0x2c(%rsp),%eax
add    0x14(%rsp,%rax,1),%r12d
sub    0x18(%rsp,%rax,1),%r12d
mov    %r15d,%edi
mov    %r12d,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    1398 <main+0x1b8>
lea    0xc82(%rip),%rdi
call   10e0 <die@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x200,%edx
call   1070 <read@plt>
cmp    $0x200,%eax
je     13ba <main+0x1da>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
xor    %eax,%eax
test   %ebx,%ebx
je     13e5 <main+0x205>
cmpb   $0x48,0x38(%rsp)
jne    13e5 <main+0x205>
cmpb   $0x64,0x39(%rsp)
jne    13e5 <main+0x205>
cmpb   $0x72,0x3a(%rsp)
jne    13e5 <main+0x205>
mov    $0x32,%esi
cmpb   $0x53,0x3b(%rsp)
je     1487 <main+0x2a7>
movzwl 0x12(%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    1413 <main+0x233>
lea    0xc07(%rip),%rdi
call   10e0 <die@plt>
lea    0x10(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
cmp    $0x400,%eax
je     1438 <main+0x258>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
lea    0x210(%rsp),%rax
jmp    1459 <main+0x279>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%rbx
cmp    %rax,%rbx
jae    1470 <main+0x290>
cmpb   $0x48,(%rbx)
jne    1450 <main+0x270>
cmpb   $0x64,0x1(%rbx)
jne    1450 <main+0x270>
cmpb   $0x72,0x2(%rbx)
jne    1450 <main+0x270>
cmpb   $0x53,0x3(%rbx)
jne    1450 <main+0x270>
cmp    %rax,%rbx
je     163a <main+0x45a>
lea    0x10(%rsp),%rax
sub    %eax,%ebx
lea    (%r14,%rbx,1),%esi
add    $0xa,%esi
mov    %r15d,%edi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
mov    0x4(%rsp),%ebx
jns    14a6 <main+0x2c6>
lea    0xb74(%rip),%rdi
call   10e0 <die@plt>
movabs $0x100000000000000,%rax
mov    %rax,0x10(%rsp)
add    $0x201f,%ebx
and    $0xffffe000,%ebx
mov    %ebx,0x18(%rsp)
mov    (%rsp),%eax
mov    %eax,0x1c(%rsp)
lea    0x12(%rsp),%rsi
mov    %r15d,%edi
mov    $0xe,%edx
call   1030 <write@plt>
cmp    $0xe,%eax
je     14ec <main+0x30c>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
mov    %r15d,%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    150c <main+0x32c>
lea    0xb0e(%rip),%rdi
call   10e0 <die@plt>
mov    %ebp,%eax
and    $0xffc00000,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
add    (%rsp),%ecx
mov    %ecx,0x10(%rsp)
movq   $0x0,0x14(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0xc,%eax
je     1547 <main+0x367>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
sub    %ebp,%ebx
add    %r12d,%ebx
mov    %r15d,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
test   %rax,%rax
jns    1569 <main+0x389>
lea    0xab1(%rip),%rdi
call   10e0 <die@plt>
mov    0x18(%r13),%rdi
mov    0x2a6c(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    158b <main+0x3ab>
mov    0x18(%r13),%rdi
call   10e0 <die@plt>
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
je     15e2 <main+0x402>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
jmp    15c6 <main+0x3e6>
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
je     15e2 <main+0x402>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
je     15b0 <main+0x3d0>
mov    0x8(%r13),%rdi
call   10e0 <die@plt>
jmp    15b0 <main+0x3d0>
mov    %r15d,%edi
call   1060 <close@plt>
test   %rax,%rax
jns    15fb <main+0x41b>
lea    0xa79(%rip),%rdi
call   10e0 <die@plt>
mov    %r14d,%edi
call   1060 <close@plt>
test   %rax,%rax
jns    1614 <main+0x434>
lea    0xa60(%rip),%rdi
call   10e0 <die@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x29a1(%rip),%rax
mov    (%rax),%edi
lea    0x9e3(%rip),%rsi
jmp    164a <main+0x46a>
mov    0x298f(%rip),%rax
mov    (%rax),%edi
lea    0x9f5(%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 = [8 x i8] c"_start\0A\00"
@.str.2 = [6 x i8] c"_end\0A\00"
@O_RDWR = global i32 0
@.str.3 = [5 x i8] c"\7FELF\00"
@.str.4 = [6 x i8] c"lseek\00"
@stderr = global i32 0
@.str.5 = [36 x i8] c"Not ELF nor a.out. Don't blame me.\0A\00"
@.str.6 = [48 x i8] c"Couldn't find headers signature in the kernel.\0A\00"
@O_RDONLY = global i32 0
@.str.7 = [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
%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 = %67, %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 %68
48: ; preds = %43
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = getelementptr inbounds i8, i8* %49, i64 19
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %48
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%55 = getelementptr inbounds i8, i8* %54, i64 8
%56 = call i32 @strtoul(i8* %55, i32* null, i32 16)
store i32 %56, i32* %12
br label %67
57: ; preds = %48
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%59 = getelementptr inbounds i8, i8* %58, i64 19
%60 = call i32 @strcmp(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%61 = icmp ne i32 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %57
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%64 = getelementptr inbounds i8, i8* %63, i64 8
%65 = call i32 @strtoul(i8* %64, i32* null, i32 16)
store i32 %65, i32* %13
br label %66
66: ; preds = %62, %57
br label %67
67: ; preds = %66, %53
br label %43
68: ; preds = %43
%69 = load i32*, i32** %15
%70 = call i32 @fclose(i32* %69)
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = load i32, i32* @O_RDWR
%75 = call i32 @open(i8* %73, i32 %74)
store i32 %75, i32* %17
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %68
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 1
%80 = load i8*, i8** %79
%81 = call i32 @die(i8* %80)
br label %82
82: ; preds = %77, %68
%83 = load i32, i32* %17
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%85 = call i32 @read(i32 %83, i8* %84, i32 512)
%86 = icmp ne i32 %85, 512
br i1 %86, label %87, label %92
87: ; preds = %82
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = load i8*, i8** %89
%91 = call i32 @die(i8* %90)
br label %92
92: ; preds = %87, %82
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%94 = call i32 @memcmp(i8* %93, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%95 = icmp ne i32 %94, 0
br i1 %95, label %134, label %96
96: ; preds = %92
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%99 = getelementptr inbounds i8, i8* %98, i64 28
%100 = bitcast i8* %99 to i32*
%101 = load i32, i32* %100
%102 = zext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %97, i64 %102
%104 = bitcast i8* %103 to i32*
store i32* %104, i32** %19
%105 = load i32*, i32** %19
%106 = getelementptr inbounds i32, i32* %105, i64 1
%107 = load i32, i32* %106
%108 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%109 = getelementptr inbounds i8, i8* %108, i64 24
%110 = bitcast i8* %109 to i32*
%111 = load i32, i32* %110
%112 = add i32 %107, %111
%113 = load i32*, i32** %19
%114 = getelementptr inbounds i32, i32* %113, i64 2
%115 = load i32, i32* %114
%116 = sub i32 %112, %115
store i32 %116, i32* %9
%117 = load i32, i32* %17
%118 = load i32, i32* %9
%119 = call i64 @lseek(i32 %117, i32 %118, i32 0)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %96
%122 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %123
123: ; preds = %121, %96
%124 = load i32, i32* %17
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%126 = call i32 @read(i32 %124, i8* %125, i32 512)
%127 = icmp ne i32 %126, 512
br i1 %127, label %128, label %133
128: ; preds = %123
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8*, i8** %130
%132 = call i32 @die(i8* %131)
br label %133
133: ; preds = %128, %123
store i32 0, i32* %10
br label %145
134: ; preds = %92
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%136 = bitcast i8* %135 to i32*
%137 = load i32, i32* %136
%138 = icmp eq i32 %137, 16974087
br i1 %138, label %139, label %140
139: ; preds = %134
store i32 32, i32* %10
store i32 32, i32* %9
br label %144
140: ; preds = %134
%141 = load i32, i32* @stderr
%142 = call i32 @fprintf(i32 %141, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%143 = call i32 @exit(i32 1)
unreachable
144: ; preds = %139
br label %145
145: ; preds = %144, %133
%146 = load i32, i32* %9
store i32 %146, i32* %11
%147 = load i32, i32* %10
%148 = icmp eq i32 %147, 32
br i1 %148, label %149, label %170
149: ; preds = %145
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 40
%151 = load i8, i8* %150
%152 = sext i8 %151 to i32
%153 = icmp eq i32 %152, 72
br i1 %153, label %154, label %170
154: ; preds = %149
%155 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 41
%156 = load i8, i8* %155
%157 = sext i8 %156 to i32
%158 = icmp eq i32 %157, 100
br i1 %158, label %159, label %170
159: ; preds = %154
%160 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 42
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = icmp eq i32 %162, 114
br i1 %163, label %164, label %170
164: ; preds = %159
%165 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 43
%166 = load i8, i8* %165
%167 = sext i8 %166 to i32
%168 = icmp eq i32 %167, 83
br i1 %168, label %169, label %170
169: ; preds = %164
store i32 50, i32* %14
br label %254
170: ; preds = %164, %159, %154, %149, %145
%171 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%172 = load i32, i32* %10
%173 = zext i32 %172 to i64
%174 = getelementptr inbounds i8, i8* %171, i64 %173
%175 = getelementptr inbounds i8, i8* %174, i64 2
%176 = bitcast i8* %175 to i16*
%177 = load i16, i16* %176
%178 = zext i16 %177 to i32
%179 = shl i32 %178, 2
%180 = sub nsw i32 %179, 512
%181 = load i32, i32* %9
%182 = add i32 %181, %180
store i32 %182, i32* %9
%183 = load i32, i32* %17
%184 = load i32, i32* %9
%185 = call i64 @lseek(i32 %183, i32 %184, i32 0)
%186 = icmp slt i64 %185, 0
br i1 %186, label %187, label %189
187: ; preds = %170
%188 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %189
189: ; preds = %187, %170
%190 = load i32, i32* %17
%191 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%192 = call i32 @read(i32 %190, i8* %191, i32 1024)
%193 = icmp ne i32 %192, 1024
br i1 %193, label %194, label %199
194: ; preds = %189
%195 = load i8**, i8*** %5
%196 = getelementptr inbounds i8*, i8** %195, i64 1
%197 = load i8*, i8** %196
%198 = call i32 @die(i8* %197)
br label %199
199: ; preds = %194, %189
%200 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8* %200, i8** %7
%201 = load i8*, i8** %7
%202 = getelementptr inbounds i8, i8* %201, i64 512
store i8* %202, i8** %8
br label %203
203: ; preds = %232, %199
%204 = load i8*, i8** %7
%205 = load i8*, i8** %8
%206 = icmp ult i8* %204, %205
br i1 %206, label %207, label %235
207: ; preds = %203
%208 = load i8*, i8** %7
%209 = load i8, i8* %208
%210 = sext i8 %209 to i32
%211 = icmp eq i32 %210, 72
br i1 %211, label %212, label %231
212: ; preds = %207
%213 = load i8*, i8** %7
%214 = getelementptr inbounds i8, i8* %213, i64 1
%215 = load i8, i8* %214
%216 = sext i8 %215 to i32
%217 = icmp eq i32 %216, 100
br i1 %217, label %218, label %231
218: ; preds = %212
%219 = load i8*, i8** %7
%220 = getelementptr inbounds i8, i8* %219, i64 2
%221 = load i8, i8* %220
%222 = sext i8 %221 to i32
%223 = icmp eq i32 %222, 114
br i1 %223, label %224, label %231
224: ; preds = %218
%225 = load i8*, i8** %7
%226 = getelementptr inbounds i8, i8* %225, i64 3
%227 = load i8, i8* %226
%228 = sext i8 %227 to i32
%229 = icmp eq i32 %228, 83
br i1 %229, label %230, label %231
230: ; preds = %224
br label %235
231: ; preds = %224, %218, %212, %207
br label %232
232: ; preds = %231
%233 = load i8*, i8** %7
%234 = getelementptr inbounds i8, i8* %233, i64 4
store i8* %234, i8** %7
br label %203
235: ; preds = %230, %203
%236 = load i8*, i8** %7
%237 = load i8*, i8** %8
%238 = icmp eq i8* %236, %237
br i1 %238, label %239, label %243
239: ; preds = %235
%240 = load i32, i32* @stderr
%241 = call i32 @fprintf(i32 %240, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.6, i64 0, i64 0))
%242 = call i32 @exit(i32 1)
unreachable
243: ; preds = %235
%244 = load i32, i32* %9
%245 = zext i32 %244 to i64
%246 = load i8*, i8** %7
%247 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%248 = ptrtoint i8* %246 to i64
%249 = ptrtoint i8* %247 to i64
%250 = sub i64 %248, %249
%251 = add nsw i64 %245, %250
%252 = add nsw i64 %251, 10
%253 = trunc i64 %252 to i32
store i32 %253, i32* %14
br label %254
254: ; preds = %243, %169
%255 = load i32, i32* %17
%256 = load i32, i32* %14
%257 = call i64 @lseek(i32 %255, i32 %256, i32 0)
%258 = icmp slt i64 %257, 0
br i1 %258, label %259, label %261
259: ; preds = %254
%260 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %261
261: ; preds = %259, %254
%262 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%263 = bitcast i8* %262 to i32*
store i32 0, i32* %263
%264 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%265 = getelementptr inbounds i8, i8* %264, i64 4
%266 = bitcast i8* %265 to i32*
store i32 16777216, i32* %266
%267 = load i32, i32* %13
%268 = add i32 %267, 32
%269 = add i32 %268, 8191
%270 = and i32 %269, -8192
%271 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%272 = getelementptr inbounds i8, i8* %271, i64 8
%273 = bitcast i8* %272 to i32*
store i32 %270, i32* %273
%274 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%275 = load i32, i32* %274
%276 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%277 = getelementptr inbounds i8, i8* %276, i64 12
%278 = bitcast i8* %277 to i32*
store i32 %275, i32* %278
%279 = load i32, i32* %17
%280 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%281 = getelementptr inbounds i8, i8* %280, i64 2
%282 = call i32 @write(i32 %279, i8* %281, i32 14)
%283 = icmp ne i32 %282, 14
br i1 %283, label %284, label %289
284: ; preds = %261
%285 = load i8**, i8*** %5
%286 = getelementptr inbounds i8*, i8** %285, i64 1
%287 = load i8*, i8** %286
%288 = call i32 @die(i8* %287)
br label %289
289: ; preds = %284, %261
%290 = load i32, i32* %17
%291 = call i64 @lseek(i32 %290, i32 4, i32 0)
%292 = icmp slt i64 %291, 0
br i1 %292, label %293, label %295
293: ; preds = %289
%294 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %295
295: ; preds = %293, %289
%296 = load i32, i32* %13
%297 = add i32 %296, 32
%298 = add i32 %297, 8191
%299 = and i32 %298, -8192
%300 = zext i32 %299 to i64
%301 = load i32, i32* %12
%302 = zext i32 %301 to i64
%303 = and i64 %302, -4194304
%304 = sub i64 %300, %303
%305 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%306 = load i32, i32* %305
%307 = zext i32 %306 to i64
%308 = add i64 %304, %307
%309 = trunc i64 %308 to i32
%310 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%311 = bitcast i8* %310 to i32*
store i32 %309, i32* %311
%312 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%313 = getelementptr inbounds i8, i8* %312, i64 4
%314 = bitcast i8* %313 to i32*
store i32 0, i32* %314
%315 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%316 = getelementptr inbounds i8, i8* %315, i64 8
%317 = bitcast i8* %316 to i32*
store i32 0, i32* %317
%318 = load i32, i32* %17
%319 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%320 = call i32 @write(i32 %318, i8* %319, i32 12)
%321 = icmp ne i32 %320, 12
br i1 %321, label %322, label %327
322: ; preds = %295
%323 = load i8**, i8*** %5
%324 = getelementptr inbounds i8*, i8** %323, i64 1
%325 = load i8*, i8** %324
%326 = call i32 @die(i8* %325)
br label %327
327: ; preds = %322, %295
%328 = load i32, i32* %17
%329 = load i32, i32* %11
%330 = load i32, i32* %12
%331 = sub i32 %329, %330
%332 = load i32, i32* %13
%333 = add i32 %332, 32
%334 = add i32 %333, 8191
%335 = and i32 %334, -8192
%336 = add i32 %331, %335
%337 = call i64 @lseek(i32 %328, i32 %336, i32 0)
%338 = icmp slt i64 %337, 0
br i1 %338, label %339, label %341
339: ; preds = %327
%340 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %341
341: ; preds = %339, %327
%342 = load i8**, i8*** %5
%343 = getelementptr inbounds i8*, i8** %342, i64 3
%344 = load i8*, i8** %343
%345 = load i32, i32* @O_RDONLY
%346 = call i32 @open(i8* %344, i32 %345)
store i32 %346, i32* %18
%347 = icmp slt i32 %346, 0
br i1 %347, label %348, label %353
348: ; preds = %341
%349 = load i8**, i8*** %5
%350 = getelementptr inbounds i8*, i8** %349, i64 3
%351 = load i8*, i8** %350
%352 = call i32 @die(i8* %351)
br label %353
353: ; preds = %348, %341
br label %354
354: ; preds = %371, %353
%355 = load i32, i32* %18
%356 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%357 = call i32 @read(i32 %355, i8* %356, i32 1024)
store i32 %357, i32* %9
%358 = icmp ugt i32 %357, 0
br i1 %358, label %359, label %372
359: ; preds = %354
%360 = load i32, i32* %17
%361 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%362 = load i32, i32* %9
%363 = call i32 @write(i32 %360, i8* %361, i32 %362)
%364 = load i32, i32* %9
%365 = icmp ne i32 %363, %364
br i1 %365, label %366, label %371
366: ; preds = %359
%367 = load i8**, i8*** %5
%368 = getelementptr inbounds i8*, i8** %367, i64 1
%369 = load i8*, i8** %368
%370 = call i32 @die(i8* %369)
br label %371
371: ; preds = %366, %359
br label %354
372: ; preds = %354
%373 = load i32, i32* %17
%374 = call i64 @close(i32 %373)
%375 = icmp slt i64 %374, 0
br i1 %375, label %376, label %378
376: ; preds = %372
%377 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %378
378: ; preds = %376, %372
%379 = load i32, i32* %18
%380 = call i64 @close(i32 %379)
%381 = icmp slt i64 %380, 0
br i1 %381, label %382, label %384
382: ; preds = %378
%383 = call i32 @die(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %384
384: ; preds = %382, %378
ret i32 0
}

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