#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 */

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int O_NONBLOCK;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int atoi(char *);
long atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int getpagesize();
int /*<<< orphan*/ ivshmem_send(void *, int /*<<< orphan*/, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ munmap(void *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int fd, length = 4 * 1024;
  void *memptr, *regptr;
  long *long_array;
  long param;
  int other;
  int i, j, k;
  int count;
  if (argc != 4) {
    printf("USAGE: server <filename> <param> <other vm>\n");
    exit(-1);
  }
  fd = open(argv[1], O_RDWR | O_NONBLOCK);
  printf("[DUMP] opening file %s\n", argv[1]);
  param = atol(argv[2]);
  other = atoi(argv[3]);
  length = (4 * 1024 * 1024);
  printf("[DUMP] size is %d\n", length);
  if ((regptr = mmap(NULL, 256, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                     0 * getpagesize())) == (void *)-1) {
    printf("mmap failed (0x%p)\n", regptr);
    close(fd);
    exit(-1);
  }
  if ((memptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd,
                     1 * getpagesize())) == (void *)-1) {
    printf("mmap failed (0x%p)\n", memptr);
    close(fd);
    exit(-1);
  }
  srand(time(NULL));
  ivshmem_send(regptr, 0, other);
  printf("[DUMP] munmap is unmapping %p\n", memptr);
  munmap(memptr, length);
  munmap(regptr, 256);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x18(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     11f8 <main+0x38>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x400000,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    0x2d47(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x58(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    $0x0,%al
call   10d0 <getpagesize@plt>
mov    -0x58(%rbp),%edx
mov    -0x54(%rbp),%ecx
mov    -0x50(%rbp),%r8d
imul   $0x0,%eax,%r9d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100,%esi
call   1030 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    12eb <main+0x12b>
mov    -0x28(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    0x2cbf(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x64(%rbp)
mov    0x2cdb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    $0x0,%al
call   10d0 <getpagesize@plt>
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
mov    -0x60(%rbp),%ecx
mov    -0x5c(%rbp),%r8d
mov    %eax,%r9d
shl    $0x0,%r9d
xor    %eax,%eax
mov    %eax,%edi
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jne    1374 <main+0x1b4>
mov    -0x20(%rbp),%rsi
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%edx
xor    %esi,%esi
call   1090 <ivshmem_send@plt>
mov    -0x20(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1080 <munmap@plt>
mov    -0x28(%rbp),%rdi
mov    $0x100,%esi
call   1080 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    132d <main+0x16d>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2df6(%rip),%rax
mov    0x2de7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,%r12d
mov    0x8(%rbx),%rsi
lea    0xe00(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,0x4(%rsp)
lea    0xdfd(%rip),%rdi
mov    $0x400000,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dca(%rip),%rax
mov    0x2d8b(%rip),%r14
mov    (%r14),%ebx
or     (%rax),%ebx
mov    0x2da7(%rip),%r15
mov    (%r15),%ebp
xor    %eax,%eax
call   10d0 <getpagesize@plt>
xor    %edi,%edi
mov    $0x100,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r12d,%r13d
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1306 <main+0x146>
mov    %rax,%r12
mov    (%r14),%ebx
mov    0x2d7d(%rip),%rax
or     (%rax),%ebx
mov    (%r15),%ebp
xor    %eax,%eax
call   10d0 <getpagesize@plt>
xor    %edi,%edi
mov    $0x400000,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
mov    %eax,%r9d
call   1040 <mmap@plt>
cmp    $0xffffffffffffffff,%rax
je     1306 <main+0x146>
mov    %rax,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    0x4(%rsp),%edx
call   10a0 <ivshmem_send@plt>
lea    0xd76(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x400000,%esi
call   1090 <munmap@plt>
mov    %r12,%rdi
mov    $0x100,%esi
call   1090 <munmap@plt>
mov    %r13d,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1e(%rip),%rdi
mov    $0xffffffffffffffff,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%edi
call   1060 <close@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
lea    0xd2a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"USAGE: server <filename> <param> <other vm>\0A\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [24 x i8] c"[DUMP] opening file %s\0A\00"
@.str.2 = [19 x i8] c"[DUMP] size is %d\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.3 = [20 x i8] c"mmap failed (0x%p)\0A\00"
@.str.4 = [31 x i8] c"[DUMP] munmap is unmapping %p\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 4096, i32* %6
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_NONBLOCK
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %24, i32 %27)
store i32 %28, i32* %5
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i64 @atol(i8* %35)
store i64 %36, i64* %10
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %11
store i32 4194304, i32* %6
%41 = load i32, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @PROT_WRITE
%45 = or i32 %43, %44
%46 = load i32, i32* @MAP_SHARED
%47 = load i32, i32* %5
%48 = call i32 (...) @getpagesize()
%49 = mul nsw i32 0, %48
%50 = call i8* @mmap(i32* null, i32 256, i32 %45, i32 %46, i32 %47, i32 %49)
store i8* %50, i8** %8
%51 = icmp eq i8* %50, inttoptr (i64 -1 to i8*)
br i1 %51, label %52, label %58
52: ; preds = %21
%53 = load i8*, i8** %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %5
%56 = call i32 @close(i32 %55)
%57 = call i32 @exit(i32 -1)
unreachable
58: ; preds = %21
%59 = load i32, i32* %6
%60 = load i32, i32* @PROT_READ
%61 = load i32, i32* @PROT_WRITE
%62 = or i32 %60, %61
%63 = load i32, i32* @MAP_SHARED
%64 = load i32, i32* %5
%65 = call i32 (...) @getpagesize()
%66 = mul nsw i32 1, %65
%67 = call i8* @mmap(i32* null, i32 %59, i32 %62, i32 %63, i32 %64, i32 %66)
store i8* %67, i8** %7
%68 = icmp eq i8* %67, inttoptr (i64 -1 to i8*)
br i1 %68, label %69, label %75
69: ; preds = %58
%70 = load i8*, i8** %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %70)
%72 = load i32, i32* %5
%73 = call i32 @close(i32 %72)
%74 = call i32 @exit(i32 -1)
unreachable
75: ; preds = %58
%76 = call i32 @time(i32* null)
%77 = call i32 @srand(i32 %76)
%78 = load i8*, i8** %8
%79 = load i32, i32* %11
%80 = call i32 @ivshmem_send(i8* %78, i32 0, i32 %79)
%81 = load i8*, i8** %7
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %81)
%83 = load i8*, i8** %7
%84 = load i32, i32* %6
%85 = call i32 @munmap(i8* %83, i32 %84)
%86 = load i8*, i8** %8
%87 = call i32 @munmap(i8* %86, i32 256)
%88 = load i32, i32* %5
%89 = call i32 @close(i32 %88)
ret i32 0
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [24 x i8] c"[DUMP] opening file %s\0A\00"
@.str.2 = [19 x i8] c"[DUMP] size is %d\0A\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@.str.3 = [20 x i8] c"mmap failed (0x%p)\0A\00"
@.str.4 = [31 x i8] c"[DUMP] munmap is unmapping %p\0A\00"
@str = [44 x i8] c"USAGE: server <filename> <param> <other vm>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 -1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_NONBLOCK
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* %9, i32 %12)
%14 = load i8*, i8** %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 4194304)
%20 = load i32, i32* @PROT_READ
%21 = load i32, i32* @PROT_WRITE
%22 = or i32 %21, %20
%23 = load i32, i32* @MAP_SHARED
%24 = tail call i32 (...) @getpagesize()
%25 = tail call i8* @mmap(i32* null, i32 256, i32 %22, i32 %23, i32 %13, i32 0)
%26 = icmp eq i8* %25, inttoptr (i64 -1 to i8*)
br i1 %26, label %27, label %31
27: ; preds = %7
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
%29 = tail call i32 @close(i32 %13)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %7
%32 = load i32, i32* @PROT_READ
%33 = load i32, i32* @PROT_WRITE
%34 = or i32 %33, %32
%35 = load i32, i32* @MAP_SHARED
%36 = tail call i32 (...) @getpagesize()
%37 = tail call i8* @mmap(i32* null, i32 4194304, i32 %34, i32 %35, i32 %13, i32 %36)
%38 = icmp eq i8* %37, inttoptr (i64 -1 to i8*)
br i1 %38, label %39, label %43
39: ; preds = %31
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* inttoptr (i64 -1 to i8*))
%41 = tail call i32 @close(i32 %13)
%42 = tail call i32 @exit(i32 -1)
unreachable
43: ; preds = %31
%44 = tail call i32 @time(i32* null)
%45 = tail call i32 @srand(i32 %44)
%46 = tail call i32 @ivshmem_send(i8* %25, i32 0, i32 %18)
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%48 = tail call i32 @munmap(i8* %37, i32 4194304)
%49 = tail call i32 @munmap(i8* %25, i32 256)
%50 = tail call i32 @close(i32 %13)
ret i32 0
}