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

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ VMFileClose(int);
int /*<<< orphan*/ VMFileOpen(char *, int, int, int *);
int /*<<< orphan*/ VMFilePrint(int, char *, ...);
int /*<<< orphan*/ VMFileRead(int, char *, int *);
int /*<<< orphan*/ VMFileSeek(int, int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ VMFileWrite(int, char *, int *);
void VMMain(int argc, char *argv[]) {
  int FileDescriptor, Length, Offset;
  char Buffer[128];
  VMFilePrint(1, "VMMain opening test.txt\n");
  VMFileOpen("test.txt", O_CREAT | O_TRUNC | O_RDWR, 0644, &FileDescriptor);
  VMFilePrint(1, "VMMain VMFileOpen returned %d\n", FileDescriptor);
  VMFilePrint(1, "VMMain writing file\n");
  Length = 13;
  VMFileWrite(FileDescriptor, "Hello world!\n", &Length);
  VMFilePrint(1, "VMMain VMFileWrite returned %d\n", Length);
  VMFilePrint(1, "VMMain seeking file\n");
  VMFileSeek(FileDescriptor, 6, 0, &Offset);
  VMFilePrint(1, "VMMain VMFileSeek offset at %d\n", Offset);
  VMFilePrint(1, "VMMain reading file\n");
  Length = sizeof(Buffer);
  VMFileRead(FileDescriptor, Buffer, &Length);
  VMFilePrint(1, "VMMain VMFileRead returned %d\n", Length);
  if (0 <= Length) {
    Buffer[Length] = '\0';
    VMFilePrint(1, "VMMain read in \"%s\"\n", Buffer);
  }
  VMFilePrint(1, "VMMain closing file\n");
  VMFileClose(FileDescriptor);
  VMFilePrint(1, "Goodbye\n");
}


x86 assembly (clang, -O0):
<VMMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%edi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
or     (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
lea    0xe72(%rip),%rdi
mov    $0x1a4,%edx
lea    -0x14(%rbp),%rcx
call   1080 <VMFileOpen@plt>
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    $0x1,%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
movl   $0xd,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    0xe67(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <VMFileWrite@plt>
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    $0x1,%edi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    -0x14(%rbp),%edi
mov    $0x6,%esi
xor    %edx,%edx
lea    -0x1c(%rbp),%rcx
call   1040 <VMFileSeek@plt>
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    $0x1,%edi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
movl   $0x80,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <VMFileRead@plt>
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jg     12be <VMMain+0x15e>
movslq -0x18(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdx
mov    $0x1,%edi
lea    0xe36(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    $0x1,%edi
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
mov    -0x14(%rbp),%edi
call   1030 <VMFileClose@plt>
mov    $0x1,%edi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1070 <VMFilePrint@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VMMain>:
push   %rbx
sub    $0x90,%rsp
lea    0xe91(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
mov    0x2e76(%rip),%rax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e44(%rip),%rax
or     (%rax),%esi
lea    0xe7c(%rip),%rdi
lea    0x8(%rsp),%rcx
mov    $0x1a4,%edx
call   1080 <VMFileOpen@plt>
mov    0x8(%rsp),%edx
lea    0xe6b(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
lea    0xe77(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
movl   $0xd,0x4(%rsp)
mov    0x8(%rsp),%edi
lea    0xe6d(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <VMFileWrite@plt>
mov    0x4(%rsp),%edx
lea    0xe63(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
lea    0xe70(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
mov    0x8(%rsp),%edi
lea    0xc(%rsp),%rcx
mov    $0x6,%esi
xor    %edx,%edx
call   1040 <VMFileSeek@plt>
mov    0xc(%rsp),%edx
lea    0xe59(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
lea    0xe66(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
movl   $0x80,0x4(%rsp)
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <VMFileRead@plt>
mov    0x4(%rsp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
js     12b4 <VMMain+0x154>
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe4a(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
lea    0xe47(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
mov    0x8(%rsp),%edi
call   1030 <VMFileClose@plt>
lea    0xe40(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <VMFilePrint@plt>
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"VMMain opening test.txt\0A\00"
@.str.1 = [9 x i8] c"test.txt\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"VMMain VMFileOpen returned %d\0A\00"
@.str.3 = [21 x i8] c"VMMain writing file\0A\00"
@.str.4 = [14 x i8] c"Hello world!\0A\00"
@.str.5 = [32 x i8] c"VMMain VMFileWrite returned %d\0A\00"
@.str.6 = [21 x i8] c"VMMain seeking file\0A\00"
@.str.7 = [32 x i8] c"VMMain VMFileSeek offset at %d\0A\00"
@.str.8 = [21 x i8] c"VMMain reading file\0A\00"
@.str.9 = [31 x i8] c"VMMain VMFileRead returned %d\0A\00"
@.str.10 = [21 x i8] c"VMMain read in \22%s\22\0A\00"
@.str.11 = [21 x i8] c"VMMain closing file\0A\00"
@.str.12 = [9 x i8] c"Goodbye\0A\00"
define void @VMMain(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_TRUNC
%12 = or i32 %10, %11
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
%15 = call i32 @VMFileOpen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 420, i32* %5)
%16 = load i32, i32* %5
%17 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 13, i32* %6
%19 = load i32, i32* %5
%20 = call i32 @VMFileWrite(i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%21 = load i32, i32* %6
%22 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%24 = load i32, i32* %5
%25 = call i32 @VMFileSeek(i32 %24, i32 6, i32 0, i32* %7)
%26 = load i32, i32* %7
%27 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %26)
%28 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 128, i32* %6
%29 = load i32, i32* %5
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = call i32 @VMFileRead(i32 %29, i8* %30, i32* %6)
%32 = load i32, i32* %6
%33 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %6
%35 = icmp sle i32 0, %34
br i1 %35, label %36, label %42
36: ; preds = %2
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %38
store i8 0, i8* %39
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%41 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %36, %2
%43 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%44 = load i32, i32* %5
%45 = call i32 @VMFileClose(i32 %44)
%46 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"VMMain opening test.txt\0A\00"
@.str.1 = [9 x i8] c"test.txt\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@.str.2 = [31 x i8] c"VMMain VMFileOpen returned %d\0A\00"
@.str.3 = [21 x i8] c"VMMain writing file\0A\00"
@.str.4 = [14 x i8] c"Hello world!\0A\00"
@.str.5 = [32 x i8] c"VMMain VMFileWrite returned %d\0A\00"
@.str.6 = [21 x i8] c"VMMain seeking file\0A\00"
@.str.7 = [32 x i8] c"VMMain VMFileSeek offset at %d\0A\00"
@.str.8 = [21 x i8] c"VMMain reading file\0A\00"
@.str.9 = [31 x i8] c"VMMain VMFileRead returned %d\0A\00"
@.str.10 = [21 x i8] c"VMMain read in \22%s\22\0A\00"
@.str.11 = [21 x i8] c"VMMain closing file\0A\00"
@.str.12 = [9 x i8] c"Goodbye\0A\00"
define void @VMMain(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%11 = tail call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %13, %12
%15 = load i32, i32* @O_RDWR
%16 = or i32 %14, %15
%17 = call i32 @VMFileOpen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 420, i32* %3)
%18 = load i32, i32* %3
%19 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 13, i32* %4
%21 = load i32, i32* %3
%22 = call i32 @VMFileWrite(i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%23 = load i32, i32* %4
%24 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%26 = load i32, i32* %3
%27 = call i32 @VMFileSeek(i32 %26, i32 6, i32 0, i32* %5)
%28 = load i32, i32* %5
%29 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %28)
%30 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
store i32 128, i32* %4
%31 = load i32, i32* %3
%32 = call i32 @VMFileRead(i32 %31, i8* %10, i32* %4)
%33 = load i32, i32* %4
%34 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %2
%38 = zext i32 %35 to i64
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i8* %10)
br label %41
41: ; preds = %37, %2
%42 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%43 = load i32, i32* %3
%44 = call i32 @VMFileClose(i32 %43)
%45 = call i32 (i32, i8*, ...) @VMFilePrint(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
ret void
}