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

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
void doOpenFile() {
  FILE *fp = fopen("oh.txt", "w");
  int result = access("oh.txt", F_OK);
  printf("access ? %d\n", result);
  if (fp != NULL) {
    printf("oh.txt opened!");
    fclose(fp);
  } else {
    printf("oh.txt opened!");
  }
}


x86 assembly (clang, -O0):
<doOpenFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <access@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x8(%rbp)
je     11af <doOpenFile+0x6f>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11bd <doOpenFile+0x7d>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doOpenFile>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%r14
lea    0xeb5(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <access@plt>
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
je     11a0 <doOpenFile+0x60>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"oh.txt\00"
@.str.1 = [2 x i8] c"w\00"
@F_OK = global i32 0
@.str.2 = [13 x i8] c"access ? %d\0A\00"
@.str.3 = [15 x i8] c"oh.txt opened!\00"
define void @doOpenFile() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32, i32* @F_OK
%5 = call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = load i32*, i32** %1
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%12 = load i32*, i32** %1
%13 = call i32 @fclose(i32* %12)
br label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"oh.txt\00"
@.str.1 = [2 x i8] c"w\00"
@F_OK = global i32 0
@.str.2 = [13 x i8] c"access ? %d\0A\00"
@.str.3 = [15 x i8] c"oh.txt opened!\00"
define void @doOpenFile() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = load i32, i32* @F_OK
%3 = tail call i32 @access(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = icmp eq i32* %1, null
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br i1 %5, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @fclose(i32* %1)
br label %9
9: ; preds = %0, %7
ret void
}