#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*/ initialize(int, char **);
char *malloc(int);
int /*<<< orphan*/ pfs_close(int);
int /*<<< orphan*/ pfs_create(char *, int);
int pfs_open(char *, char);
int /*<<< orphan*/ pfs_read(int, char *, int, int /*<<< orphan*/, int *);
int main(int argc, char *argv[]) {
  initialize(argc, argv);
  pfs_create("foo.txt", 1);
  int fd = pfs_open("pfs_file1", 'w');
  int cache_hit;
  char *data = malloc(1024);
  pfs_read(fd, data, 1024, 0, &cache_hit);
  pfs_close(fd);
  return 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    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <initialize@plt>
lea    0xe77(%rip),%rdi
mov    $0x1,%esi
call   1080 <pfs_create@plt>
lea    0xe6e(%rip),%rdi
mov    $0x77,%esi
call   1040 <pfs_open@plt>
mov    %eax,-0x14(%rbp)
mov    $0x400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
call   1030 <pfs_read@plt>
mov    -0x14(%rbp),%edi
call   1070 <pfs_close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
call   1050 <initialize@plt>
lea    0xe8f(%rip),%rdi
mov    $0x1,%esi
call   1080 <pfs_create@plt>
lea    0xe86(%rip),%rdi
mov    $0x77,%esi
call   1040 <pfs_open@plt>
mov    %eax,%ebx
mov    $0x400,%edi
call   1060 <malloc@plt>
lea    0xc(%rsp),%r8
mov    %ebx,%edi
mov    %rax,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <pfs_read@plt>
mov    %ebx,%edi
call   1070 <pfs_close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [10 x i8] c"pfs_file1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @initialize(i32 %9, i8** %10)
%12 = call i32 @pfs_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1)
%13 = call i32 @pfs_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8 signext 119)
store i32 %13, i32* %6
%14 = call i8* @malloc(i32 1024)
store i8* %14, i8** %8
%15 = load i32, i32* %6
%16 = load i8*, i8** %8
%17 = call i32 @pfs_read(i32 %15, i8* %16, i32 1024, i32 0, i32* %7)
%18 = load i32, i32* %6
%19 = call i32 @pfs_close(i32 %18)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [10 x i8] c"pfs_file1\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = tail call i32 @initialize(i32 %0, i8** %1)
%5 = tail call i32 @pfs_create(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 1)
%6 = tail call i32 @pfs_open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8 signext 119)
%7 = bitcast i32* %3 to i8*
%8 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%9 = call i32 @pfs_read(i32 %6, i8* %8, i32 1024, i32 0, i32* %3)
%10 = call i32 @pfs_close(i32 %6)
ret i32 0
}