#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int create_file(const char *filename) {
  int failed = 0;
  FILE *file = fopen(filename, "r");
  if (NULL == file) {
    file = fopen(filename, "w");
    if (NULL == file) {
      failed = 1;
    }
  }
  if (file) {
    fclose(file);
  }
  return failed;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    117f <create_file+0x5f>
mov    -0x8(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    117a <create_file+0x5a>
movl   $0x1,-0xc(%rbp)
jmp    117f <create_file+0x5f>
cmpq   $0x0,-0x18(%rbp)
je     1193 <create_file+0x73>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
jne    1149 <create_file+0x29>
lea    0xec6(%rip),%rsi
mov    %rbx,%rdi
call   1040 <fopen@plt>
test   %rax,%rax
je     1155 <create_file+0x35>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @create_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp eq i32* null, %7
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 1, i32* %3
br label %15
15: ; preds = %14, %9
br label %16
16: ; preds = %15, %1
%17 = load i32*, i32** %4
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @create_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %1, %4
%8 = phi i32* [ %5, %4 ], [ %2, %1 ]
%9 = tail call i32 @fclose(i32* %8)
br label %10
10: ; preds = %7, %4
%11 = phi i32 [ 0, %7 ], [ 1, %4 ]
ret i32 %11
}