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

/* Variables and functions */
scalar_t__ MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int PROT_READ;
int PROT_WRITE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getchar();
scalar_t__ iopl(int);
scalar_t__ mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char const *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
unsigned long strtoul(char const *, char **, int);
int usleep(int);
int main(int argc, const char *argv[]) {
  FILE *fp;
  char buf[100];
  char addr[10], origin[10], fourbyte[10], c;
  int map_len, i, j, bytes, parsed[4], fd;
  int sleep_now = 0, new_map = 0;
  long hex_buf;
  unsigned long data, tempaddress, physicaladdress, *log_phy_addr,
      pageoffset = 0x0L;
  unsigned long icr_address, pageoffset_icr_low, pageoffset_icr_high;
  char filename[80];
  unsigned long apid;
  unsigned long bAddr = 0x9F;
  int silent = 0;
  if (argc != 4) {
    printf("Usage:%s <file.bin> <0xAPID> <0xboot code addr>\n", argv[0]);
    exit(-1);
  } else if (strlen(argv[1]) > 80) {
    printf("Filename needs to be less than %d chars long\n", 80);
    exit(-2);
  } else {
    char *p;
    errno = 0;
    apid = strtoul(argv[2], &p, 10);
    if (errno != 0 || *p != 0 || p == argv[2] || apid > 8 || apid == 0) {
      printf("argv2:%s\n", argv[2]);
      printf("APID:%lu incorrect! You should choose between 1 to 8\n", apid);
      exit(-3);
    }
    errno = 0;
    bAddr = strtoul(argv[3], &p, 16);
    if (errno != 0 || *p != 0 || p == argv[3] || bAddr > 0xFF) {
      printf("argv3:%s\n", argv[2]);
      printf("boot code addr:%lu incorrect! You should use < 0xFF\n", bAddr);
      exit(-4);
    }
    strncpy(filename, argv[1], 80);
    printf("Filename:%s\tAPID:0x%08x\tBoot Addr:0x%02x\n", filename,
           (apid << 24), bAddr);
  }
  if (iopl(3)) {
    printf("Cannot get I/O permissions (being root helps)\n");
    return -1;
  }
  fd = open("/dev/mem", O_RDWR);
  if ((fp = fopen(filename, "r")) == NULL) {
    printf("File not found\n");
    return -1;
  } else {
    while (!(fgets(buf, 100, fp) == NULL)) {
      strncpy(origin, buf, 7);
      if ((strncmp(origin, "/origin", 7)) == 0) {
        if (new_map == 1) {
          printf("Unmapping 'old' page\n");
          tempaddress &= 0xfffff000;
          munmap((void *)tempaddress, map_len);
        }
        strncpy(addr, buf + 8, 8);
        physicaladdress = strtoul(addr, NULL, 16);
        printf("Press key to start writing for this origin address 0x%x\n",
               physicaladdress);
        printf("Press y to auto load all data\n");
        if (!silent) {
          c = getchar();
          if (c == 'y')
            silent = 1;
        }
        map_len = 0x1000;
        pageoffset = physicaladdress & 0x00000fff;
        physicaladdress = physicaladdress & 0xfffff000;
        tempaddress =
            (unsigned long)mmap(NULL, map_len, PROT_READ | PROT_WRITE,
                                MAP_SHARED, fd, (off_t)physicaladdress);
        if (tempaddress == (unsigned long)MAP_FAILED) {
          perror("Mapping memory for absolute memory access failed.\n");
          return -3;
        }
        tempaddress |= pageoffset;
        log_phy_addr = (unsigned long *)tempaddress;
        physicaladdress |= pageoffset;
        new_map = 1;
      } else {
        bytes = 0;
        for (i = 0; i < 4; i++) {
          for (j = 0; j < 4; j++) {
            strncpy(fourbyte, buf + bytes, 2);
            hex_buf = strtol(fourbyte, NULL, 16);
            bytes += 3;
            parsed[j] = hex_buf;
          }
          data = parsed[0] << 0;
          data += parsed[1] << 8;
          data += parsed[2] << 16;
          data += parsed[3] << 24;
          *log_phy_addr = data;
          log_phy_addr++;
          data = 0;
        }
      }
    }
  }
  printf("End of File\n");
  printf("Opcodes loaded in memory, ready to send INIT/SIPI sequence\n");
  physicaladdress = 0xfee00000;
  pageoffset_icr_low = 0x00000300;
  pageoffset_icr_high = 0x00000310;
  printf("Assuming APIC physical base: %lx \n", physicaladdress);
  tempaddress = (unsigned long)mmap(NULL, map_len, PROT_READ | PROT_WRITE,
                                    MAP_SHARED, fd, (off_t)physicaladdress);
  if (tempaddress == (unsigned long)MAP_FAILED) {
    perror("Mapping memory for absolute memory access failed.\n");
    return -3;
  }
  printf("Hit enter for INIT / SIPI / SIPI sequence\n");
  c = getchar();
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_high;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = apid << 24;
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_low;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = 0x004500;
  sleep_now = usleep(10000);
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_high;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = apid << 24;
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_low;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = 0x004600 | bAddr;
  sleep_now = usleep(500);
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_high;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = apid << 24;
  icr_address = tempaddress;
  icr_address |= pageoffset_icr_low;
  log_phy_addr = (unsigned long *)icr_address;
  *log_phy_addr = 0x004600 | bAddr;
  sleep_now = usleep(500);
  printf("Unmapping APIC Base page\n");
  tempaddress &= 0xfffff000;
  munmap((void *)tempaddress, map_len);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xc8(%rbp)
movl   $0x0,-0xcc(%rbp)
movq   $0x0,-0x100(%rbp)
movq   $0x9f,-0x180(%rbp)
movl   $0x0,-0x184(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1276 <main+0x76>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x50,%eax
jle    12a9 <main+0xa9>
lea    0xd9e(%rip),%rdi
mov    $0x50,%esi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffe,%edi
call   1110 <exit@plt>
mov    0x2d18(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x190(%rbp),%rsi
mov    $0xa,%edx
call   1100 <strtoul@plt>
mov    %rax,-0x178(%rbp)
mov    0x2cea(%rip),%rax
cmpq   $0x0,(%rax)
jne    132c <main+0x12c>
mov    -0x190(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    132c <main+0x12c>
mov    -0x190(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x10(%rcx),%rax
je     132c <main+0x12c>
cmpq   $0x8,-0x178(%rbp)
08
ja     132c <main+0x12c>
cmpq   $0x0,-0x178(%rbp)
jne    1361 <main+0x161>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x178(%rbp),%rsi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffd,%edi
call   1110 <exit@plt>
mov    0x2c60(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    -0x190(%rbp),%rsi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %rax,-0x180(%rbp)
mov    0x2c32(%rip),%rax
cmpq   $0x0,(%rax)
jne    13d9 <main+0x1d9>
mov    -0x190(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    13d9 <main+0x1d9>
mov    -0x190(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    0x18(%rcx),%rax
je     13d9 <main+0x1d9>
cmpq   $0xff,-0x180(%rbp)
jbe    140e <main+0x20e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x180(%rbp),%rsi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfffffffc,%edi
call   1110 <exit@plt>
lea    -0x170(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
lea    -0x170(%rbp),%rsi
mov    -0x178(%rbp),%rdx
shl    $0x18,%rdx
mov    -0x180(%rbp),%rcx
lea    0xc97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1453 <main+0x253>
mov    $0x3,%edi
call   1080 <iopl@plt>
cmp    $0x0,%rax
je     1481 <main+0x281>
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1b4b <main+0x94b>
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
lea    0xca6(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0xc4(%rbp)
lea    -0x170(%rbp),%rdi
lea    0xc96(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14d7 <main+0x2d7>
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1b4b <main+0x94b>
jmp    14dc <main+0x2dc>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
sete   %al
xor    $0xff,%al
test   $0x1,%al
jne    1504 <main+0x304>
jmp    1855 <main+0x655>
lea    -0x94(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
lea    -0x94(%rbp),%rdi
lea    0xc2b(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    16ff <main+0x4ff>
cmpl   $0x1,-0xcc(%rbp)
jne    1580 <main+0x380>
lea    0xc0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movabs $0xfffff000,%rax
and    -0xe8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
mov    -0xa4(%rbp),%esi
call   10c0 <munmap@plt>
lea    -0x8a(%rbp),%rdi
lea    -0x80(%rbp),%rsi
add    $0x8,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x8a(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1100 <strtoul@plt>
mov    %rax,-0xf0(%rbp)
mov    -0xf0(%rbp),%rsi
lea    0xbad(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x0,-0x184(%rbp)
jne    1611 <main+0x411>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %al,-0x9f(%rbp)
movsbl -0x9f(%rbp),%eax
cmp    $0x79,%eax
jne    160c <main+0x40c>
movl   $0x1,-0x184(%rbp)
jmp    1611 <main+0x411>
movl   $0x1000,-0xa4(%rbp)
mov    -0xf0(%rbp),%rax
and    $0xfff,%rax
mov    %rax,-0x100(%rbp)
movabs $0xfffff000,%rax
and    -0xf0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
mov    -0xa4(%rbp),%esi
mov    0x29a4(%rip),%rax
mov    (%rax),%edx
mov    0x2963(%rip),%rax
or     (%rax),%edx
mov    0x2982(%rip),%rax
mov    (%rax),%ecx
mov    -0xc4(%rbp),%r8d
mov    -0xf0(%rbp),%rax
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mmap@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
mov    0x2921(%rip),%rcx
cmp    (%rcx),%rax
jne    16b8 <main+0x4b8>
lea    0xb21(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1b4b <main+0x94b>
mov    -0x100(%rbp),%rax
or     -0xe8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x100(%rbp),%rax
or     -0xf0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
movl   $0x1,-0xcc(%rbp)
jmp    1850 <main+0x650>
movl   $0x0,-0xb0(%rbp)
movl   $0x0,-0xa8(%rbp)
cmpl   $0x4,-0xa8(%rbp)
jge    184b <main+0x64b>
movl   $0x0,-0xac(%rbp)
cmpl   $0x4,-0xac(%rbp)
jge    17ac <main+0x5ac>
lea    -0x9e(%rbp),%rdi
lea    -0x80(%rbp),%rsi
movslq -0xb0(%rbp),%rax
add    %rax,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
lea    -0x9e(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtol@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xb0(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xb0(%rbp)
mov    -0xd8(%rbp),%rax
mov    %eax,%ecx
movslq -0xac(%rbp),%rax
mov    %ecx,-0xc0(%rbp,%rax,4)
mov    -0xac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    172a <main+0x52a>
mov    -0xc0(%rbp),%eax
shl    $0x0,%eax
cltq
mov    %rax,-0xe0(%rbp)
mov    -0xbc(%rbp),%eax
shl    $0x8,%eax
cltq
add    -0xe0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xb8(%rbp),%eax
shl    $0x10,%eax
cltq
add    -0xe0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xb4(%rbp),%eax
shl    $0x18,%eax
cltq
add    -0xe0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xe0(%rbp),%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xf8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0xf8(%rbp)
movq   $0x0,-0xe0(%rbp)
mov    -0xa8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa8(%rbp)
jmp    1713 <main+0x513>
jmp    1850 <main+0x650>
jmp    14dc <main+0x2dc>
jmp    185a <main+0x65a>
lea    0x99a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0x999(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xfee00000,%eax
mov    %rax,-0xf0(%rbp)
movq   $0x300,-0x110(%rbp)
movq   $0x310,-0x118(%rbp)
mov    -0xf0(%rbp),%rsi
lea    0x99e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xa4(%rbp),%esi
mov    0x273e(%rip),%rax
mov    (%rax),%edx
mov    0x26fd(%rip),%rax
or     (%rax),%edx
mov    0x271c(%rip),%rax
mov    (%rax),%ecx
mov    -0xc4(%rbp),%r8d
mov    -0xf0(%rbp),%rax
mov    %eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mmap@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
mov    0x26bb(%rip),%rcx
cmp    (%rcx),%rax
jne    191e <main+0x71e>
lea    0x8bb(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1b4b <main+0x94b>
lea    0x942(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %al,-0x9f(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x118(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x178(%rbp),%rcx
shl    $0x18,%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x110(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf8(%rbp),%rax
movq   $0x4500,(%rax)
mov    $0x2710,%edi
call   1120 <usleep@plt>
mov    %eax,-0xc8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x118(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x178(%rbp),%rcx
shl    $0x18,%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x110(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x180(%rbp),%rcx
or     $0x4600,%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x1f4,%edi
call   1120 <usleep@plt>
mov    %eax,-0xc8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x118(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x178(%rbp),%rcx
shl    $0x18,%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x110(%rbp),%rax
or     -0x108(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x108(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    -0x180(%rbp),%rcx
or     $0x4600,%rcx
mov    -0xf8(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x1f4,%edi
call   1120 <usleep@plt>
mov    %eax,-0xc8(%rbp)
lea    0x77f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movabs $0xfffff000,%rax
and    -0xe8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rdi
mov    -0xa4(%rbp),%esi
call   10c0 <munmap@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1795 <main+0x585>
mov    0x8(%rbx),%rdi
call   1060 <strlen@plt>
cmp    $0x51,%eax
jge    17b0 <main+0x5a0>
mov    0x2d82(%rip),%r14
movq   $0x0,(%r14)
mov    0x10(%rbx),%rdi
lea    0x60(%rsp),%rsi
mov    $0xa,%edx
call   1110 <strtoul@plt>
mov    %rax,%r15
cmpq   $0x0,(%r14)
jne    173b <main+0x52b>
mov    0x60(%rsp),%rax
cmpb   $0x0,(%rax)
jne    173b <main+0x52b>
cmp    0x10(%rbx),%rax
je     173b <main+0x52b>
cmp    $0x8,%r15
ja     173b <main+0x52b>
test   %r15,%r15
je     173b <main+0x52b>
movq   $0x0,(%r14)
mov    0x18(%rbx),%rdi
lea    0x60(%rsp),%rsi
mov    $0x10,%edx
call   1110 <strtoul@plt>
cmpq   $0x0,(%r14)
mov    %rax,%r14
jne    1768 <main+0x558>
mov    0x60(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1768 <main+0x558>
cmp    0x18(%rbx),%rax
je     1768 <main+0x558>
cmp    $0x100,%r14
jae    1768 <main+0x558>
mov    0x8(%rbx),%rsi
lea    0xd0(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%edx
call   1030 <strncpy@plt>
shl    $0x18,%r15
lea    0xdd6(%rip),%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x3,%edi
call   1090 <iopl@plt>
test   %rax,%rax
je     133e <main+0x12e>
lea    0xf48(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
jmp    1706 <main+0x4f6>
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
lea    0xdba(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,0xc(%rsp)
lea    0xdb3(%rip),%rsi
lea    0xd0(%rsp),%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     171b <main+0x50b>
mov    %rax,%r12
mov    %r14,0x18(%rsp)
mov    %r15,0x20(%rsp)
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1604 <main+0x3f4>
lea    0x42(%rsp),%r14
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
mov    %r12,0x30(%rsp)
jmp    1495 <main+0x285>
xchg   %ax,%ax
lea    0x56(%rsp),%rbx
mov    %rbx,%rdi
lea    0x68(%rsp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1110 <strtoul@plt>
mov    %rax,%rbx
lea    0xd2b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe33(%rip),%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x14(%rsp)
mov    $0x1,%ecx
je     15f1 <main+0x3e1>
mov    %ecx,0x14(%rsp)
mov    0x2b9f(%rip),%rax
mov    (%rax),%edx
mov    0x2bce(%rip),%rax
or     (%rax),%edx
mov    0x2bb5(%rip),%rax
mov    (%rax),%ecx
mov    %ebx,%r9d
and    $0xfffff000,%r9d
xor    %edi,%edi
mov    $0x1000,%esi
mov    0xc(%rsp),%r8d
call   1070 <mmap@plt>
mov    %rax,%rcx
mov    0x2b5e(%rip),%rax
cmp    (%rax),%rcx
je     1727 <main+0x517>
and    $0xfff,%ebx
or     %rbx,%rcx
movl   $0x1,0x10(%rsp)
mov    %rcx,0x28(%rsp)
mov    %rcx,%r13
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1604 <main+0x3f4>
lea    0x4c(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
lea    0xc5f(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     15c0 <main+0x3b0>
xor    %r15d,%r15d
mov    %rbp,%rbx
mov    %r13,0x38(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtol@plt>
mov    %rax,%r13
lea    0x3(%rbx),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtol@plt>
mov    %rax,%rbp
lea    0x6(%rbx),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtol@plt>
mov    %rax,%r12
lea    0x9(%rbx),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtol@plt>
movslq %r13d,%rcx
mov    0x38(%rsp),%r13
shl    $0x8,%ebp
movslq %ebp,%rdx
add    %rcx,%rdx
shl    $0x10,%r12d
movslq %r12d,%rcx
add    %rdx,%rcx
shl    $0x18,%eax
cltq
add    %rcx,%rax
mov    %rax,0x0(%r13,%r15,1)
add    $0xc,%rbx
add    $0x8,%r15
cmp    $0x20,%r15d
jne    14e0 <main+0x2d0>
add    %r15,%r13
mov    0x30(%rsp),%r12
lea    0x60(%rsp),%rbp
jmp    147c <main+0x26c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpl   $0x1,0x10(%rsp)
jne    13c0 <main+0x1b0>
lea    0xc80(%rip),%rdi
call   1050 <puts@plt>
mov    0x28(%rsp),%rdi
and    $0xfffff000,%edi
mov    $0x1000,%esi
call   10d0 <munmap@plt>
jmp    13c0 <main+0x1b0>
xor    %eax,%eax
call   10b0 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x79,%al
sete   %cl
jmp    1416 <main+0x206>
lea    0xb9f(%rip),%rdi
call   1050 <puts@plt>
lea    0xb9f(%rip),%rdi
call   1050 <puts@plt>
lea    0xb64(%rip),%rdi
xor    %r14d,%r14d
mov    $0xfee00000,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x29bf(%rip),%rax
mov    0x2980(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x299d(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    0xc(%rsp),%r8d
mov    $0xfee00000,%r9d
call   1070 <mmap@plt>
mov    %rax,%r15
mov    0x294a(%rip),%rax
cmp    (%rax),%r15
je     1727 <main+0x517>
lea    0xb73(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   10b0 <getchar@plt>
mov    %r15,%r13
or     $0x310,%r13
mov    0x20(%rsp),%r12
mov    %r12,0x0(%r13)
mov    %r15,%rbx
or     $0x300,%rbx
movq   $0x4500,(%rbx)
mov    $0x2710,%edi
call   1130 <usleep@plt>
mov    %r12,0x0(%r13)
mov    0x18(%rsp),%rbp
or     $0x4600,%rbp
mov    %rbp,(%rbx)
mov    $0x1f4,%edi
call   1130 <usleep@plt>
mov    %r12,0x0(%r13)
mov    %rbp,(%rbx)
mov    $0x1f4,%edi
call   1130 <usleep@plt>
lea    0xb2e(%rip),%rdi
call   1050 <puts@plt>
and    $0xfffff000,%r15d
mov    %r15,%rdi
mov    $0x1000,%esi
call   10d0 <munmap@plt>
mov    %r14d,%eax
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb45(%rip),%rdi
jmp    132e <main+0x11e>
lea    0xa26(%rip),%rdi
call   1100 <perror@plt>
mov    $0xfffffffd,%r14d
jmp    1706 <main+0x4f6>
mov    0x10(%rbx),%rsi
lea    0x919(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x915(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffd,%edi
call   1120 <exit@plt>
mov    0x10(%rbx),%rsi
lea    0x92c(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x928(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffc,%edi
call   1120 <exit@plt>
mov    (%rbx),%rsi
lea    0x861(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
lea    0x87a(%rip),%rdi
mov    $0x50,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xfffffffe,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Usage:%s <file.bin> <0xAPID> <0xboot code addr>\0A\00"
@.str.1 = [46 x i8] c"Filename needs to be less than %d chars long\0A\00"
@errno = global i64 0
@.str.2 = [10 x i8] c"argv2:%s\0A\00"
@.str.3 = [54 x i8] c"APID:%lu incorrect! You should choose between 1 to 8\0A\00"
@.str.4 = [10 x i8] c"argv3:%s\0A\00"
@.str.5 = [53 x i8] c"boot code addr:%lu incorrect! You should use < 0xFF\0A\00"
@.str.6 = [42 x i8] c"Filename:%s\09APID:0x%08x\09Boot Addr:0x%02x\0A\00"
@.str.7 = [47 x i8] c"Cannot get I/O permissions (being root helps)\0A\00"
@.str.8 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.9 = [2 x i8] c"r\00"
@.str.10 = [16 x i8] c"File not found\0A\00"
@.str.11 = [8 x i8] c"/origin\00"
@.str.12 = [22 x i8] c"Unmapping 'old' page\0A\00"
@.str.13 = [57 x i8] c"Press key to start writing for this origin address 0x%x\0A\00"
@.str.14 = [31 x i8] c"Press y to auto load all data\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i64 0
@.str.15 = [51 x i8] c"Mapping memory for absolute memory access failed.\0A\00"
@.str.16 = [13 x i8] c"End of File\0A\00"
@.str.17 = [60 x i8] c"Opcodes loaded in memory, ready to send INIT/SIPI sequence\0A\00"
@.str.18 = [35 x i8] c"Assuming APIC physical base: %lx \0A\00"
@.str.19 = [43 x i8] c"Hit enter for INIT / SIPI / SIPI sequence\0A\00"
@.str.20 = [26 x i8] c"Unmapping APIC Base page\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [100 x i8]
%8 = alloca [10 x i8]
%9 = alloca [10 x i8]
%10 = alloca [10 x i8]
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [4 x i32]
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i64
%21 = alloca i64
%22 = alloca i64
%23 = alloca i64
%24 = alloca i64*
%25 = alloca i64
%26 = alloca i64
%27 = alloca i64
%28 = alloca i64
%29 = alloca [80 x i8]
%30 = alloca i64
%31 = alloca i64
%32 = alloca i32
%33 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %18
store i32 0, i32* %19
store i64 0, i64* %25
store i64 159, i64* %31
store i32 0, i32* %32
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 4
br i1 %35, label %36, label %42
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %2
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 @strlen(i8* %45)
%47 = icmp sgt i32 %46, 80
br i1 %47, label %48, label %51
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 80)
%50 = call i32 @exit(i32 -2)
unreachable
51: ; preds = %42
store i64 0, i64* @errno
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i64 @strtoul(i8* %54, i8** %33, i32 10)
store i64 %55, i64* %30
%56 = load i64, i64* @errno
%57 = icmp ne i64 %56, 0
br i1 %57, label %75, label %58
58: ; preds = %51
%59 = load i8*, i8** %33
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %75, label %63
63: ; preds = %58
%64 = load i8*, i8** %33
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = icmp eq i8* %64, %67
br i1 %68, label %75, label %69
69: ; preds = %63
%70 = load i64, i64* %30
%71 = icmp ugt i64 %70, 8
br i1 %71, label %75, label %72
72: ; preds = %69
%73 = load i64, i64* %30
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %83
75: ; preds = %72, %69, %63, %58, %51
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 2
%78 = load i8*, i8** %77
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %78)
%80 = load i64, i64* %30
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i64 %80)
%82 = call i32 @exit(i32 -3)
unreachable
83: ; preds = %72
store i64 0, i64* @errno
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 3
%86 = load i8*, i8** %85
%87 = call i64 @strtoul(i8* %86, i8** %33, i32 16)
store i64 %87, i64* %31
%88 = load i64, i64* @errno
%89 = icmp ne i64 %88, 0
br i1 %89, label %104, label %90
90: ; preds = %83
%91 = load i8*, i8** %33
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
%94 = icmp ne i32 %93, 0
br i1 %94, label %104, label %95
95: ; preds = %90
%96 = load i8*, i8** %33
%97 = load i8**, i8*** %5
%98 = getelementptr inbounds i8*, i8** %97, i64 3
%99 = load i8*, i8** %98
%100 = icmp eq i8* %96, %99
br i1 %100, label %104, label %101
101: ; preds = %95
%102 = load i64, i64* %31
%103 = icmp ugt i64 %102, 255
br i1 %103, label %104, label %112
104: ; preds = %101, %95, %90, %83
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 2
%107 = load i8*, i8** %106
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %107)
%109 = load i64, i64* %31
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i64 %109)
%111 = call i32 @exit(i32 -4)
unreachable
112: ; preds = %101
%113 = getelementptr inbounds [80 x i8], [80 x i8]* %29, i64 0, i64 0
%114 = load i8**, i8*** %5
%115 = getelementptr inbounds i8*, i8** %114, i64 1
%116 = load i8*, i8** %115
%117 = call i32 @strncpy(i8* %113, i8* %116, i32 80)
%118 = getelementptr inbounds [80 x i8], [80 x i8]* %29, i64 0, i64 0
%119 = load i64, i64* %30
%120 = shl i64 %119, 24
%121 = load i64, i64* %31
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %118, i64 %120, i64 %121)
br label %123
123: ; preds = %112
br label %124
124: ; preds = %123
%125 = call i64 @iopl(i32 3)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %124
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %353
129: ; preds = %124
%130 = load i32, i32* @O_RDWR
%131 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %130)
store i32 %131, i32* %17
%132 = getelementptr inbounds [80 x i8], [80 x i8]* %29, i64 0, i64 0
%133 = call i32* @fopen(i8* %132, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32* %133, i32** %6
%134 = icmp eq i32* %133, null
br i1 %134, label %135, label %137
135: ; preds = %129
%136 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %3
br label %353
137: ; preds = %129
br label %138
138: ; preds = %267, %137
%139 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%140 = load i32*, i32** %6
%141 = call i32* @fgets(i8* %139, i32 100, i32* %140)
%142 = icmp eq i32* %141, null
%143 = xor i1 %142, true
br i1 %143, label %144, label %268
144: ; preds = %138
%145 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%146 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%147 = call i32 @strncpy(i8* %145, i8* %146, i32 7)
%148 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%149 = call i64 @strncmp(i8* %148, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i32 7)
%150 = icmp eq i64 %149, 0
br i1 %150, label %151, label %209
151: ; preds = %144
%152 = load i32, i32* %19
%153 = icmp eq i32 %152, 1
br i1 %153, label %154, label %162
154: ; preds = %151
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0))
%156 = load i64, i64* %22
%157 = and i64 %156, 4294963200
store i64 %157, i64* %22
%158 = load i64, i64* %22
%159 = inttoptr i64 %158 to i8*
%160 = load i32, i32* %12
%161 = call i32 @munmap(i8* %159, i32 %160)
br label %162
162: ; preds = %154, %151
%163 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%164 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%165 = getelementptr inbounds i8, i8* %164, i64 8
%166 = call i32 @strncpy(i8* %163, i8* %165, i32 8)
%167 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%168 = call i64 @strtoul(i8* %167, i8** null, i32 16)
store i64 %168, i64* %23
%169 = load i64, i64* %23
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.13, i64 0, i64 0), i64 %169)
%171 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
%172 = load i32, i32* %32
%173 = icmp ne i32 %172, 0
br i1 %173, label %181, label %174
174: ; preds = %162
%175 = call signext i8 (...) @getchar()
store i8 %175, i8* %11
%176 = load i8, i8* %11
%177 = sext i8 %176 to i32
%178 = icmp eq i32 %177, 121
br i1 %178, label %179, label %180
179: ; preds = %174
store i32 1, i32* %32
br label %180
180: ; preds = %179, %174
br label %181
181: ; preds = %180, %162
store i32 4096, i32* %12
%182 = load i64, i64* %23
%183 = and i64 %182, 4095
store i64 %183, i64* %25
%184 = load i64, i64* %23
%185 = and i64 %184, 4294963200
store i64 %185, i64* %23
%186 = load i32, i32* %12
%187 = load i32, i32* @PROT_READ
%188 = load i32, i32* @PROT_WRITE
%189 = or i32 %187, %188
%190 = load i32, i32* @MAP_SHARED
%191 = load i32, i32* %17
%192 = load i64, i64* %23
%193 = trunc i64 %192 to i32
%194 = call i64 @mmap(i32* null, i32 %186, i32 %189, i32 %190, i32 %191, i32 %193)
store i64 %194, i64* %22
%195 = load i64, i64* %22
%196 = load i64, i64* @MAP_FAILED
%197 = icmp eq i64 %195, %196
br i1 %197, label %198, label %200
198: ; preds = %181
%199 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.15, i64 0, i64 0))
store i32 -3, i32* %3
br label %353
200: ; preds = %181
%201 = load i64, i64* %25
%202 = load i64, i64* %22
%203 = or i64 %202, %201
store i64 %203, i64* %22
%204 = load i64, i64* %22
%205 = inttoptr i64 %204 to i64*
store i64* %205, i64** %24
%206 = load i64, i64* %25
%207 = load i64, i64* %23
%208 = or i64 %207, %206
store i64 %208, i64* %23
store i32 1, i32* %19
br label %267
209: ; preds = %144
store i32 0, i32* %15
store i32 0, i32* %13
br label %210
210: ; preds = %263, %209
%211 = load i32, i32* %13
%212 = icmp slt i32 %211, 4
br i1 %212, label %213, label %266
213: ; preds = %210
store i32 0, i32* %14
br label %214
214: ; preds = %233, %213
%215 = load i32, i32* %14
%216 = icmp slt i32 %215, 4
br i1 %216, label %217, label %236
217: ; preds = %214
%218 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%219 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%220 = load i32, i32* %15
%221 = sext i32 %220 to i64
%222 = getelementptr inbounds i8, i8* %219, i64 %221
%223 = call i32 @strncpy(i8* %218, i8* %222, i32 2)
%224 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%225 = call i64 @strtol(i8* %224, i32* null, i32 16)
store i64 %225, i64* %20
%226 = load i32, i32* %15
%227 = add nsw i32 %226, 3
store i32 %227, i32* %15
%228 = load i64, i64* %20
%229 = trunc i64 %228 to i32
%230 = load i32, i32* %14
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 %231
store i32 %229, i32* %232
br label %233
233: ; preds = %217
%234 = load i32, i32* %14
%235 = add nsw i32 %234, 1
store i32 %235, i32* %14
br label %214
236: ; preds = %214
%237 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%238 = load i32, i32* %237
%239 = shl i32 %238, 0
%240 = sext i32 %239 to i64
store i64 %240, i64* %21
%241 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 1
%242 = load i32, i32* %241
%243 = shl i32 %242, 8
%244 = sext i32 %243 to i64
%245 = load i64, i64* %21
%246 = add i64 %245, %244
store i64 %246, i64* %21
%247 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 2
%248 = load i32, i32* %247
%249 = shl i32 %248, 16
%250 = sext i32 %249 to i64
%251 = load i64, i64* %21
%252 = add i64 %251, %250
store i64 %252, i64* %21
%253 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 3
%254 = load i32, i32* %253
%255 = shl i32 %254, 24
%256 = sext i32 %255 to i64
%257 = load i64, i64* %21
%258 = add i64 %257, %256
store i64 %258, i64* %21
%259 = load i64, i64* %21
%260 = load i64*, i64** %24
store i64 %259, i64* %260
%261 = load i64*, i64** %24
%262 = getelementptr inbounds i64, i64* %261, i32 1
store i64* %262, i64** %24
store i64 0, i64* %21
br label %263
263: ; preds = %236
%264 = load i32, i32* %13
%265 = add nsw i32 %264, 1
store i32 %265, i32* %13
br label %210
266: ; preds = %210
br label %267
267: ; preds = %266, %200
br label %138
268: ; preds = %138
br label %269
269: ; preds = %268
%270 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0))
%271 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.17, i64 0, i64 0))
store i64 4276092928, i64* %23
store i64 768, i64* %27
store i64 784, i64* %28
%272 = load i64, i64* %23
%273 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.18, i64 0, i64 0), i64 %272)
%274 = load i32, i32* %12
%275 = load i32, i32* @PROT_READ
%276 = load i32, i32* @PROT_WRITE
%277 = or i32 %275, %276
%278 = load i32, i32* @MAP_SHARED
%279 = load i32, i32* %17
%280 = load i64, i64* %23
%281 = trunc i64 %280 to i32
%282 = call i64 @mmap(i32* null, i32 %274, i32 %277, i32 %278, i32 %279, i32 %281)
store i64 %282, i64* %22
%283 = load i64, i64* %22
%284 = load i64, i64* @MAP_FAILED
%285 = icmp eq i64 %283, %284
br i1 %285, label %286, label %288
286: ; preds = %269
%287 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.15, i64 0, i64 0))
store i32 -3, i32* %3
br label %353
288: ; preds = %269
%289 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.19, i64 0, i64 0))
%290 = call signext i8 (...) @getchar()
store i8 %290, i8* %11
%291 = load i64, i64* %22
store i64 %291, i64* %26
%292 = load i64, i64* %28
%293 = load i64, i64* %26
%294 = or i64 %293, %292
store i64 %294, i64* %26
%295 = load i64, i64* %26
%296 = inttoptr i64 %295 to i64*
store i64* %296, i64** %24
%297 = load i64, i64* %30
%298 = shl i64 %297, 24
%299 = load i64*, i64** %24
store i64 %298, i64* %299
%300 = load i64, i64* %22
store i64 %300, i64* %26
%301 = load i64, i64* %27
%302 = load i64, i64* %26
%303 = or i64 %302, %301
store i64 %303, i64* %26
%304 = load i64, i64* %26
%305 = inttoptr i64 %304 to i64*
store i64* %305, i64** %24
%306 = load i64*, i64** %24
store i64 17664, i64* %306
%307 = call i32 @usleep(i32 10000)
store i32 %307, i32* %18
%308 = load i64, i64* %22
store i64 %308, i64* %26
%309 = load i64, i64* %28
%310 = load i64, i64* %26
%311 = or i64 %310, %309
store i64 %311, i64* %26
%312 = load i64, i64* %26
%313 = inttoptr i64 %312 to i64*
store i64* %313, i64** %24
%314 = load i64, i64* %30
%315 = shl i64 %314, 24
%316 = load i64*, i64** %24
store i64 %315, i64* %316
%317 = load i64, i64* %22
store i64 %317, i64* %26
%318 = load i64, i64* %27
%319 = load i64, i64* %26
%320 = or i64 %319, %318
store i64 %320, i64* %26
%321 = load i64, i64* %26
%322 = inttoptr i64 %321 to i64*
store i64* %322, i64** %24
%323 = load i64, i64* %31
%324 = or i64 17920, %323
%325 = load i64*, i64** %24
store i64 %324, i64* %325
%326 = call i32 @usleep(i32 500)
store i32 %326, i32* %18
%327 = load i64, i64* %22
store i64 %327, i64* %26
%328 = load i64, i64* %28
%329 = load i64, i64* %26
%330 = or i64 %329, %328
store i64 %330, i64* %26
%331 = load i64, i64* %26
%332 = inttoptr i64 %331 to i64*
store i64* %332, i64** %24
%333 = load i64, i64* %30
%334 = shl i64 %333, 24
%335 = load i64*, i64** %24
store i64 %334, i64* %335
%336 = load i64, i64* %22
store i64 %336, i64* %26
%337 = load i64, i64* %27
%338 = load i64, i64* %26
%339 = or i64 %338, %337
store i64 %339, i64* %26
%340 = load i64, i64* %26
%341 = inttoptr i64 %340 to i64*
store i64* %341, i64** %24
%342 = load i64, i64* %31
%343 = or i64 17920, %342
%344 = load i64*, i64** %24
store i64 %343, i64* %344
%345 = call i32 @usleep(i32 500)
store i32 %345, i32* %18
%346 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.20, i64 0, i64 0))
%347 = load i64, i64* %22
%348 = and i64 %347, 4294963200
store i64 %348, i64* %22
%349 = load i64, i64* %22
%350 = inttoptr i64 %349 to i8*
%351 = load i32, i32* %12
%352 = call i32 @munmap(i8* %350, i32 %351)
store i32 0, i32* %3
br label %353
353: ; preds = %288, %286, %198, %135, %127
%354 = load i32, i32* %3
ret i32 %354
}

LLVM IR (-O2):
@.str = [49 x i8] c"Usage:%s <file.bin> <0xAPID> <0xboot code addr>\0A\00"
@.str.1 = [46 x i8] c"Filename needs to be less than %d chars long\0A\00"
@errno = global i64 0
@.str.2 = [10 x i8] c"argv2:%s\0A\00"
@.str.3 = [54 x i8] c"APID:%lu incorrect! You should choose between 1 to 8\0A\00"
@.str.4 = [10 x i8] c"argv3:%s\0A\00"
@.str.5 = [53 x i8] c"boot code addr:%lu incorrect! You should use < 0xFF\0A\00"
@.str.6 = [42 x i8] c"Filename:%s\09APID:0x%08x\09Boot Addr:0x%02x\0A\00"
@.str.8 = [9 x i8] c"/dev/mem\00"
@O_RDWR = global i32 0
@.str.9 = [2 x i8] c"r\00"
@.str.11 = [8 x i8] c"/origin\00"
@.str.13 = [57 x i8] c"Press key to start writing for this origin address 0x%x\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i64 0
@.str.15 = [51 x i8] c"Mapping memory for absolute memory access failed.\0A\00"
@.str.18 = [35 x i8] c"Assuming APIC physical base: %lx \0A\00"
@str = [12 x i8] c"End of File\00"
@str.21 = [59 x i8] c"Opcodes loaded in memory, ready to send INIT/SIPI sequence\00"
@str.22 = [42 x i8] c"Hit enter for INIT / SIPI / SIPI sequence\00"
@str.23 = [25 x i8] c"Unmapping APIC Base page\00"
@str.24 = [30 x i8] c"Press y to auto load all data\00"
@str.25 = [21 x i8] c"Unmapping 'old' page\00"
@str.26 = [15 x i8] c"File not found\00"
@str.27 = [46 x i8] c"Cannot get I/O permissions (being root helps)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
%7 = alloca [80 x i8]
%8 = alloca i8*
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%14 = icmp eq i32 %0, 4
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i8*, i8** %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 80
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 80)
%26 = tail call i32 @exit(i32 -2)
unreachable
27: ; preds = %19
%28 = bitcast i8** %8 to i8*
store i64 0, i64* @errno
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @strtoul(i8* %30, i8** %8, i32 10)
%32 = load i64, i64* @errno
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %27
%35 = load i8*, i8** %8
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i8*, i8** %29
%40 = icmp eq i8* %35, %39
%41 = icmp ugt i64 %31, 8
%42 = select i1 %40, i1 true, i1 %41
%43 = icmp eq i64 %31, 0
%44 = select i1 %42, i1 true, i1 %43
br i1 %44, label %45, label %50
45: ; preds = %38, %34, %27
%46 = load i8*, i8** %29
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %46)
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i64 %31)
%49 = tail call i32 @exit(i32 -3)
unreachable
50: ; preds = %38
store i64 0, i64* @errno
%51 = getelementptr inbounds i8*, i8** %1, i64 3
%52 = load i8*, i8** %51
%53 = call i64 @strtoul(i8* %52, i8** %8, i32 16)
%54 = load i64, i64* @errno
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %65
56: ; preds = %50
%57 = load i8*, i8** %8
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i8*, i8** %51
%62 = icmp eq i8* %57, %61
%63 = icmp ugt i64 %53, 255
%64 = select i1 %62, i1 true, i1 %63
br i1 %64, label %65, label %70
65: ; preds = %60, %56, %50
%66 = load i8*, i8** %29
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%68 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.5, i64 0, i64 0), i64 %53)
%69 = tail call i32 @exit(i32 -4)
unreachable
70: ; preds = %60
%71 = load i8*, i8** %20
%72 = call i32 @strncpy(i8* %13, i8* %71, i32 80)
%73 = shl nuw nsw i64 %31, 24
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %13, i64 %73, i64 %53)
%75 = call i64 @iopl(i32 3)
%76 = icmp eq i64 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %70
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.27, i64 0, i64 0))
br label %205
79: ; preds = %70
%80 = load i32, i32* @O_RDWR
%81 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %80)
%82 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%83 = icmp eq i32* %82, null
br i1 %83, label %89, label %84
84: ; preds = %79
%85 = call i32* @fgets(i8* %9, i32 100, i32* %82)
%86 = icmp eq i32* %85, null
br i1 %86, label %177, label %87
87: ; preds = %84
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 8
br label %91
89: ; preds = %79
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.26, i64 0, i64 0))
br label %205
91: ; preds = %87, %170
%92 = phi i32 [ 0, %87 ], [ %174, %170 ]
%93 = phi i64* [ undef, %87 ], [ %173, %170 ]
%94 = phi i64 [ undef, %87 ], [ %172, %170 ]
%95 = phi i32 [ 0, %87 ], [ %171, %170 ]
%96 = call i32 @strncpy(i8* %11, i8* %9, i32 7)
%97 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0), i32 7)
%98 = icmp eq i64 %97, 0
br i1 %98, label %99, label %133
99: ; preds = %91
%100 = icmp eq i32 %95, 1
br i1 %100, label %101, label %106
101: ; preds = %99
%102 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.25, i64 0, i64 0))
%103 = and i64 %94, 4294963200
%104 = inttoptr i64 %103 to i8*
%105 = call i32 @munmap(i8* %104, i32 4096)
br label %106
106: ; preds = %101, %99
%107 = call i32 @strncpy(i8* %10, i8* %88, i32 8)
%108 = call i64 @strtoul(i8* nocapture %10, i8** null, i32 16)
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.13, i64 0, i64 0), i64 %108)
%110 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.24, i64 0, i64 0))
%111 = icmp eq i32 %92, 0
br i1 %111, label %112, label %116
112: ; preds = %106
%113 = call signext i8 (...) @getchar()
%114 = icmp eq i8 %113, 121
%115 = zext i1 %114 to i32
br label %116
116: ; preds = %112, %106
%117 = phi i32 [ 1, %106 ], [ %115, %112 ]
%118 = load i32, i32* @PROT_READ
%119 = load i32, i32* @PROT_WRITE
%120 = or i32 %119, %118
%121 = load i32, i32* @MAP_SHARED
%122 = trunc i64 %108 to i32
%123 = and i32 %122, -4096
%124 = call i64 @mmap(i32* null, i32 4096, i32 %120, i32 %121, i32 %81, i32 %123)
%125 = load i64, i64* @MAP_FAILED
%126 = icmp eq i64 %124, %125
br i1 %126, label %127, label %129
127: ; preds = %116
%128 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.15, i64 0, i64 0))
br label %205
129: ; preds = %116
%130 = and i64 %108, 4095
%131 = or i64 %124, %130
%132 = inttoptr i64 %131 to i64*
br label %170
133: ; preds = %91, %133
%134 = phi i64 [ %155, %133 ], [ 0, %91 ]
%135 = phi i32 [ %168, %133 ], [ 0, %91 ]
%136 = phi i64* [ %167, %133 ], [ %93, %91 ]
%137 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %134
%138 = call i32 @strncpy(i8* %12, i8* %137, i32 2)
%139 = call i64 @strtol(i8* nocapture %12, i32* null, i32 16)
%140 = or i64 %134, 3
%141 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %140
%142 = call i32 @strncpy(i8* %12, i8* %141, i32 2)
%143 = call i64 @strtol(i8* nocapture %12, i32* null, i32 16)
%144 = add nuw i64 %134, 6
%145 = trunc i64 %143 to i32
%146 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %144
%147 = call i32 @strncpy(i8* %12, i8* %146, i32 2)
%148 = call i64 @strtol(i8* nocapture %12, i32* null, i32 16)
%149 = add nuw i64 %134, 9
%150 = trunc i64 %148 to i32
%151 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %149
%152 = call i32 @strncpy(i8* %12, i8* %151, i32 2)
%153 = call i64 @strtol(i8* nocapture %12, i32* null, i32 16)
%154 = trunc i64 %153 to i32
%155 = add nuw nsw i64 %134, 12
%156 = shl i64 %139, 32
%157 = ashr exact i64 %156, 32
%158 = shl i32 %145, 8
%159 = sext i32 %158 to i64
%160 = add nsw i64 %157, %159
%161 = shl i32 %150, 16
%162 = sext i32 %161 to i64
%163 = add nsw i64 %160, %162
%164 = shl i32 %154, 24
%165 = sext i32 %164 to i64
%166 = add nsw i64 %163, %165
store i64 %166, i64* %136
%167 = getelementptr inbounds i64, i64* %136, i64 1
%168 = add nuw nsw i32 %135, 1
%169 = icmp eq i32 %168, 4
br i1 %169, label %170, label %133
170: ; preds = %133, %129
%171 = phi i32 [ 1, %129 ], [ %95, %133 ]
%172 = phi i64 [ %131, %129 ], [ %94, %133 ]
%173 = phi i64* [ %132, %129 ], [ %167, %133 ]
%174 = phi i32 [ %117, %129 ], [ %92, %133 ]
%175 = call i32* @fgets(i8* %9, i32 100, i32* %82)
%176 = icmp eq i32* %175, null
br i1 %176, label %177, label %91
177: ; preds = %170, %84
%178 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%179 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.21, i64 0, i64 0))
%180 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.18, i64 0, i64 0), i64 4276092928)
%181 = load i32, i32* @PROT_READ
%182 = load i32, i32* @PROT_WRITE
%183 = or i32 %182, %181
%184 = load i32, i32* @MAP_SHARED
%185 = call i64 @mmap(i32* null, i32 4096, i32 %183, i32 %184, i32 %81, i32 -18874368)
%186 = load i64, i64* @MAP_FAILED
%187 = icmp eq i64 %185, %186
br i1 %187, label %188, label %190
188: ; preds = %177
%189 = call i32 @perror(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.15, i64 0, i64 0))
br label %205
190: ; preds = %177
%191 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.22, i64 0, i64 0))
%192 = call signext i8 (...) @getchar()
%193 = or i64 %185, 784
%194 = inttoptr i64 %193 to i64*
store i64 %73, i64* %194
%195 = or i64 %185, 768
%196 = inttoptr i64 %195 to i64*
store i64 17664, i64* %196
%197 = call i32 @usleep(i32 10000)
store i64 %73, i64* %194
%198 = or i64 %53, 17920
store i64 %198, i64* %196
%199 = call i32 @usleep(i32 500)
store i64 %73, i64* %194
store i64 %198, i64* %196
%200 = call i32 @usleep(i32 500)
%201 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.23, i64 0, i64 0))
%202 = and i64 %185, 4294963200
%203 = inttoptr i64 %202 to i8*
%204 = call i32 @munmap(i8* %203, i32 4096)
br label %205
205: ; preds = %190, %188, %127, %89, %77
%206 = phi i32 [ -1, %77 ], [ -1, %89 ], [ -3, %127 ], [ -3, %188 ], [ 0, %190 ]
ret i32 %206
}