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

/* Forward declarations */
typedef struct TYPE_8__ TYPE_4__;
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint64_t;
struct TYPE_5__ {
  scalar_t__ selector;
  scalar_t__ base;
};
struct kvm_userspace_memory_region {
  int guest_phys_addr;
  int memory_size;
  int rip;
  int rax;
  int rbx;
  int rflags;
  TYPE_1__ cs;
  int /*<<< orphan*/ userspace_addr;
  int /*<<< orphan*/ slot;
};
struct kvm_sregs {
  int guest_phys_addr;
  int memory_size;
  int rip;
  int rax;
  int rbx;
  int rflags;
  TYPE_1__ cs;
  int /*<<< orphan*/ userspace_addr;
  int /*<<< orphan*/ slot;
};
struct TYPE_8__ {
  unsigned long long suberror;
};
struct TYPE_7__ {
  scalar_t__ hardware_entry_failure_reason;
};
struct TYPE_6__ {
  int size;
  int port;
  int count;
  int /*<<< orphan*/ data_offset;
  int /*<<< orphan*/ direction;
};
struct kvm_run {
  int exit_reason;
  TYPE_4__ internal;
  TYPE_3__ fail_entry;
  TYPE_2__ io;
};
struct kvm_regs {
  int guest_phys_addr;
  int memory_size;
  int rip;
  int rax;
  int rbx;
  int rflags;
  TYPE_1__ cs;
  int /*<<< orphan*/ userspace_addr;
  int /*<<< orphan*/ slot;
};
typedef int /*<<< orphan*/ code;

/* Variables and functions */
int /*<<< orphan*/ KVM_CREATE_VCPU;
int /*<<< orphan*/ KVM_CREATE_VM;
#define KVM_EXIT_FAIL_ENTRY 131
#define KVM_EXIT_HLT 130
#define KVM_EXIT_INTERNAL_ERROR 129
#define KVM_EXIT_IO 128
int /*<<< orphan*/ KVM_EXIT_IO_OUT;
int /*<<< orphan*/ KVM_GET_API_VERSION;
int /*<<< orphan*/ KVM_GET_SREGS;
int /*<<< orphan*/ KVM_GET_VCPU_MMAP_SIZE;
int /*<<< orphan*/ KVM_RUN;
int /*<<< orphan*/ KVM_SET_REGS;
int /*<<< orphan*/ KVM_SET_USER_MEMORY_REGION;
int MAP_ANONYMOUS;
int MAP_SHARED;
int O_CLOEXEC;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, ...);
void *ioctl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ memcpy(int *, int const *, int);
void *mmap(int /*<<< orphan*/ *, size_t, int, int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int main() {
  const uint8_t code[] = {
      0xba, 0xf8, 0x03, 0x00, 0xd8, 0x04, '0', 0xee, 0xb0, '\n', 0xee, 0xf4,
  };
  int kvm, vmfd, vcpufd, ret;
  uint8_t *mem;
  struct kvm_sregs sregs;
  struct kvm_run *run;
  size_t mmap_size;
  kvm = open("/dev/kvm", O_RDWR | O_CLOEXEC);
  if (kvm == -1)
    err(1, "/dev/kvm");
  ret = ioctl(kvm, KVM_GET_API_VERSION, NULL);
  if (ret == -1)
    err(1, "KVM_GET_API_VERSION");
  if (ret != 12)
    errx(1, "KVM_GET_API_VERSION %d, expected 12", ret);
  vmfd = ioctl(kvm, KVM_CREATE_VM, (unsigned long)0);
  if (vmfd == -1)
    err(1, "KVM_CREATE_VM");
  mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS,
             -1, 0);
  if (!mem)
    err(1, "allocating guest memory");
  memcpy(mem, code, sizeof(code));
  struct kvm_userspace_memory_region region = {
      .slot = 0,
      .guest_phys_addr = 0x1000,
      .memory_size = 0x1000,
      .userspace_addr = (uint64_t)mem,
  };
  ret = ioctl(vmfd, KVM_SET_USER_MEMORY_REGION, &region);
  if (ret == -1)
    err(1, "KVM_SET_USER_MEMORY_REGION");
  vcpufd = ioctl(vmfd, KVM_CREATE_VCPU, (unsigned long)0);
  if (vcpufd == -1)
    err(1, "KVM_CREATE_VCPU");
  mmap_size = ioctl(kvm, KVM_GET_VCPU_MMAP_SIZE, NULL);
  if (mmap_size == -1)
    err(1, "KVM_GET_VCPU_MMAP_SIZE");
  if (mmap_size < sizeof(*run))
    errx(1, "KVM_GET_VCPU_MMAP_SIZE unexpectedly small");
  run = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, vcpufd, 0);
  if (!run)
    err(1, "mmap vcpu");
  ret = ioctl(vcpufd, KVM_GET_SREGS, &sregs);
  if (ret == -1)
    err(1, "KVM_GET_SREGS");
  sregs.cs.base = 0;
  sregs.cs.selector = 0;
  ret = ioctl(vcpufd, KVM_SET_REGS, &sregs);
  if (ret == -1)
    err(1, "KVM_SET_REGS");
  struct kvm_regs regs = {
      .rip = 0x1000,
      .rax = 2,
      .rbx = 2,
      .rflags = 0x2,
  };
  ret = ioctl(vcpufd, KVM_SET_REGS, &regs);
  if (ret == -1)
    err(1, "KVM_SET_REGS");
  while (1) {
    ret = ioctl(vcpufd, KVM_RUN, NULL);
    if (ret == -1)
      err(1, "KVM_RUN");
    switch (run->exit_reason) {
    case KVM_EXIT_HLT:
      puts("KVM_EXIT_HLT");
      return 0;
    case KVM_EXIT_IO:
      if (run->io.direction == KVM_EXIT_IO_OUT && run->io.size == 1 &&
          run->io.port == 0x3f8 && run->io.count == 1)
        putchar(*(((char *)run) + run->io.data_offset));
      else
        errx(1, "unhandled KVM_EXIT_IO");
      break;
    case KVM_EXIT_FAIL_ENTRY:
      errx(1, "KVM_EXIT_FAIL_ENTRY: hardware_entry_failure_reason = 0x%llx",
           (unsigned long long)run->fail_entry.hardware_entry_failure_reason);
    case KVM_EXIT_INTERNAL_ERROR:
      errx(1, "KVM_EXIT_INTERNAL_ERROR: suberror = 0x%x",
           run->internal.suberror);
    default:
      errx(1, "exit_reason = 0x%x", run->exit_reason);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe63(%rip),%rsi
mov    $0x30,%edx
call   1090 <memcpy@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2da9(%rip),%rax
or     (%rax),%esi
lea    0xe70(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    11f3 <main+0x63>
mov    $0x1,%edi
lea    0xe52(%rip),%rsi
call   10a0 <err@plt>
mov    -0x44(%rbp),%edi
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1228 <main+0x98>
mov    $0x1,%edi
lea    0xe26(%rip),%rsi
call   10a0 <err@plt>
cmpl   $0xc,-0x50(%rbp)
je     1248 <main+0xb8>
mov    -0x50(%rbp),%edx
mov    $0x1,%edi
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x44(%rbp),%edi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    127d <main+0xed>
mov    $0x1,%edi
lea    0xe09(%rip),%rsi
call   10a0 <err@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edx
mov    0x2d03(%rip),%rax
or     (%rax),%edx
mov    0x2d4a(%rip),%rax
mov    (%rax),%ecx
mov    0x2d11(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    12d8 <main+0x148>
mov    $0x1,%edi
lea    0xdbc(%rip),%rsi
call   10a0 <err@plt>
mov    -0x58(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x30,%edx
call   1090 <memcpy@plt>
lea    -0xc8(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
movl   $0x1000,-0xc8(%rbp)
movl   $0x1000,-0xc4(%rbp)
mov    -0x58(%rbp),%rax
mov    %eax,-0xa0(%rbp)
mov    -0x48(%rbp),%edi
mov    0x2c5b(%rip),%rax
mov    (%rax),%esi
lea    -0xc8(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1353 <main+0x1c3>
mov    $0x1,%edi
lea    0xd59(%rip),%rsi
call   10a0 <err@plt>
mov    -0x48(%rbp),%edi
mov    0x2c63(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    1388 <main+0x1f8>
mov    $0x1,%edi
lea    0xd3f(%rip),%rsi
call   10a0 <err@plt>
mov    -0x44(%rbp),%edi
mov    0x2c36(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0xffffffffffffffff,-0x98(%rbp)
ff
jne    13c5 <main+0x235>
mov    $0x1,%edi
lea    0xd12(%rip),%rsi
call   10a0 <err@plt>
cmpq   $0x30,-0x98(%rbp)
30
jae    13e6 <main+0x256>
mov    $0x1,%edi
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x98(%rbp),%rsi
mov    0x2c04(%rip),%rax
mov    (%rax),%edx
mov    0x2b93(%rip),%rax
or     (%rax),%edx
mov    0x2bda(%rip),%rax
mov    (%rax),%ecx
mov    -0x4c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
jne    143e <main+0x2ae>
mov    $0x1,%edi
lea    0xcda(%rip),%rsi
call   10a0 <err@plt>
mov    -0x4c(%rbp),%edi
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1476 <main+0x2e6>
mov    $0x1,%edi
lea    0xcac(%rip),%rsi
call   10a0 <err@plt>
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
mov    -0x4c(%rbp),%edi
mov    0x2b18(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    14be <main+0x32e>
mov    $0x1,%edi
lea    0xc72(%rip),%rsi
call   10a0 <err@plt>
lea    -0xf8(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
movl   $0x1000,-0xf0(%rbp)
movl   $0x2,-0xec(%rbp)
movl   $0x2,-0xe8(%rbp)
movl   $0x2,-0xe4(%rbp)
mov    -0x4c(%rbp),%edi
mov    0x2aa5(%rip),%rax
mov    (%rax),%esi
lea    -0xf8(%rbp),%rdx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    1531 <main+0x3a1>
mov    $0x1,%edi
lea    0xbff(%rip),%rsi
call   10a0 <err@plt>
jmp    1536 <main+0x3a6>
mov    -0x4c(%rbp),%edi
mov    0x2aa8(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1080 <ioctl@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    156b <main+0x3db>
mov    $0x1,%edi
lea    0xbd2(%rip),%rsi
call   10a0 <err@plt>
mov    -0x90(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x100(%rbp)
sub    $0x3,%eax
ja     167a <main+0x4ea>
mov    -0x100(%rbp),%rax
lea    0xa69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xb99(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret
mov    -0x90(%rbp),%rax
mov    0x28(%rax),%eax
mov    0x29a0(%rip),%rcx
cmp    (%rcx),%eax
jne    1626 <main+0x496>
mov    -0x90(%rbp),%rax
cmpl   $0x1,0x18(%rax)
jne    1626 <main+0x496>
mov    -0x90(%rbp),%rax
cmpl   $0x3f8,0x1c(%rax)
jne    1626 <main+0x496>
mov    -0x90(%rbp),%rax
cmpl   $0x1,0x20(%rax)
jne    1626 <main+0x496>
mov    -0x90(%rbp),%rax
mov    -0x90(%rbp),%rcx
movslq 0x24(%rcx),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <putchar@plt>
jmp    1639 <main+0x4a9>
mov    $0x1,%edi
lea    0xb1b(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
jmp    1696 <main+0x506>
mov    -0x90(%rbp),%rax
mov    0x10(%rax),%rdx
mov    $0x1,%edi
lea    0xb0e(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%edi
lea    0xb2c(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
mov    -0x90(%rbp),%rax
mov    (%rax),%edx
mov    $0x1,%edi
lea    0xb39(%rip),%rsi
mov    $0x0,%al
call   1060 <errx@plt>
jmp    1536 <main+0x3a6>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
movaps 0xea8(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe6d(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
mov    0x2e11(%rip),%rax
mov    0x2daa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe7f(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11ef <main+0x6f>
lea    0xe6b(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <ioctl@plt>
mov    %rax,%rbx
cmp    $0xc,%ebx
je     1237 <main+0xb7>
cmp    $0xffffffff,%ebx
jne    1222 <main+0xa2>
lea    0xe41(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0xe44(%rip),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <ioctl@plt>
mov    %rax,%rbp
cmp    $0xffffffff,%ebp
jne    1265 <main+0xe5>
lea    0xe36(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2d8c(%rip),%rax
mov    0x2d1d(%rip),%r13
mov    0x0(%r13),%edx
or     (%rax),%edx
mov    0x2d60(%rip),%r12
mov    0x2d29(%rip),%rax
mov    (%rax),%ecx
or     (%r12),%ecx
mov    $0x1000,%esi
xor    %edi,%edi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    12bb <main+0x13b>
lea    0xdee(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
lea    0x60(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x30,%edx
call   1080 <memcpy@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movups %xmm0,0x8(%rsp)
movq   $0x0,0x28(%rsp)
movabs $0x100000001000,%rax
mov    %rax,(%rsp)
mov    %ebx,0x28(%rsp)
mov    0x2c84(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
xor    %eax,%eax
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1320 <main+0x1a0>
lea    0xda1(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <ioctl@plt>
mov    %rax,%r14
cmp    $0xffffffff,%r14d
jne    134e <main+0x1ce>
lea    0xd8e(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2c73(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <ioctl@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
je     1387 <main+0x207>
cmp    $0x2f,%rbx
ja     1398 <main+0x218>
lea    0xd80(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <errx@plt>
jmp    1398 <main+0x218>
lea    0xd54(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x0(%r13),%edx
mov    0x2c55(%rip),%rax
or     (%rax),%edx
mov    (%r12),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r14d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13d2 <main+0x252>
lea    0xd5b(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2bbf(%rip),%rax
mov    (%rax),%esi
lea    0x98(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1403 <main+0x283>
lea    0xd34(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0xb0(%rsp)
mov    0x2b93(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0x98(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1440 <main+0x2c0>
lea    0xd05(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x50(%rsp)
movaps 0xba7(%rip),%xmm0
movups %xmm0,0x38(%rsp)
mov    0x0(%rbp),%esi
lea    0x30(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1486 <main+0x306>
lea    0xcbf(%rip),%rsi
mov    $0x1,%edi
call   1090 <err@plt>
mov    0x2b5b(%rip),%r13
lea    0xd44(%rip),%r12
lea    0xb75(%rip),%r15
lea    0xd0d(%rip),%rbp
jmp    14eb <main+0x36b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rbx),%rdx
mov    $0x1,%edi
lea    0xcb3(%rip),%rsi
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x8(%rbx),%rdx
mov    $0x1,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <errx@plt>
mov    (%rbx),%edx
mov    $0x1,%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <errx@plt>
mov    0x0(%r13),%esi
mov    %r14d,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1511 <main+0x391>
mov    $0x1,%edi
lea    0xc3c(%rip),%rsi
call   1090 <err@plt>
mov    (%rbx),%edx
lea    -0x80(%rdx),%eax
cmp    $0x3,%eax
ja     14dc <main+0x35c>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x28(%rbx),%eax
mov    0x2a3a(%rip),%rcx
cmp    (%rcx),%eax
jne    1560 <main+0x3e0>
cmpl   $0x1,0x18(%rbx)
jne    1560 <main+0x3e0>
cmpl   $0x3f8,0x1c(%rbx)
jne    1560 <main+0x3e0>
cmpl   $0x1,0x20(%rbx)
jne    1560 <main+0x3e0>
movslq 0x24(%rbx),%rax
movsbl (%rbx,%rax,1),%edi
call   1030 <putchar@plt>
jmp    14eb <main+0x36b>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
lea    0xbf1(%rip),%rsi
xor    %eax,%eax
call   1060 <errx@plt>
jmp    14eb <main+0x36b>
lea    0xbd1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kvm_sregs = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
%struct.TYPE_5__ = type { i64, i64 }
%struct.kvm_run = type { i32, %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__ }
%struct.TYPE_8__ = type { i64 }
%struct.TYPE_7__ = type { i64 }
%struct.TYPE_6__ = type { i32, i32, i32, i32, i32 }
%struct.kvm_userspace_memory_region = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
%struct.kvm_regs = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
@__const.main.code = [12 x i32] [i32 186, i32 248, i32 3, i32 0, i32 216, i32 4, i32 48, i32 238, i32 176, i32 10, i32 238, i32 244]
@.str = [9 x i8] c"/dev/kvm\00"
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@KVM_GET_API_VERSION = global i32 0
@.str.1 = [20 x i8] c"KVM_GET_API_VERSION\00"
@.str.2 = [36 x i8] c"KVM_GET_API_VERSION %d, expected 12\00"
@KVM_CREATE_VM = global i32 0
@.str.3 = [14 x i8] c"KVM_CREATE_VM\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.4 = [24 x i8] c"allocating guest memory\00"
@KVM_SET_USER_MEMORY_REGION = global i32 0
@.str.5 = [27 x i8] c"KVM_SET_USER_MEMORY_REGION\00"
@KVM_CREATE_VCPU = global i32 0
@.str.6 = [16 x i8] c"KVM_CREATE_VCPU\00"
@KVM_GET_VCPU_MMAP_SIZE = global i32 0
@.str.7 = [23 x i8] c"KVM_GET_VCPU_MMAP_SIZE\00"
@.str.8 = [42 x i8] c"KVM_GET_VCPU_MMAP_SIZE unexpectedly small\00"
@.str.9 = [10 x i8] c"mmap vcpu\00"
@KVM_GET_SREGS = global i32 0
@.str.10 = [14 x i8] c"KVM_GET_SREGS\00"
@KVM_SET_REGS = global i32 0
@.str.11 = [13 x i8] c"KVM_SET_REGS\00"
@KVM_RUN = global i32 0
@.str.12 = [8 x i8] c"KVM_RUN\00"
@.str.13 = [13 x i8] c"KVM_EXIT_HLT\00"
@KVM_EXIT_IO_OUT = global i32 0
@.str.14 = [22 x i8] c"unhandled KVM_EXIT_IO\00"
@.str.15 = [60 x i8] c"KVM_EXIT_FAIL_ENTRY: hardware_entry_failure_reason = 0x%llx\00"
@.str.16 = [41 x i8] c"KVM_EXIT_INTERNAL_ERROR: suberror = 0x%x\00"
@.str.17 = [19 x i8] c"exit_reason = 0x%x\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.kvm_sregs
%9 = alloca %struct.kvm_run*
%10 = alloca i64
%11 = alloca %struct.kvm_userspace_memory_region
%12 = alloca %struct.kvm_regs
store i32 0, i32* %1
%13 = bitcast [12 x i32]* %2 to i8*
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CLOEXEC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %0
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %0
%23 = load i32, i32* %3
%24 = load i32, i32* @KVM_GET_API_VERSION
%25 = call i8* (i32, i32, ...) @ioctl(i32 %23, i32 %24, i8* null)
%26 = ptrtoint i8* %25 to i32
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 12
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %6
%36 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %3
%39 = load i32, i32* @KVM_CREATE_VM
%40 = call i8* (i32, i32, ...) @ioctl(i32 %38, i32 %39, i64 0)
%41 = ptrtoint i8* %40 to i32
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %37
%47 = load i32, i32* @PROT_READ
%48 = load i32, i32* @PROT_WRITE
%49 = or i32 %47, %48
%50 = load i32, i32* @MAP_SHARED
%51 = load i32, i32* @MAP_ANONYMOUS
%52 = or i32 %50, %51
%53 = call i8* @mmap(i32* null, i64 4096, i32 %49, i32 %52, i32 -1, i32 0)
%54 = bitcast i8* %53 to i32*
store i32* %54, i32** %7
%55 = load i32*, i32** %7
%56 = icmp ne i32* %55, null
br i1 %56, label %59, label %57
57: ; preds = %46
%58 = call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %57, %46
%60 = load i32*, i32** %7
%61 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 0
%62 = call i32 @memcpy(i32* %60, i32* %61, i32 48)
%63 = bitcast %struct.kvm_userspace_memory_region* %11 to i8*
%64 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %11, i32 0, i32 0
store i32 4096, i32* %64
%65 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %11, i32 0, i32 1
store i32 4096, i32* %65
%66 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %11, i32 0, i32 7
%67 = load i32*, i32** %7
%68 = ptrtoint i32* %67 to i32
store i32 %68, i32* %66
%69 = load i32, i32* %4
%70 = load i32, i32* @KVM_SET_USER_MEMORY_REGION
%71 = call i8* (i32, i32, ...) @ioctl(i32 %69, i32 %70, %struct.kvm_userspace_memory_region* %11)
%72 = ptrtoint i8* %71 to i32
store i32 %72, i32* %6
%73 = load i32, i32* %6
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %77
75: ; preds = %59
%76 = call i32 @err(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %77
77: ; preds = %75, %59
%78 = load i32, i32* %4
%79 = load i32, i32* @KVM_CREATE_VCPU
%80 = call i8* (i32, i32, ...) @ioctl(i32 %78, i32 %79, i64 0)
%81 = ptrtoint i8* %80 to i32
store i32 %81, i32* %5
%82 = load i32, i32* %5
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %77
%85 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %86
86: ; preds = %84, %77
%87 = load i32, i32* %3
%88 = load i32, i32* @KVM_GET_VCPU_MMAP_SIZE
%89 = call i8* (i32, i32, ...) @ioctl(i32 %87, i32 %88, i8* null)
%90 = ptrtoint i8* %89 to i64
store i64 %90, i64* %10
%91 = load i64, i64* %10
%92 = icmp eq i64 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %86
%94 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %95
95: ; preds = %93, %86
%96 = load i64, i64* %10
%97 = icmp ult i64 %96, 48
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
br label %100
100: ; preds = %98, %95
%101 = load i64, i64* %10
%102 = load i32, i32* @PROT_READ
%103 = load i32, i32* @PROT_WRITE
%104 = or i32 %102, %103
%105 = load i32, i32* @MAP_SHARED
%106 = load i32, i32* %5
%107 = call i8* @mmap(i32* null, i64 %101, i32 %104, i32 %105, i32 %106, i32 0)
%108 = bitcast i8* %107 to %struct.kvm_run*
store %struct.kvm_run* %108, %struct.kvm_run** %9
%109 = load %struct.kvm_run*, %struct.kvm_run** %9
%110 = icmp ne %struct.kvm_run* %109, null
br i1 %110, label %113, label %111
111: ; preds = %100
%112 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
br label %113
113: ; preds = %111, %100
%114 = load i32, i32* %5
%115 = load i32, i32* @KVM_GET_SREGS
%116 = call i8* (i32, i32, ...) @ioctl(i32 %114, i32 %115, %struct.kvm_sregs* %8)
%117 = ptrtoint i8* %116 to i32
store i32 %117, i32* %6
%118 = load i32, i32* %6
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %122
120: ; preds = %113
%121 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %122
122: ; preds = %120, %113
%123 = getelementptr inbounds %struct.kvm_sregs, %struct.kvm_sregs* %8, i32 0, i32 6
%124 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %123, i32 0, i32 1
store i64 0, i64* %124
%125 = getelementptr inbounds %struct.kvm_sregs, %struct.kvm_sregs* %8, i32 0, i32 6
%126 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %125, i32 0, i32 0
store i64 0, i64* %126
%127 = load i32, i32* %5
%128 = load i32, i32* @KVM_SET_REGS
%129 = call i8* (i32, i32, ...) @ioctl(i32 %127, i32 %128, %struct.kvm_sregs* %8)
%130 = ptrtoint i8* %129 to i32
store i32 %130, i32* %6
%131 = load i32, i32* %6
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %135
133: ; preds = %122
%134 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %135
135: ; preds = %133, %122
%136 = bitcast %struct.kvm_regs* %12 to i8*
%137 = bitcast i8* %136 to %struct.kvm_regs*
%138 = getelementptr inbounds %struct.kvm_regs, %struct.kvm_regs* %137, i32 0, i32 2
store i32 4096, i32* %138
%139 = getelementptr inbounds %struct.kvm_regs, %struct.kvm_regs* %137, i32 0, i32 3
store i32 2, i32* %139
%140 = getelementptr inbounds %struct.kvm_regs, %struct.kvm_regs* %137, i32 0, i32 4
store i32 2, i32* %140
%141 = getelementptr inbounds %struct.kvm_regs, %struct.kvm_regs* %137, i32 0, i32 5
store i32 2, i32* %141
%142 = load i32, i32* %5
%143 = load i32, i32* @KVM_SET_REGS
%144 = call i8* (i32, i32, ...) @ioctl(i32 %142, i32 %143, %struct.kvm_regs* %12)
%145 = ptrtoint i8* %144 to i32
store i32 %145, i32* %6
%146 = load i32, i32* %6
%147 = icmp eq i32 %146, -1
br i1 %147, label %148, label %150
148: ; preds = %135
%149 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %150
150: ; preds = %148, %135
br label %151
151: ; preds = %150, %222
%152 = load i32, i32* %5
%153 = load i32, i32* @KVM_RUN
%154 = call i8* (i32, i32, ...) @ioctl(i32 %152, i32 %153, i8* null)
%155 = ptrtoint i8* %154 to i32
store i32 %155, i32* %6
%156 = load i32, i32* %6
%157 = icmp eq i32 %156, -1
br i1 %157, label %158, label %160
158: ; preds = %151
%159 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
br label %160
160: ; preds = %158, %151
%161 = load %struct.kvm_run*, %struct.kvm_run** %9
%162 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %161, i32 0, i32 0
%163 = load i32, i32* %162
switch i32 %163, label %217 [
i32 130, label %164
i32 128, label %166
i32 131, label %205
i32 129, label %211
]
164: ; preds = %160
%165 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
ret i32 0
166: ; preds = %160
%167 = load %struct.kvm_run*, %struct.kvm_run** %9
%168 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %167, i32 0, i32 3
%169 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %168, i32 0, i32 4
%170 = load i32, i32* %169
%171 = load i32, i32* @KVM_EXIT_IO_OUT
%172 = icmp eq i32 %170, %171
br i1 %172, label %173, label %202
173: ; preds = %166
%174 = load %struct.kvm_run*, %struct.kvm_run** %9
%175 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %174, i32 0, i32 3
%176 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %175, i32 0, i32 0
%177 = load i32, i32* %176
%178 = icmp eq i32 %177, 1
br i1 %178, label %179, label %202
179: ; preds = %173
%180 = load %struct.kvm_run*, %struct.kvm_run** %9
%181 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %180, i32 0, i32 3
%182 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %181, i32 0, i32 1
%183 = load i32, i32* %182
%184 = icmp eq i32 %183, 1016
br i1 %184, label %185, label %202
185: ; preds = %179
%186 = load %struct.kvm_run*, %struct.kvm_run** %9
%187 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %186, i32 0, i32 3
%188 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %187, i32 0, i32 2
%189 = load i32, i32* %188
%190 = icmp eq i32 %189, 1
br i1 %190, label %191, label %202
191: ; preds = %185
%192 = load %struct.kvm_run*, %struct.kvm_run** %9
%193 = bitcast %struct.kvm_run* %192 to i8*
%194 = load %struct.kvm_run*, %struct.kvm_run** %9
%195 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %194, i32 0, i32 3
%196 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %195, i32 0, i32 3
%197 = load i32, i32* %196
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds i8, i8* %193, i64 %198
%200 = load i8, i8* %199
%201 = call i32 @putchar(i8 signext %200)
br label %204
202: ; preds = %185, %179, %173, %166
%203 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
br label %204
204: ; preds = %202, %191
br label %222
205: ; preds = %160
%206 = load %struct.kvm_run*, %struct.kvm_run** %9
%207 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %206, i32 0, i32 2
%208 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %207, i32 0, i32 0
%209 = load i64, i64* %208
%210 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.15, i64 0, i64 0), i64 %209)
br label %211
211: ; preds = %160, %205
%212 = load %struct.kvm_run*, %struct.kvm_run** %9
%213 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %212, i32 0, i32 1
%214 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %213, i32 0, i32 0
%215 = load i64, i64* %214
%216 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i64 %215)
br label %217
217: ; preds = %160, %211
%218 = load %struct.kvm_run*, %struct.kvm_run** %9
%219 = getelementptr inbounds %struct.kvm_run, %struct.kvm_run* %218, i32 0, i32 0
%220 = load i32, i32* %219
%221 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i32 %220)
br label %222
222: ; preds = %217, %204
br label %151
}

LLVM IR (-O2):
%struct.kvm_sregs = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
%struct.TYPE_5__ = type { i64, i64 }
%struct.kvm_userspace_memory_region = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
%struct.kvm_regs = type { i32, i32, i32, i32, i32, i32, %struct.TYPE_5__, i32, i32 }
@__const.main.code = [12 x i32] [i32 186, i32 248, i32 3, i32 0, i32 216, i32 4, i32 48, i32 238, i32 176, i32 10, i32 238, i32 244]
@.str = [9 x i8] c"/dev/kvm\00"
@O_RDWR = global i32 0
@O_CLOEXEC = global i32 0
@KVM_GET_API_VERSION = global i32 0
@.str.1 = [20 x i8] c"KVM_GET_API_VERSION\00"
@.str.2 = [36 x i8] c"KVM_GET_API_VERSION %d, expected 12\00"
@KVM_CREATE_VM = global i32 0
@.str.3 = [14 x i8] c"KVM_CREATE_VM\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str.4 = [24 x i8] c"allocating guest memory\00"
@KVM_SET_USER_MEMORY_REGION = global i32 0
@.str.5 = [27 x i8] c"KVM_SET_USER_MEMORY_REGION\00"
@KVM_CREATE_VCPU = global i32 0
@.str.6 = [16 x i8] c"KVM_CREATE_VCPU\00"
@KVM_GET_VCPU_MMAP_SIZE = global i32 0
@.str.7 = [23 x i8] c"KVM_GET_VCPU_MMAP_SIZE\00"
@.str.8 = [42 x i8] c"KVM_GET_VCPU_MMAP_SIZE unexpectedly small\00"
@.str.9 = [10 x i8] c"mmap vcpu\00"
@KVM_GET_SREGS = global i32 0
@.str.10 = [14 x i8] c"KVM_GET_SREGS\00"
@KVM_SET_REGS = global i32 0
@.str.11 = [13 x i8] c"KVM_SET_REGS\00"
@KVM_RUN = global i32 0
@.str.12 = [8 x i8] c"KVM_RUN\00"
@.str.13 = [13 x i8] c"KVM_EXIT_HLT\00"
@KVM_EXIT_IO_OUT = global i32 0
@.str.14 = [22 x i8] c"unhandled KVM_EXIT_IO\00"
@.str.15 = [60 x i8] c"KVM_EXIT_FAIL_ENTRY: hardware_entry_failure_reason = 0x%llx\00"
@.str.16 = [41 x i8] c"KVM_EXIT_INTERNAL_ERROR: suberror = 0x%x\00"
@.str.17 = [19 x i8] c"exit_reason = 0x%x\00"
define i32 @main() {
%1 = alloca [12 x i32]
%2 = alloca %struct.kvm_sregs
%3 = alloca %struct.kvm_userspace_memory_region
%4 = alloca %struct.kvm_regs
%5 = bitcast [12 x i32]* %1 to i8*
%6 = bitcast %struct.kvm_sregs* %2 to i8*
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @O_CLOEXEC
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = load i32, i32* @KVM_GET_API_VERSION
%16 = tail call i8* (i32, i32, ...) @ioctl(i32 %10, i32 %15, i8* null)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
switch i32 %18, label %21 [
i32 -1, label %19
i32 12, label %23
]
19: ; preds = %14
%20 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %14
%22 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %23
23: ; preds = %14, %21
%24 = load i32, i32* @KVM_CREATE_VM
%25 = tail call i8* (i32, i32, ...) @ioctl(i32 %10, i32 %24, i64 0)
%26 = ptrtoint i8* %25 to i64
%27 = trunc i64 %26 to i32
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_SHARED
%36 = load i32, i32* @MAP_ANONYMOUS
%37 = or i32 %36, %35
%38 = tail call i8* @mmap(i32* null, i64 4096, i32 %34, i32 %37, i32 -1, i32 0)
%39 = bitcast i8* %38 to i32*
%40 = icmp eq i8* %38, null
br i1 %40, label %41, label %43
41: ; preds = %31
%42 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %31
%44 = getelementptr inbounds [12 x i32], [12 x i32]* %1, i64 0, i64 0
%45 = call i32 @memcpy(i32* %39, i32* %44, i32 48)
%46 = bitcast %struct.kvm_userspace_memory_region* %3 to i8*
%47 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %3, i64 0, i32 2
%48 = bitcast i32* %47 to i8*
%49 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %3, i64 0, i32 0
store i32 4096, i32* %49
%50 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %3, i64 0, i32 1
store i32 4096, i32* %50
%51 = getelementptr inbounds %struct.kvm_userspace_memory_region, %struct.kvm_userspace_memory_region* %3, i64 0, i32 7
%52 = ptrtoint i8* %38 to i64
%53 = trunc i64 %52 to i32
store i32 %53, i32* %51
%54 = load i32, i32* @KVM_SET_USER_MEMORY_REGION
%55 = call i8* (i32, i32, ...) @ioctl(i32 %27, i32 %54, %struct.kvm_userspace_memory_region* %3)
%56 = ptrtoint i8* %55 to i64
%57 = trunc i64 %56 to i32
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %43
%60 = call i32 @err(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %61
61: ; preds = %59, %43
%62 = load i32, i32* @KVM_CREATE_VCPU
%63 = call i8* (i32, i32, ...) @ioctl(i32 %27, i32 %62, i64 0)
%64 = ptrtoint i8* %63 to i64
%65 = trunc i64 %64 to i32
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @err(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %67, %61
%70 = load i32, i32* @KVM_GET_VCPU_MMAP_SIZE
%71 = call i8* (i32, i32, ...) @ioctl(i32 %10, i32 %70, i8* null)
%72 = ptrtoint i8* %71 to i64
%73 = icmp eq i8* %71, inttoptr (i64 -1 to i8*)
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = call i32 @err(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %80
76: ; preds = %69
%77 = icmp ult i8* %71, inttoptr (i64 48 to i8*)
br i1 %77, label %78, label %80
78: ; preds = %76
%79 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.8, i64 0, i64 0))
br label %80
80: ; preds = %74, %78, %76
%81 = load i32, i32* @PROT_READ
%82 = load i32, i32* @PROT_WRITE
%83 = or i32 %82, %81
%84 = load i32, i32* @MAP_SHARED
%85 = call i8* @mmap(i32* null, i64 %72, i32 %83, i32 %84, i32 %65, i32 0)
%86 = icmp eq i8* %85, null
br i1 %86, label %87, label %89
87: ; preds = %80
%88 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
br label %89
89: ; preds = %87, %80
%90 = load i32, i32* @KVM_GET_SREGS
%91 = call i8* (i32, i32, ...) @ioctl(i32 %65, i32 %90, %struct.kvm_sregs* %2)
%92 = ptrtoint i8* %91 to i64
%93 = trunc i64 %92 to i32
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %89
%96 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0))
br label %97
97: ; preds = %95, %89
%98 = getelementptr inbounds %struct.kvm_sregs, %struct.kvm_sregs* %2, i64 0, i32 6, i32 0
%99 = bitcast i64* %98 to i8*
%100 = load i32, i32* @KVM_SET_REGS
%101 = call i8* (i32, i32, ...) @ioctl(i32 %65, i32 %100, %struct.kvm_sregs* %2)
%102 = ptrtoint i8* %101 to i64
%103 = trunc i64 %102 to i32
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %97
%106 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %107
107: ; preds = %105, %97
%108 = bitcast %struct.kvm_regs* %4 to i8*
%109 = getelementptr inbounds %struct.kvm_regs, %struct.kvm_regs* %4, i64 0, i32 2
%110 = bitcast i32* %109 to <4 x i32>*
store <4 x i32> <i32 4096, i32 2, i32 2, i32 2>, <4 x i32>* %110
%111 = load i32, i32* @KVM_SET_REGS
%112 = call i8* (i32, i32, ...) @ioctl(i32 %65, i32 %111, %struct.kvm_regs* %4)
%113 = ptrtoint i8* %112 to i64
%114 = trunc i64 %113 to i32
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %118
116: ; preds = %107
%117 = call i32 @err(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
br label %118
118: ; preds = %116, %107
%119 = bitcast i8* %85 to i32*
%120 = getelementptr inbounds i8, i8* %85, i64 16
%121 = bitcast i8* %120 to i64*
%122 = getelementptr inbounds i8, i8* %85, i64 8
%123 = bitcast i8* %122 to i64*
%124 = getelementptr inbounds i8, i8* %85, i64 40
%125 = bitcast i8* %124 to i32*
%126 = getelementptr inbounds i8, i8* %85, i64 24
%127 = bitcast i8* %126 to i32*
%128 = getelementptr inbounds i8, i8* %85, i64 28
%129 = bitcast i8* %128 to i32*
%130 = getelementptr inbounds i8, i8* %85, i64 32
%131 = bitcast i8* %130 to i32*
%132 = getelementptr inbounds i8, i8* %85, i64 36
%133 = bitcast i8* %132 to i32*
br label %134
134: ; preds = %165, %118
%135 = load i32, i32* @KVM_RUN
%136 = call i8* (i32, i32, ...) @ioctl(i32 %65, i32 %135, i8* null)
%137 = ptrtoint i8* %136 to i64
%138 = trunc i64 %137 to i32
%139 = icmp eq i32 %138, -1
br i1 %139, label %140, label %142
140: ; preds = %134
%141 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
br label %142
142: ; preds = %140, %134
%143 = load i32, i32* %119
switch i32 %143, label %175 [
i32 130, label %144
i32 128, label %146
i32 131, label %168
i32 129, label %171
]
144: ; preds = %142
%145 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
ret i32 0
146: ; preds = %142
%147 = load i32, i32* %125
%148 = load i32, i32* @KVM_EXIT_IO_OUT
%149 = icmp eq i32 %147, %148
br i1 %149, label %150, label %166
150: ; preds = %146
%151 = load i32, i32* %127
%152 = icmp eq i32 %151, 1
br i1 %152, label %153, label %166
153: ; preds = %150
%154 = load i32, i32* %129
%155 = icmp eq i32 %154, 1016
br i1 %155, label %156, label %166
156: ; preds = %153
%157 = load i32, i32* %131
%158 = icmp eq i32 %157, 1
br i1 %158, label %159, label %166
159: ; preds = %156
%160 = load i32, i32* %133
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds i8, i8* %85, i64 %161
%163 = load i8, i8* %162
%164 = call i32 @putchar(i8 signext %163)
br label %165
165: ; preds = %159, %166, %175
br label %134
166: ; preds = %156, %153, %150, %146
%167 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
br label %165
168: ; preds = %142
%169 = load i64, i64* %121
%170 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.15, i64 0, i64 0), i64 %169)
br label %171
171: ; preds = %142, %168
%172 = load i64, i64* %123
%173 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i64 %172)
%174 = load i32, i32* %119
br label %175
175: ; preds = %142, %171
%176 = phi i32 [ %143, %142 ], [ %174, %171 ]
%177 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.17, i64 0, i64 0), i32 %176)
br label %165
}