#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*/ filename;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AT_FDCWD;
scalar_t__ EISDIR;
scalar_t__ ENOENT;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int close(int);
scalar_t__ errno;
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int openat(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ perror(char *);
int printf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  size_t rets;
  int reti;
  char filename[255];
  memset(filename, 'a', sizeof(filename));
  filename[255 - 1] = '\0';
  char filepath[sizeof("tmp/") + sizeof(filename) - 1];
  strcpy(filepath, "tmp/");
  strcat(filepath, filename);
  printf("filepath = %s (len = %lu)\n", filepath, strlen(filepath));
  FILE *fp = fopen("", "r");
  if (fp != NULL || errno != ENOENT) {
    perror("(sanity check) fopen with empty filename did not fail with ENOENT");
    return 1;
  }
  fp = fopen("tmp/", "w");
  if (fp != NULL || errno != EISDIR) {
    perror("(sanity check) fopen of dir with write access did not fail");
    return 1;
  }
  int fd = openat(AT_FDCWD, "tmp/filecreatedbygraphene",
                  O_WRONLY | O_CREAT | O_TRUNC, 0666);
  if (fd < 0) {
    perror("failed to create file from within Graphene");
    return 1;
  }
  reti = close(fd);
  if (reti < 0) {
    perror("fclose failed");
    return 1;
  }
  fp = fopen(filepath, "w");
  if (fp == NULL) {
    perror("fopen failed");
    return 1;
  }
  rets = fwrite("Hello World", sizeof("Hello World"), 1, fp);
  if (rets != 1) {
    perror("fwrite failed");
    return 1;
  }
  reti = fclose(fp);
  if (reti) {
    perror("fclose failed");
    return 1;
  }
  fp = fopen(filepath, "r");
  if (fp == NULL) {
    perror("fopen failed");
    return 1;
  }
  char buf[256];
  rets = fread(buf, 1, sizeof(buf), fp);
  if (rets != sizeof("Hello World")) {
    perror("fread failed");
    return 1;
  }
  reti = fclose(fp);
  if (reti) {
    perror("fclose failed");
    return 1;
  }
  reti = printf("Successfully read from file: %s\n", buf);
  if (reti < 0) {
    perror("printf failed");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x61,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
movb   $0x0,-0x22(%rbp)
lea    -0x230(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x230(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   10d0 <strcat@plt>
lea    -0x230(%rbp),%rax
mov    %rax,-0x348(%rbp)
lea    -0x230(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x348(%rbp),%rsi
mov    %eax,%edx
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdce(%rip),%rdi
lea    0xdc8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    128c <main+0xcc>
mov    0x2d4f(%rip),%rax
mov    (%rax),%rax
mov    0x2d35(%rip),%rcx
cmp    (%rcx),%rax
je     12a4 <main+0xe4>
lea    0xd8f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
lea    0xd55(%rip),%rdi
lea    0xdb2(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    12e6 <main+0x126>
mov    0x2cf5(%rip),%rax
mov    (%rax),%rax
mov    0x2cfb(%rip),%rcx
cmp    (%rcx),%rax
je     12fe <main+0x13e>
lea    0xd79(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%edx
mov    0x2ce1(%rip),%rax
or     (%rax),%edx
mov    0x2cd0(%rip),%rax
or     (%rax),%edx
lea    0xd78(%rip),%rsi
mov    $0x1b6,%ecx
call   1070 <openat@plt>
mov    %eax,-0x23c(%rbp)
cmpl   $0x0,-0x23c(%rbp)
jge    135e <main+0x19e>
lea    0xd6e(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
mov    -0x23c(%rbp),%edi
call   10a0 <close@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    138e <main+0x1ce>
lea    0xd69(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
lea    -0x230(%rbp),%rdi
lea    0xcc8(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    13ce <main+0x20e>
lea    0xd37(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
mov    -0x238(%rbp),%rcx
lea    0xd25(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
je     1412 <main+0x252>
lea    0xd0c(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
mov    -0x238(%rbp),%rdi
call   1050 <fclose@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1443 <main+0x283>
lea    0xcb4(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
lea    -0x230(%rbp),%rdi
lea    0xbcf(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1483 <main+0x2c3>
lea    0xc82(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
lea    -0x340(%rbp),%rdi
mov    -0x238(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1040 <fread@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xc,-0x18(%rbp)
je     14c7 <main+0x307>
lea    0xc65(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
mov    -0x238(%rbp),%rdi
call   1050 <fclose@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     14f8 <main+0x338>
lea    0xbff(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
lea    -0x340(%rbp),%rsi
lea    0xc22(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1532 <main+0x372>
lea    0xc28(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1539 <main+0x379>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x318,%rsp
lea    0x110(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x61,%esi
mov    $0xff,%edx
call   1090 <memset@plt>
movb   $0x0,0x20e(%rsp)
lea    0xe0e(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10d0 <strcat@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0xdee(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xdf5(%rip),%rdi
lea    0xdef(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    1397 <main+0x1d7>
mov    0x2d82(%rip),%rbx
mov    (%rbx),%rax
mov    0x2d68(%rip),%rcx
cmp    (%rcx),%rax
jne    1397 <main+0x1d7>
lea    0xda0(%rip),%rdi
lea    0xdfd(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
jne    13a0 <main+0x1e0>
mov    (%rbx),%rax
mov    0x2d59(%rip),%rcx
cmp    (%rcx),%rax
jne    13a0 <main+0x1e0>
mov    0x2d19(%rip),%rax
mov    0x2d1a(%rip),%rcx
mov    0x2d5b(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    (%rax),%edi
mov    0x2d46(%rip),%rax
or     (%rax),%edx
lea    0xdee(%rip),%rsi
mov    $0x1b6,%ecx
call   1070 <openat@plt>
test   %eax,%eax
js     13b2 <main+0x1f2>
mov    %eax,%edi
call   10a0 <close@plt>
test   %eax,%eax
js     13a9 <main+0x1e9>
lea    0xd89(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13bb <main+0x1fb>
mov    %rax,%rbx
lea    0xe0b(%rip),%rdi
mov    $0x1,%ebp
mov    $0xc,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10e0 <fwrite@plt>
cmp    $0x1,%rax
jne    13c4 <main+0x204>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %eax,%eax
jne    13d2 <main+0x212>
lea    0xcf2(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     13e0 <main+0x220>
mov    %rax,%rbx
lea    0x210(%rsp),%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0xc,%rax
jne    13ee <main+0x22e>
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %eax,%eax
jne    13a9 <main+0x1e9>
lea    0xdaf(%rip),%rdi
xor    %ebp,%ebp
lea    0x210(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
test   %eax,%eax
jns    13ff <main+0x23f>
lea    0xdb4(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xc84(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xcbf(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xd36(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xd02(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xd32(%rip),%rdi
jmp    13f5 <main+0x235>
lea    0xd42(%rip),%rdi
call   10c0 <perror@plt>
jmp    13ff <main+0x23f>
lea    0xd0d(%rip),%rdi
call   10c0 <perror@plt>
jmp    13ff <main+0x23f>
lea    0xd0d(%rip),%rdi
call   10c0 <perror@plt>
jmp    13ff <main+0x23f>
lea    0xd26(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x318,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"tmp/\00"
@.str.1 = [27 x i8] c"filepath = %s (len = %lu)\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [66 x i8] c"(sanity check) fopen with empty filename did not fail with ENOENT\00"
@.str.5 = [2 x i8] c"w\00"
@EISDIR = global i64 0
@.str.6 = [59 x i8] c"(sanity check) fopen of dir with write access did not fail\00"
@AT_FDCWD = global i32 0
@.str.7 = [26 x i8] c"tmp/filecreatedbygraphene\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [43 x i8] c"failed to create file from within Graphene\00"
@.str.9 = [14 x i8] c"fclose failed\00"
@.str.10 = [13 x i8] c"fopen failed\00"
@.str.11 = [12 x i8] c"Hello World\00"
@.str.12 = [14 x i8] c"fwrite failed\00"
@.str.13 = [13 x i8] c"fread failed\00"
@.str.14 = [33 x i8] c"Successfully read from file: %s\0A\00"
@.str.15 = [14 x i8] c"printf failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca [255 x i8]
%9 = alloca [259 x i8]
%10 = alloca i32*
%11 = alloca i32
%12 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i8 signext 97, i32 255)
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 254
store i8 0, i8* %15
%16 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %23)
%25 = call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %10
%26 = load i32*, i32** %10
%27 = icmp ne i32* %26, null
br i1 %27, label %32, label %28
28: ; preds = %2
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp ne i64 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %28, %2
%33 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %114
34: ; preds = %28
%35 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %35, i32** %10
%36 = load i32*, i32** %10
%37 = icmp ne i32* %36, null
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i64, i64* @errno
%40 = load i64, i64* @EISDIR
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %44
42: ; preds = %38, %34
%43 = call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %114
44: ; preds = %38
%45 = load i32, i32* @AT_FDCWD
%46 = load i32, i32* @O_WRONLY
%47 = load i32, i32* @O_CREAT
%48 = or i32 %46, %47
%49 = load i32, i32* @O_TRUNC
%50 = or i32 %48, %49
%51 = call i32 @openat(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %50, i32 438)
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %44
%55 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %114
56: ; preds = %44
%57 = load i32, i32* %11
%58 = call i32 @close(i32 %57)
store i32 %58, i32* %7
%59 = load i32, i32* %7
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %114
63: ; preds = %56
%64 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%65 = call i32* @fopen(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %65, i32** %10
%66 = load i32*, i32** %10
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %114
70: ; preds = %63
%71 = load i32*, i32** %10
%72 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 12, i32 1, i32* %71)
store i64 %72, i64* %6
%73 = load i64, i64* %6
%74 = icmp ne i64 %73, 1
br i1 %74, label %75, label %77
75: ; preds = %70
%76 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %3
br label %114
77: ; preds = %70
%78 = load i32*, i32** %10
%79 = call i32 @fclose(i32* %78)
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %77
%83 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %114
84: ; preds = %77
%85 = getelementptr inbounds [259 x i8], [259 x i8]* %9, i64 0, i64 0
%86 = call i32* @fopen(i8* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %86, i32** %10
%87 = load i32*, i32** %10
%88 = icmp eq i32* %87, null
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %3
br label %114
91: ; preds = %84
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%93 = load i32*, i32** %10
%94 = call i64 @fread(i8* %92, i32 1, i32 256, i32* %93)
store i64 %94, i64* %6
%95 = load i64, i64* %6
%96 = icmp ne i64 %95, 12
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %3
br label %114
99: ; preds = %91
%100 = load i32*, i32** %10
%101 = call i32 @fclose(i32* %100)
store i32 %101, i32* %7
%102 = load i32, i32* %7
%103 = icmp ne i32 %102, 0
br i1 %103, label %104, label %106
104: ; preds = %99
%105 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %3
br label %114
106: ; preds = %99
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%108 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i8* %107)
store i32 %108, i32* %7
%109 = load i32, i32* %7
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %106
%112 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
store i32 1, i32* %3
br label %114
113: ; preds = %106
store i32 0, i32* %3
br label %114
114: ; preds = %113, %111, %104, %97, %89, %82, %75, %68, %61, %54, %42, %32
%115 = load i32, i32* %3
ret i32 %115
}

LLVM IR (-O2):
@.str = [5 x i8] c"tmp/\00"
@.str.1 = [27 x i8] c"filepath = %s (len = %lu)\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [2 x i8] c"r\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [66 x i8] c"(sanity check) fopen with empty filename did not fail with ENOENT\00"
@.str.5 = [2 x i8] c"w\00"
@EISDIR = global i64 0
@.str.6 = [59 x i8] c"(sanity check) fopen of dir with write access did not fail\00"
@AT_FDCWD = global i32 0
@.str.7 = [26 x i8] c"tmp/filecreatedbygraphene\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.8 = [43 x i8] c"failed to create file from within Graphene\00"
@.str.9 = [14 x i8] c"fclose failed\00"
@.str.10 = [13 x i8] c"fopen failed\00"
@.str.11 = [12 x i8] c"Hello World\00"
@.str.12 = [14 x i8] c"fwrite failed\00"
@.str.13 = [13 x i8] c"fread failed\00"
@.str.14 = [33 x i8] c"Successfully read from file: %s\0A\00"
@.str.15 = [14 x i8] c"printf failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = alloca [259 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i8 signext 97, i32 255)
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 254
store i8 0, i8* %8
%9 = getelementptr inbounds [259 x i8], [259 x i8]* %4, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @strcat(i8* %9, i8* %6)
%12 = call i32 @strlen(i8* %9)
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %12)
%14 = call i32* @fopen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOENT
%19 = icmp eq i64 %17, %18
br i1 %19, label %22, label %20
20: ; preds = %16, %2
%21 = call i32 @perror(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0))
br label %82
22: ; preds = %16
%23 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i64, i64* @errno
%27 = load i64, i64* @EISDIR
%28 = icmp eq i64 %26, %27
br i1 %28, label %31, label %29
29: ; preds = %25, %22
%30 = call i32 @perror(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.6, i64 0, i64 0))
br label %82
31: ; preds = %25
%32 = load i32, i32* @AT_FDCWD
%33 = load i32, i32* @O_WRONLY
%34 = load i32, i32* @O_CREAT
%35 = or i32 %34, %33
%36 = load i32, i32* @O_TRUNC
%37 = or i32 %35, %36
%38 = call i32 @openat(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i32 %37, i32 438)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %31
%41 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
br label %82
42: ; preds = %31
%43 = call i32 @close(i32 %38)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %82
47: ; preds = %42
%48 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %82
52: ; preds = %47
%53 = call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 12, i32 1, i32* %48)
%54 = icmp eq i64 %53, 1
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %82
57: ; preds = %52
%58 = call i32 @fclose(i32* %48)
%59 = icmp eq i32 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %82
62: ; preds = %57
%63 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%64 = icmp eq i32* %63, null
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %82
67: ; preds = %62
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%69 = call i64 @fread(i8* %68, i32 1, i32 256, i32* %63)
%70 = icmp eq i64 %69, 12
br i1 %70, label %71, label %77
71: ; preds = %67
%72 = call i32 @fclose(i32* %63)
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %71
%75 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.14, i64 0, i64 0), i8* %68)
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74, %71, %67
%78 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.13, i64 0, i64 0), %67 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), %71 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0), %74 ]
%79 = call i32 @perror(i8* %78)
br label %80
80: ; preds = %77, %74
%81 = phi i32 [ 0, %74 ], [ 1, %77 ]
br label %82
82: ; preds = %40, %45, %50, %55, %60, %65, %80, %29, %20
%83 = phi i32 [ 1, %20 ], [ 1, %29 ], [ 1, %40 ], [ 1, %45 ], [ 1, %50 ], [ 1, %55 ], [ 1, %60 ], [ 1, %65 ], [ %81, %80 ]
ret i32 %83
}