#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ get4k(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ put4k(int /*<<< orphan*/ *, char *);
char *strstr(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  char inbuf[4096];
  FILE *sysmap = NULL;
  char *ptr_end = NULL;
  FILE *inputVmlinux = NULL;
  FILE *outputVmlinux = NULL;
  long i = 0;
  unsigned long sysmapFileLen = 0;
  unsigned long sysmapLen = 0;
  unsigned long roundR = 0;
  unsigned long kernelLen = 0;
  unsigned long actualKernelLen = 0;
  unsigned long round = 0;
  unsigned long roundedKernelLen = 0;
  unsigned long sysmapStartOffs = 0;
  unsigned long sysmapPages = 0;
  unsigned long roundedKernelPages = 0;
  long padPages = 0;
  if (argc < 2) {
    printf("Name of System Map file missing.\n");
    exit(1);
  }
  if (argc < 3) {
    printf("Name of vmlinux file missing.\n");
    exit(1);
  }
  if (argc < 4) {
    printf("Name of vmlinux output file missing.\n");
    exit(1);
  }
  sysmap = fopen(argv[1], "r");
  if (!sysmap) {
    printf("System Map file \"%s\" failed to open.\n", argv[1]);
    exit(1);
  }
  inputVmlinux = fopen(argv[2], "r");
  if (!inputVmlinux) {
    printf("vmlinux file \"%s\" failed to open.\n", argv[2]);
    exit(1);
  }
  outputVmlinux = fopen(argv[3], "w");
  if (!outputVmlinux) {
    printf("output vmlinux file \"%s\" failed to open.\n", argv[3]);
    exit(1);
  }
  fseek(inputVmlinux, 0, SEEK_END);
  kernelLen = ftell(inputVmlinux);
  fseek(inputVmlinux, 0, SEEK_SET);
  printf("kernel file size = %ld\n", kernelLen);
  if (kernelLen == 0) {
    printf("You must have a linux kernel specified as argv[2]\n");
    exit(1);
  }
  actualKernelLen = kernelLen - (64 * 1024);
  printf("actual kernel length (minus ELF header) = %ld/%lxx \n",
         actualKernelLen, actualKernelLen);
  round = actualKernelLen % 4096;
  roundedKernelLen = actualKernelLen;
  if (round)
    roundedKernelLen += (4096 - round);
  printf("Kernel length rounded up to a 4k multiple = %ld/%lxx \n",
         roundedKernelLen, roundedKernelLen);
  roundedKernelPages = roundedKernelLen / 4096;
  printf("Kernel pages to copy = %ld/%lxx\n", roundedKernelPages,
         roundedKernelPages);
  fseek(sysmap, 0, SEEK_END);
  sysmapFileLen = ftell(sysmap);
  fseek(sysmap, 0, SEEK_SET);
  printf("%s file size = %ld\n", argv[1], sysmapFileLen);
  sysmapLen = sysmapFileLen;
  roundR = 4096 - (sysmapLen % 4096);
  if (roundR) {
    printf("Rounding System Map file up to a multiple of 4096, adding %ld\n",
           roundR);
    sysmapLen += roundR;
  }
  printf("Rounded System Map size is %ld\n", sysmapLen);
  sysmapPages = sysmapLen / 4096;
  printf("System map pages to copy = %ld\n", sysmapPages);
  for (i = 0; i < sysmapPages; ++i) {
    get4k(sysmap, inbuf);
  }
  ptr_end = strstr(inbuf, " _end");
  if (!ptr_end) {
    printf("Unable to find _end in the sysmap file \n");
    printf("inbuf: \n");
    printf("%s \n", inbuf);
    exit(1);
  }
  printf("Found _end in the last page of the sysmap - backing up 10 characters "
         "it looks like %s",
         ptr_end - 10);
  sysmapStartOffs = (unsigned int)strtol(ptr_end - 10, NULL, 16);
  padPages = sysmapStartOffs / 4096 - roundedKernelPages;
  if (padPages < 0) {
    sysmapStartOffs = roundedKernelLen;
    printf("vmlinux is larger than _end indicates it needs to be - "
           "sysmapStartOffs = %lx \n",
           sysmapStartOffs);
    padPages = 0;
    printf("will insert %lx pages between the vmlinux and the start of the "
           "sysmap \n",
           padPages);
  } else {
    printf("vmlinux is smaller than _end indicates is needed - sysmapStartOffs "
           "= %lx \n",
           sysmapStartOffs);
    printf("will insert %lx pages between the vmlinux and the start of the "
           "sysmap \n",
           padPages);
  }
  for (i = 0; i < (((64 * 1024) / 4096)); ++i) {
    get4k(inputVmlinux, inbuf);
    put4k(outputVmlinux, inbuf);
  }
  fseek(inputVmlinux, (64 * 1024), SEEK_SET);
  for (i = 0; i < roundedKernelPages; ++i) {
    get4k(inputVmlinux, inbuf);
    if (i == 0) {
      unsigned long *p;
      printf("Storing embedded_sysmap_start at 0x3c\n");
      p = (unsigned long *)(inbuf + 0x3c);
      *p = sysmapStartOffs;
      printf("Storing embedded_sysmap_end at 0x44\n");
      p = (unsigned long *)(inbuf + 0x44);
      *p = sysmapStartOffs + sysmapFileLen;
    }
    put4k(outputVmlinux, inbuf);
  }
  for (i = 0; i < padPages; ++i) {
    memset(inbuf, 0, 4096);
    put4k(outputVmlinux, inbuf);
  }
  fseek(sysmap, 0, SEEK_SET);
  for (i = 0; i < sysmapPages; ++i) {
    get4k(sysmap, inbuf);
    put4k(outputVmlinux, inbuf);
  }
  fclose(sysmap);
  fclose(inputVmlinux);
  fclose(outputVmlinux);
  chmod(argv[3],
        S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x1018(%rbp)
movq   $0x0,-0x1020(%rbp)
movq   $0x0,-0x1028(%rbp)
movq   $0x0,-0x1030(%rbp)
movq   $0x0,-0x1038(%rbp)
movq   $0x0,-0x1040(%rbp)
movq   $0x0,-0x1048(%rbp)
movq   $0x0,-0x1050(%rbp)
movq   $0x0,-0x1058(%rbp)
movq   $0x0,-0x1060(%rbp)
movq   $0x0,-0x1068(%rbp)
movq   $0x0,-0x1070(%rbp)
movq   $0x0,-0x1078(%rbp)
movq   $0x0,-0x1080(%rbp)
movq   $0x0,-0x1088(%rbp)
movq   $0x0,-0x1090(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    12ab <main+0xeb>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jge    12cd <main+0x10d>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jge    12ef <main+0x12f>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd69(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1018(%rbp)
cmpq   $0x0,-0x1018(%rbp)
jne    1338 <main+0x178>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xd20(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    1381 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xcff(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1030(%rbp)
cmpq   $0x0,-0x1030(%rbp)
jne    13ca <main+0x20a>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x1028(%rbp),%rdi
mov    0x2c08(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x1028(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x1058(%rbp)
mov    -0x1028(%rbp),%rdi
mov    0x2bb6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x1058(%rbp),%rsi
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x1058(%rbp)
jne    1446 <main+0x286>
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x1058(%rbp),%rax
sub    $0x10000,%rax
mov    %rax,-0x1060(%rbp)
mov    -0x1060(%rbp),%rsi
mov    -0x1060(%rbp),%rdx
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1060(%rbp),%rax
and    $0xfff,%rax
mov    %rax,-0x1068(%rbp)
mov    -0x1060(%rbp),%rax
mov    %rax,-0x1070(%rbp)
cmpq   $0x0,-0x1068(%rbp)
je     14c0 <main+0x300>
mov    $0x1000,%eax
sub    -0x1068(%rbp),%rax
add    -0x1070(%rbp),%rax
mov    %rax,-0x1070(%rbp)
mov    -0x1070(%rbp),%rsi
mov    -0x1070(%rbp),%rdx
lea    0xc66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1070(%rbp),%rax
shr    $0xc,%rax
mov    %rax,-0x1088(%rbp)
mov    -0x1088(%rbp),%rsi
mov    -0x1088(%rbp),%rdx
lea    0xc6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1018(%rbp),%rdi
mov    0x2ac8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x1018(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x1018(%rbp),%rdi
mov    0x2a76(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x1040(%rbp),%rdx
lea    0xc32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1040(%rbp),%rax
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rcx
and    $0xfff,%rcx
mov    $0x1000,%eax
sub    %rcx,%rax
mov    %rax,-0x1050(%rbp)
cmpq   $0x0,-0x1050(%rbp)
je     15cb <main+0x40b>
mov    -0x1050(%rbp),%rsi
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1050(%rbp),%rax
add    -0x1048(%rbp),%rax
mov    %rax,-0x1048(%rbp)
mov    -0x1048(%rbp),%rsi
lea    0xc0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1048(%rbp),%rax
shr    $0xc,%rax
mov    %rax,-0x1080(%rbp)
mov    -0x1080(%rbp),%rsi
lea    0xc06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
cmp    -0x1080(%rbp),%rax
jae    1650 <main+0x490>
mov    -0x1018(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1080 <get4k@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    1612 <main+0x452>
lea    -0x1010(%rbp),%rdi
lea    0xbc8(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
jne    16b3 <main+0x4f3>
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xbbc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x1020(%rbp),%rsi
add    $0xfffffffffffffff6,%rsi
lea    0xb9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1020(%rbp),%rdi
add    $0xfffffffffffffff6,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,%eax
mov    %rax,-0x1078(%rbp)
mov    -0x1078(%rbp),%rax
shr    $0xc,%rax
sub    -0x1088(%rbp),%rax
mov    %rax,-0x1090(%rbp)
cmpq   $0x0,-0x1090(%rbp)
jge    175d <main+0x59d>
mov    -0x1070(%rbp),%rax
mov    %rax,-0x1078(%rbp)
mov    -0x1078(%rbp),%rsi
lea    0xb88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x1090(%rbp)
mov    -0x1090(%rbp),%rsi
lea    0xbb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1787 <main+0x5c7>
mov    -0x1078(%rbp),%rsi
lea    0xbe5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1090(%rbp),%rsi
lea    0xb88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x1038(%rbp)
cmpq   $0x10,-0x1038(%rbp)
10
jge    17dd <main+0x61d>
mov    -0x1028(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1080 <get4k@plt>
mov    -0x1030(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   10e0 <put4k@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    1792 <main+0x5d2>
mov    -0x1028(%rbp),%rdi
mov    0x27cd(%rip),%rax
mov    (%rax),%edx
mov    $0x10000,%esi
call   1090 <fseek@plt>
movq   $0x0,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
cmp    -0x1088(%rbp),%rax
jae    18ca <main+0x70a>
mov    -0x1028(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1080 <get4k@plt>
cmpq   $0x0,-0x1038(%rbp)
jne    18a0 <main+0x6e0>
lea    0xb5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rax
add    $0x3c,%rax
mov    %rax,-0x1098(%rbp)
mov    -0x1078(%rbp),%rcx
mov    -0x1098(%rbp),%rax
mov    %rcx,(%rax)
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1010(%rbp),%rax
add    $0x44,%rax
mov    %rax,-0x1098(%rbp)
mov    -0x1078(%rbp),%rcx
add    -0x1040(%rbp),%rcx
mov    -0x1098(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1030(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   10e0 <put4k@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    1802 <main+0x642>
movq   $0x0,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
cmp    -0x1090(%rbp),%rax
jge    1926 <main+0x766>
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1050 <memset@plt>
mov    -0x1030(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   10e0 <put4k@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    18d5 <main+0x715>
mov    -0x1018(%rbp),%rdi
mov    0x2684(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
movq   $0x0,-0x1038(%rbp)
mov    -0x1038(%rbp),%rax
cmp    -0x1080(%rbp),%rax
jae    1999 <main+0x7d9>
mov    -0x1018(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   1080 <get4k@plt>
mov    -0x1030(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
call   10e0 <put4k@plt>
mov    -0x1038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1038(%rbp)
jmp    1948 <main+0x788>
mov    -0x1018(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1028(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1030(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x25d4(%rip),%rax
mov    (%rax),%esi
mov    0x25fb(%rip),%rax
or     (%rax),%esi
mov    0x25fa(%rip),%rax
or     (%rax),%esi
mov    0x25c9(%rip),%rax
or     (%rax),%esi
mov    0x25d8(%rip),%rax
or     (%rax),%esi
mov    0x25af(%rip),%rax
or     (%rax),%esi
mov    0x25e6(%rip),%rax
or     (%rax),%esi
call   10a0 <chmod@plt>
xor    %eax,%eax
add    $0x10a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
cmp    $0x1,%edi
jle    17b5 <main+0x5e5>
cmp    $0x2,%edi
je     17be <main+0x5ee>
cmp    $0x3,%edi
jbe    17c7 <main+0x5f7>
mov    %rsi,%r13
mov    0x8(%rsi),%rdi
lea    0xdf6(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     17d0 <main+0x600>
mov    %rax,%r12
mov    0x10(%r13),%rdi
lea    0xdda(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     17dd <main+0x60d>
mov    %rax,0x18(%rsp)
mov    0x18(%r13),%rdi
lea    0xde4(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     17ea <main+0x61a>
mov    %rax,%r15
mov    0x2d84(%rip),%rax
mov    (%rax),%edx
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbp
mov    0x2d39(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    0xdc2(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbp,%rbp
je     17f7 <main+0x627>
lea    -0x10000(%rbp),%r14
lea    0xdb9(%rip),%rdi
mov    %r14,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rbx
add    $0xffffffffffff1000,%rbx
and    $0xfffffffffffff000,%rbx
test   $0xfff,%ebp
cmove  %r14,%rbx
lea    0xdbf(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,0x8(%rsp)
shr    $0xc,%rbx
lea    0xdd9(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r12,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbx
mov    0x2c82(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r13,0x38(%rsp)
mov    0x8(%r13),%rsi
lea    0xda7(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
and    $0xfff,%eax
mov    $0x1000,%r13d
sub    %rax,%r13
lea    0xd9a(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,0x20(%rsp)
add    %rbx,%r13
lea    0xdc0(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%r14
shr    $0xc,%r14
lea    0xdc8(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1000,%r13
jb     13e1 <main+0x211>
cmp    $0x2,%r14
mov    $0x1,%ebx
cmovae %r14,%rbx
lea    0x40(%rsp),%rbp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1090 <get4k@plt>
add    $0xffffffffffffffff,%rbx
jne    13d0 <main+0x200>
mov    %r14,0x28(%rsp)
lea    0xd9f(%rip),%rsi
lea    0x40(%rsp),%rdi
call   10e0 <strstr@plt>
test   %rax,%rax
je     180d <main+0x63d>
mov    %rax,%rbp
add    $0xfffffffffffffff6,%rbp
lea    0xd89(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %eax,%eax
mov    %rax,%r14
shr    $0xc,%r14
sub    0x10(%rsp),%r14
mov    %r13,0x30(%rsp)
js     1453 <main+0x283>
lea    0xe41(%rip),%rdi
mov    %rax,(%rsp)
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1470 <main+0x2a0>
lea    0xd93(%rip),%rdi
xor    %r14d,%r14d
mov    0x8(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,(%rsp)
mov    0x2b41(%rip),%rbp
lea    0xdbe(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x40(%rsp),%r13
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   10f0 <put4k@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%r13
call   10f0 <put4k@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x10000,%esi
call   10a0 <fseek@plt>
mov    0x8(%rsp),%rax
cmp    $0x1000,%rax
jb     16ac <main+0x4dc>
mov    0x10(%rsp),%rcx
cmp    $0x2,%rcx
mov    $0x1,%ebx
cmovae %rcx,%rbx
lea    0x40(%rsp),%rsi
mov    %r13,%rdi
call   1090 <get4k@plt>
mov    0x20(%rsp),%rbp
add    (%rsp),%rbp
lea    0xcba(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%rax
mov    %rax,0x7c(%rsp)
lea    0xccb(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,0x84(%rsp)
mov    %r15,%rdi
lea    0x40(%rsp),%rsi
call   10f0 <put4k@plt>
cmpq   $0x2000,0x8(%rsp)
jb     16ac <main+0x4dc>
add    $0xffffffffffffffff,%rbx
lea    0x40(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10f0 <put4k@plt>
add    $0xffffffffffffffff,%rbx
jne    1690 <main+0x4c0>
test   %r14,%r14
jle    16e0 <main+0x510>
lea    0x40(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10f0 <put4k@plt>
add    $0xffffffffffffffff,%r14
jne    16c0 <main+0x4f0>
mov    0x28d1(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cmpq   $0x1000,0x30(%rsp)
jb     173c <main+0x56c>
mov    0x28(%rsp),%rax
cmp    $0x2,%rax
mov    $0x1,%ebx
cmovae %rax,%rbx
lea    0x40(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rbp,%rsi
call   1090 <get4k@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10f0 <put4k@plt>
add    $0xffffffffffffffff,%rbx
jne    1720 <main+0x550>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2845(%rip),%rax
mov    0x286e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x286b(%rip),%rax
or     (%rax),%esi
mov    0x283a(%rip),%rax
or     (%rax),%esi
mov    0x2849(%rip),%rax
or     (%rax),%esi
mov    0x2820(%rip),%rax
or     (%rax),%esi
mov    0x38(%rsp),%rax
mov    0x18(%rax),%rdi
mov    0x284e(%rip),%rax
or     (%rax),%esi
call   10b0 <chmod@plt>
xor    %eax,%eax
add    $0x1048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc02(%rip),%rdi
jmp    17fe <main+0x62e>
lea    0xbdb(%rip),%rdi
jmp    17fe <main+0x62e>
lea    0xbad(%rip),%rdi
jmp    17fe <main+0x62e>
mov    0x8(%r13),%rsi
lea    0x827(%rip),%rdi
jmp    1831 <main+0x661>
mov    0x10(%r13),%rsi
lea    0x849(%rip),%rdi
jmp    1831 <main+0x661>
mov    0x18(%r13),%rsi
lea    0x835(%rip),%rdi
jmp    1831 <main+0x661>
lea    0xb4b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xabb(%rip),%rdi
call   1030 <puts@plt>
lea    0xad7(%rip),%rdi
call   1030 <puts@plt>
lea    0x966(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"Name of System Map file missing.\0A\00"
@.str.1 = [31 x i8] c"Name of vmlinux file missing.\0A\00"
@.str.2 = [38 x i8] c"Name of vmlinux output file missing.\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [38 x i8] c"System Map file \22%s\22 failed to open.\0A\00"
@.str.5 = [35 x i8] c"vmlinux file \22%s\22 failed to open.\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [42 x i8] c"output vmlinux file \22%s\22 failed to open.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [24 x i8] c"kernel file size = %ld\0A\00"
@.str.9 = [51 x i8] c"You must have a linux kernel specified as argv[2]\0A\00"
@.str.10 = [53 x i8] c"actual kernel length (minus ELF header) = %ld/%lxx \0A\00"
@.str.11 = [55 x i8] c"Kernel length rounded up to a 4k multiple = %ld/%lxx \0A\00"
@.str.12 = [33 x i8] c"Kernel pages to copy = %ld/%lxx\0A\00"
@.str.13 = [20 x i8] c"%s file size = %ld\0A\00"
@.str.14 = [63 x i8] c"Rounding System Map file up to a multiple of 4096, adding %ld\0A\00"
@.str.15 = [32 x i8] c"Rounded System Map size is %ld\0A\00"
@.str.16 = [32 x i8] c"System map pages to copy = %ld\0A\00"
@.str.17 = [6 x i8] c" _end\00"
@.str.18 = [41 x i8] c"Unable to find _end in the sysmap file \0A\00"
@.str.19 = [9 x i8] c"inbuf: \0A\00"
@.str.20 = [5 x i8] c"%s \0A\00"
@.str.21 = [86 x i8] c"Found _end in the last page of the sysmap - backing up 10 characters it looks like %s\00"
@.str.22 = [79 x i8] c"vmlinux is larger than _end indicates it needs to be - sysmapStartOffs = %lx \0A\00"
@.str.23 = [72 x i8] c"will insert %lx pages between the vmlinux and the start of the sysmap \0A\00"
@.str.24 = [75 x i8] c"vmlinux is smaller than _end indicates is needed - sysmapStartOffs = %lx \0A\00"
@.str.25 = [39 x i8] c"Storing embedded_sysmap_start at 0x3c\0A\00"
@.str.26 = [37 x i8] c"Storing embedded_sysmap_end at 0x44\0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
store i8* null, i8** %8
store i32* null, i32** %9
store i32* null, i32** %10
store i64 0, i64* %11
store i64 0, i64* %12
store i64 0, i64* %13
store i64 0, i64* %14
store i64 0, i64* %15
store i64 0, i64* %16
store i64 0, i64* %17
store i64 0, i64* %18
store i64 0, i64* %19
store i64 0, i64* %20
store i64 0, i64* %21
store i64 0, i64* %22
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %29
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 4
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %45, i32** %7
%46 = load i32*, i32** %7
%47 = icmp ne i32* %46, null
br i1 %47, label %54, label %48
48: ; preds = %41
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %41
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32* @fopen(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %58, i32** %9
%59 = load i32*, i32** %9
%60 = icmp ne i32* %59, null
br i1 %60, label %67, label %61
61: ; preds = %54
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %54
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 3
%70 = load i8*, i8** %69
%71 = call i32* @fopen(i8* %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %71, i32** %10
%72 = load i32*, i32** %10
%73 = icmp ne i32* %72, null
br i1 %73, label %80, label %74
74: ; preds = %67
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 3
%77 = load i8*, i8** %76
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %77)
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %67
%81 = load i32*, i32** %9
%82 = load i32, i32* @SEEK_END
%83 = call i32 @fseek(i32* %81, i32 0, i32 %82)
%84 = load i32*, i32** %9
%85 = call i64 @ftell(i32* %84)
store i64 %85, i64* %15
%86 = load i32*, i32** %9
%87 = load i32, i32* @SEEK_SET
%88 = call i32 @fseek(i32* %86, i32 0, i32 %87)
%89 = load i64, i64* %15
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %89)
%91 = load i64, i64* %15
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %80
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.9, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %80
%97 = load i64, i64* %15
%98 = sub i64 %97, 65536
store i64 %98, i64* %16
%99 = load i64, i64* %16
%100 = load i64, i64* %16
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i64 %99, i64 %100)
%102 = load i64, i64* %16
%103 = urem i64 %102, 4096
store i64 %103, i64* %17
%104 = load i64, i64* %16
store i64 %104, i64* %18
%105 = load i64, i64* %17
%106 = icmp ne i64 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %96
%108 = load i64, i64* %17
%109 = sub i64 4096, %108
%110 = load i64, i64* %18
%111 = add i64 %110, %109
store i64 %111, i64* %18
br label %112
112: ; preds = %107, %96
%113 = load i64, i64* %18
%114 = load i64, i64* %18
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), i64 %113, i64 %114)
%116 = load i64, i64* %18
%117 = udiv i64 %116, 4096
store i64 %117, i64* %21
%118 = load i64, i64* %21
%119 = load i64, i64* %21
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0), i64 %118, i64 %119)
%121 = load i32*, i32** %7
%122 = load i32, i32* @SEEK_END
%123 = call i32 @fseek(i32* %121, i32 0, i32 %122)
%124 = load i32*, i32** %7
%125 = call i64 @ftell(i32* %124)
store i64 %125, i64* %12
%126 = load i32*, i32** %7
%127 = load i32, i32* @SEEK_SET
%128 = call i32 @fseek(i32* %126, i32 0, i32 %127)
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 1
%131 = load i8*, i8** %130
%132 = load i64, i64* %12
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8* %131, i64 %132)
%134 = load i64, i64* %12
store i64 %134, i64* %13
%135 = load i64, i64* %13
%136 = urem i64 %135, 4096
%137 = sub i64 4096, %136
store i64 %137, i64* %14
%138 = load i64, i64* %14
%139 = icmp ne i64 %138, 0
br i1 %139, label %140, label %146
140: ; preds = %112
%141 = load i64, i64* %14
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.14, i64 0, i64 0), i64 %141)
%143 = load i64, i64* %14
%144 = load i64, i64* %13
%145 = add i64 %144, %143
store i64 %145, i64* %13
br label %146
146: ; preds = %140, %112
%147 = load i64, i64* %13
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i64 %147)
%149 = load i64, i64* %13
%150 = udiv i64 %149, 4096
store i64 %150, i64* %20
%151 = load i64, i64* %20
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i64 %151)
store i64 0, i64* %11
br label %153
153: ; preds = %161, %146
%154 = load i64, i64* %11
%155 = load i64, i64* %20
%156 = icmp ult i64 %154, %155
br i1 %156, label %157, label %164
157: ; preds = %153
%158 = load i32*, i32** %7
%159 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%160 = call i32 @get4k(i32* %158, i8* %159)
br label %161
161: ; preds = %157
%162 = load i64, i64* %11
%163 = add nsw i64 %162, 1
store i64 %163, i64* %11
br label %153
164: ; preds = %153
%165 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%166 = call i8* @strstr(i8* %165, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
store i8* %166, i8** %8
%167 = load i8*, i8** %8
%168 = icmp ne i8* %167, null
br i1 %168, label %175, label %169
169: ; preds = %164
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.18, i64 0, i64 0))
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0))
%172 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.20, i64 0, i64 0), i8* %172)
%174 = call i32 @exit(i32 1)
unreachable
175: ; preds = %164
%176 = load i8*, i8** %8
%177 = getelementptr inbounds i8, i8* %176, i64 -10
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.21, i64 0, i64 0), i8* %177)
%179 = load i8*, i8** %8
%180 = getelementptr inbounds i8, i8* %179, i64 -10
%181 = call i64 @strtol(i8* %180, i32* null, i32 16)
%182 = trunc i64 %181 to i32
%183 = zext i32 %182 to i64
store i64 %183, i64* %19
%184 = load i64, i64* %19
%185 = udiv i64 %184, 4096
%186 = load i64, i64* %21
%187 = sub i64 %185, %186
store i64 %187, i64* %22
%188 = load i64, i64* %22
%189 = icmp slt i64 %188, 0
br i1 %189, label %190, label %196
190: ; preds = %175
%191 = load i64, i64* %18
store i64 %191, i64* %19
%192 = load i64, i64* %19
%193 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.22, i64 0, i64 0), i64 %192)
store i64 0, i64* %22
%194 = load i64, i64* %22
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.23, i64 0, i64 0), i64 %194)
br label %201
196: ; preds = %175
%197 = load i64, i64* %19
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.24, i64 0, i64 0), i64 %197)
%199 = load i64, i64* %22
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.23, i64 0, i64 0), i64 %199)
br label %201
201: ; preds = %196, %190
store i64 0, i64* %11
br label %202
202: ; preds = %212, %201
%203 = load i64, i64* %11
%204 = icmp slt i64 %203, 16
br i1 %204, label %205, label %215
205: ; preds = %202
%206 = load i32*, i32** %9
%207 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%208 = call i32 @get4k(i32* %206, i8* %207)
%209 = load i32*, i32** %10
%210 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%211 = call i32 @put4k(i32* %209, i8* %210)
br label %212
212: ; preds = %205
%213 = load i64, i64* %11
%214 = add nsw i64 %213, 1
store i64 %214, i64* %11
br label %202
215: ; preds = %202
%216 = load i32*, i32** %9
%217 = load i32, i32* @SEEK_SET
%218 = call i32 @fseek(i32* %216, i32 65536, i32 %217)
store i64 0, i64* %11
br label %219
219: ; preds = %248, %215
%220 = load i64, i64* %11
%221 = load i64, i64* %21
%222 = icmp ult i64 %220, %221
br i1 %222, label %223, label %251
223: ; preds = %219
%224 = load i32*, i32** %9
%225 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%226 = call i32 @get4k(i32* %224, i8* %225)
%227 = load i64, i64* %11
%228 = icmp eq i64 %227, 0
br i1 %228, label %229, label %244
229: ; preds = %223
%230 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.25, i64 0, i64 0))
%231 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%232 = getelementptr inbounds i8, i8* %231, i64 60
%233 = bitcast i8* %232 to i64*
store i64* %233, i64** %23
%234 = load i64, i64* %19
%235 = load i64*, i64** %23
store i64 %234, i64* %235
%236 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.26, i64 0, i64 0))
%237 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%238 = getelementptr inbounds i8, i8* %237, i64 68
%239 = bitcast i8* %238 to i64*
store i64* %239, i64** %23
%240 = load i64, i64* %19
%241 = load i64, i64* %12
%242 = add i64 %240, %241
%243 = load i64*, i64** %23
store i64 %242, i64* %243
br label %244
244: ; preds = %229, %223
%245 = load i32*, i32** %10
%246 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%247 = call i32 @put4k(i32* %245, i8* %246)
br label %248
248: ; preds = %244
%249 = load i64, i64* %11
%250 = add nsw i64 %249, 1
store i64 %250, i64* %11
br label %219
251: ; preds = %219
store i64 0, i64* %11
br label %252
252: ; preds = %262, %251
%253 = load i64, i64* %11
%254 = load i64, i64* %22
%255 = icmp slt i64 %253, %254
br i1 %255, label %256, label %265
256: ; preds = %252
%257 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%258 = call i32 @memset(i8* %257, i32 0, i32 4096)
%259 = load i32*, i32** %10
%260 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%261 = call i32 @put4k(i32* %259, i8* %260)
br label %262
262: ; preds = %256
%263 = load i64, i64* %11
%264 = add nsw i64 %263, 1
store i64 %264, i64* %11
br label %252
265: ; preds = %252
%266 = load i32*, i32** %7
%267 = load i32, i32* @SEEK_SET
%268 = call i32 @fseek(i32* %266, i32 0, i32 %267)
store i64 0, i64* %11
br label %269
269: ; preds = %280, %265
%270 = load i64, i64* %11
%271 = load i64, i64* %20
%272 = icmp ult i64 %270, %271
br i1 %272, label %273, label %283
273: ; preds = %269
%274 = load i32*, i32** %7
%275 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%276 = call i32 @get4k(i32* %274, i8* %275)
%277 = load i32*, i32** %10
%278 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%279 = call i32 @put4k(i32* %277, i8* %278)
br label %280
280: ; preds = %273
%281 = load i64, i64* %11
%282 = add nsw i64 %281, 1
store i64 %282, i64* %11
br label %269
283: ; preds = %269
%284 = load i32*, i32** %7
%285 = call i32 @fclose(i32* %284)
%286 = load i32*, i32** %9
%287 = call i32 @fclose(i32* %286)
%288 = load i32*, i32** %10
%289 = call i32 @fclose(i32* %288)
%290 = load i8**, i8*** %5
%291 = getelementptr inbounds i8*, i8** %290, i64 3
%292 = load i8*, i8** %291
%293 = load i32, i32* @S_IRUSR
%294 = load i32, i32* @S_IWUSR
%295 = or i32 %293, %294
%296 = load i32, i32* @S_IXUSR
%297 = or i32 %295, %296
%298 = load i32, i32* @S_IRGRP
%299 = or i32 %297, %298
%300 = load i32, i32* @S_IXGRP
%301 = or i32 %299, %300
%302 = load i32, i32* @S_IROTH
%303 = or i32 %301, %302
%304 = load i32, i32* @S_IXOTH
%305 = or i32 %303, %304
%306 = call i32 @chmod(i8* %292, i32 %305)
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [38 x i8] c"System Map file \22%s\22 failed to open.\0A\00"
@.str.5 = [35 x i8] c"vmlinux file \22%s\22 failed to open.\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [42 x i8] c"output vmlinux file \22%s\22 failed to open.\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.8 = [24 x i8] c"kernel file size = %ld\0A\00"
@.str.10 = [53 x i8] c"actual kernel length (minus ELF header) = %ld/%lxx \0A\00"
@.str.11 = [55 x i8] c"Kernel length rounded up to a 4k multiple = %ld/%lxx \0A\00"
@.str.12 = [33 x i8] c"Kernel pages to copy = %ld/%lxx\0A\00"
@.str.13 = [20 x i8] c"%s file size = %ld\0A\00"
@.str.14 = [63 x i8] c"Rounding System Map file up to a multiple of 4096, adding %ld\0A\00"
@.str.15 = [32 x i8] c"Rounded System Map size is %ld\0A\00"
@.str.16 = [32 x i8] c"System map pages to copy = %ld\0A\00"
@.str.17 = [6 x i8] c" _end\00"
@.str.20 = [5 x i8] c"%s \0A\00"
@.str.21 = [86 x i8] c"Found _end in the last page of the sysmap - backing up 10 characters it looks like %s\00"
@.str.22 = [79 x i8] c"vmlinux is larger than _end indicates it needs to be - sysmapStartOffs = %lx \0A\00"
@.str.23 = [72 x i8] c"will insert %lx pages between the vmlinux and the start of the sysmap \0A\00"
@.str.24 = [75 x i8] c"vmlinux is smaller than _end indicates is needed - sysmapStartOffs = %lx \0A\00"
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@str = [40 x i8] c"Unable to find _end in the sysmap file \00"
@str.27 = [8 x i8] c"inbuf: \00"
@str.28 = [38 x i8] c"Storing embedded_sysmap_start at 0x3c\00"
@str.29 = [36 x i8] c"Storing embedded_sysmap_end at 0x44\00"
@str.30 = [50 x i8] c"You must have a linux kernel specified as argv[2]\00"
@str.31 = [37 x i8] c"Name of vmlinux output file missing.\00"
@str.32 = [30 x i8] c"Name of vmlinux file missing.\00"
@str.33 = [33 x i8] c"Name of System Map file missing.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.33, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.32, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %9
%15 = icmp ult i32 %0, 4
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.31, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i8*, i8** %20
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %25)
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i8*, i8** %29
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = tail call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i8*, i8** %38
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %43)
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = load i32, i32* @SEEK_END
%48 = tail call i32 @fseek(i32* %31, i32 0, i32 %47)
%49 = tail call i64 @ftell(i32* %31)
%50 = load i32, i32* @SEEK_SET
%51 = tail call i32 @fseek(i32* %31, i32 0, i32 %50)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %49)
%53 = icmp eq i64 %49, 0
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.30, i64 0, i64 0))
%56 = tail call i32 @exit(i32 1)
unreachable
57: ; preds = %46
%58 = add i64 %49, -65536
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0), i64 %58, i64 %58)
%60 = and i64 %49, 4095
%61 = icmp eq i64 %60, 0
%62 = add i64 %49, -61440
%63 = and i64 %62, -4096
%64 = select i1 %61, i64 %58, i64 %63
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.11, i64 0, i64 0), i64 %64, i64 %64)
%66 = lshr i64 %64, 12
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.12, i64 0, i64 0), i64 %66, i64 %66)
%68 = load i32, i32* @SEEK_END
%69 = tail call i32 @fseek(i32* %22, i32 0, i32 %68)
%70 = tail call i64 @ftell(i32* %22)
%71 = load i32, i32* @SEEK_SET
%72 = tail call i32 @fseek(i32* %22, i32 0, i32 %71)
%73 = load i8*, i8** %20
%74 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0), i8* %73, i64 %70)
%75 = and i64 %70, 4095
%76 = sub nuw nsw i64 4096, %75
%77 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.14, i64 0, i64 0), i64 %76)
%78 = add i64 %76, %70
%79 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i64 %78)
%80 = lshr i64 %78, 12
%81 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i64 %80)
%82 = icmp ult i64 %78, 4096
br i1 %82, label %90, label %83
83: ; preds = %57
%84 = call i64 @llvm.umax.i64(i64 %80, i64 1)
br label %85
85: ; preds = %83, %85
%86 = phi i64 [ %88, %85 ], [ 0, %83 ]
%87 = call i32 @get4k(i32* %22, i8* %4)
%88 = add nuw nsw i64 %86, 1
%89 = icmp eq i64 %88, %84
br i1 %89, label %90, label %85
90: ; preds = %85, %57
%91 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
%92 = icmp eq i8* %91, null
br i1 %92, label %93, label %98
93: ; preds = %90
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%95 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.27, i64 0, i64 0))
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.20, i64 0, i64 0), i8* %4)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %90
%99 = getelementptr inbounds i8, i8* %91, i64 -10
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.21, i64 0, i64 0), i8* %99)
%101 = call i64 @strtol(i8* nocapture %99, i32* null, i32 16)
%102 = and i64 %101, 4294967295
%103 = lshr i64 %102, 12
%104 = sub nsw i64 %103, %66
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %98
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @.str.22, i64 0, i64 0), i64 %64)
br label %110
108: ; preds = %98
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.24, i64 0, i64 0), i64 %102)
br label %110
110: ; preds = %108, %106
%111 = phi i64 [ %104, %108 ], [ 0, %106 ]
%112 = phi i64 [ %102, %108 ], [ %64, %106 ]
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.23, i64 0, i64 0), i64 %111)
%114 = call i32 @get4k(i32* %31, i8* %4)
%115 = call i32 @put4k(i32* %40, i8* %4)
%116 = call i32 @get4k(i32* %31, i8* %4)
%117 = call i32 @put4k(i32* %40, i8* %4)
%118 = call i32 @get4k(i32* %31, i8* %4)
%119 = call i32 @put4k(i32* %40, i8* %4)
%120 = call i32 @get4k(i32* %31, i8* %4)
%121 = call i32 @put4k(i32* %40, i8* %4)
%122 = call i32 @get4k(i32* %31, i8* %4)
%123 = call i32 @put4k(i32* %40, i8* %4)
%124 = call i32 @get4k(i32* %31, i8* %4)
%125 = call i32 @put4k(i32* %40, i8* %4)
%126 = call i32 @get4k(i32* %31, i8* %4)
%127 = call i32 @put4k(i32* %40, i8* %4)
%128 = call i32 @get4k(i32* %31, i8* %4)
%129 = call i32 @put4k(i32* %40, i8* %4)
%130 = call i32 @get4k(i32* %31, i8* %4)
%131 = call i32 @put4k(i32* %40, i8* %4)
%132 = call i32 @get4k(i32* %31, i8* %4)
%133 = call i32 @put4k(i32* %40, i8* %4)
%134 = call i32 @get4k(i32* %31, i8* %4)
%135 = call i32 @put4k(i32* %40, i8* %4)
%136 = call i32 @get4k(i32* %31, i8* %4)
%137 = call i32 @put4k(i32* %40, i8* %4)
%138 = call i32 @get4k(i32* %31, i8* %4)
%139 = call i32 @put4k(i32* %40, i8* %4)
%140 = call i32 @get4k(i32* %31, i8* %4)
%141 = call i32 @put4k(i32* %40, i8* %4)
%142 = call i32 @get4k(i32* %31, i8* %4)
%143 = call i32 @put4k(i32* %40, i8* %4)
%144 = call i32 @get4k(i32* %31, i8* %4)
%145 = call i32 @put4k(i32* %40, i8* %4)
%146 = load i32, i32* @SEEK_SET
%147 = call i32 @fseek(i32* %31, i32 65536, i32 %146)
%148 = icmp ult i64 %64, 4096
br i1 %148, label %161, label %149
149: ; preds = %110
%150 = call i64 @llvm.umax.i64(i64 %66, i64 1)
%151 = call i32 @get4k(i32* %31, i8* %4)
%152 = add i64 %112, %70
%153 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 68
%154 = bitcast i8* %153 to i64*
%155 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 60
%156 = bitcast i8* %155 to i64*
%157 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.28, i64 0, i64 0))
store i64 %112, i64* %156
%158 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.29, i64 0, i64 0))
store i64 %152, i64* %154
%159 = call i32 @put4k(i32* %40, i8* %4)
%160 = icmp ult i64 %64, 8192
br i1 %160, label %161, label %163
161: ; preds = %163, %149, %110
%162 = icmp sgt i64 %111, 0
br i1 %162, label %169, label %175
163: ; preds = %149, %163
%164 = phi i64 [ %167, %163 ], [ 1, %149 ]
%165 = call i32 @get4k(i32* %31, i8* %4)
%166 = call i32 @put4k(i32* %40, i8* %4)
%167 = add nuw nsw i64 %164, 1
%168 = icmp eq i64 %167, %150
br i1 %168, label %161, label %163
169: ; preds = %161, %169
%170 = phi i64 [ %173, %169 ], [ 0, %161 ]
%171 = call i32 @memset(i8* %4, i32 0, i32 4096)
%172 = call i32 @put4k(i32* %40, i8* %4)
%173 = add nuw nsw i64 %170, 1
%174 = icmp eq i64 %173, %111
br i1 %174, label %175, label %169
175: ; preds = %169, %161
%176 = load i32, i32* @SEEK_SET
%177 = call i32 @fseek(i32* %22, i32 0, i32 %176)
br i1 %82, label %186, label %178
178: ; preds = %175
%179 = call i64 @llvm.umax.i64(i64 %80, i64 1)
br label %180
180: ; preds = %178, %180
%181 = phi i64 [ %184, %180 ], [ 0, %178 ]
%182 = call i32 @get4k(i32* %22, i8* %4)
%183 = call i32 @put4k(i32* %40, i8* %4)
%184 = add nuw nsw i64 %181, 1
%185 = icmp eq i64 %184, %179
br i1 %185, label %186, label %180
186: ; preds = %180, %175
%187 = call i32 @fclose(i32* %22)
%188 = call i32 @fclose(i32* %31)
%189 = call i32 @fclose(i32* %40)
%190 = load i8*, i8** %38
%191 = load i32, i32* @S_IRUSR
%192 = load i32, i32* @S_IWUSR
%193 = or i32 %192, %191
%194 = load i32, i32* @S_IXUSR
%195 = or i32 %193, %194
%196 = load i32, i32* @S_IRGRP
%197 = or i32 %195, %196
%198 = load i32, i32* @S_IXGRP
%199 = or i32 %197, %198
%200 = load i32, i32* @S_IROTH
%201 = or i32 %199, %200
%202 = load i32, i32* @S_IXOTH
%203 = or i32 %201, %202
%204 = call i32 @chmod(i8* %190, i32 %203)
ret i32 0
}