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

/* Forward declarations */

/* Type definitions */
struct utsname {
  int dummy;
};

/* Variables and functions */
struct utsname *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ PROT_WRITE;
int /*<<< orphan*/ exit(int);
struct utsname *mmap(int /*<<< orphan*/ *, int, int /*<<< orphan*/,
                     int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(struct utsname *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ uname(struct utsname *);
int main(int argc, char *argv[]) {
  int fd;
  struct utsname *buf;
  if ((fd = open("/mnt/fabric_emulation", O_RDWR)) == -1) {
    perror("open failed");
    exit(1);
  }
  if ((buf = mmap(NULL, 256, PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
    perror("mmap failed");
    exit(1);
  }
  uname(buf);
  munmap(buf, 256);
  printf("On the VM host, examine /dev/shm/fabric_emulation\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11bd <main+0x4d>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    0x2e23(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x100,%esi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x20(%rbp)
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
jne    120e <main+0x9e>
lea    0xe23(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <uname@plt>
mov    -0x20(%rbp),%rdi
mov    $0x100,%esi
call   1060 <munmap@plt>
lea    0xe02(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    0xe7f(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
jne    1194 <main+0x24>
lea    0xe84(%rip),%rdi
jmp    11ce <main+0x5e>
mov    0x2e35(%rip),%rcx
mov    (%rcx),%edx
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    $0x100,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2e06(%rip),%rax
cmp    (%rax),%rbx
jne    11dd <main+0x6d>
lea    0xe54(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    %rbx,%rdi
call   1050 <uname@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
call   1060 <munmap@plt>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [22 x i8] c"/mnt/fabric_emulation\00"
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"open failed\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global %struct.utsname* null
@.str.2 = [12 x i8] c"mmap failed\00"
@.str.3 = [51 x i8] c"On the VM host, examine /dev/shm/fabric_emulation\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.utsname*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @PROT_WRITE
%16 = load i32, i32* @MAP_SHARED
%17 = load i32, i32* %6
%18 = call %struct.utsname* @mmap(i32* null, i32 256, i32 %15, i32 %16, i32 %17, i32 0)
store %struct.utsname* %18, %struct.utsname** %7
%19 = load %struct.utsname*, %struct.utsname** @MAP_FAILED
%20 = icmp eq %struct.utsname* %18, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load %struct.utsname*, %struct.utsname** %7
%26 = call i32 @uname(%struct.utsname* %25)
%27 = load %struct.utsname*, %struct.utsname** %7
%28 = call i32 @munmap(%struct.utsname* %27, i32 256)
%29 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [22 x i8] c"/mnt/fabric_emulation\00"
@O_RDWR = global i32 0
@.str.1 = [12 x i8] c"open failed\00"
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global %struct.utsname* null
@.str.2 = [12 x i8] c"mmap failed\00"
@str = [50 x i8] c"On the VM host, examine /dev/shm/fabric_emulation\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = load i32, i32* @PROT_WRITE
%11 = load i32, i32* @MAP_SHARED
%12 = tail call %struct.utsname* @mmap(i32* null, i32 256, i32 %10, i32 %11, i32 %4, i32 0)
%13 = load %struct.utsname*, %struct.utsname** @MAP_FAILED
%14 = icmp eq %struct.utsname* %12, %13
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %9
%19 = tail call i32 @uname(%struct.utsname* %12)
%20 = tail call i32 @munmap(%struct.utsname* %12, i32 256)
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 0)
unreachable
}