#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int create_file(char *path, char *txt) {
  FILE *fp = fopen(path, "w");
  if (fp == NULL)
    return 0;
  if (txt != NULL)
    fprintf(fp, "%s", txt);
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <create_file+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    119a <create_file+0x6a>
cmpq   $0x0,-0x18(%rbp)
je     118a <create_file+0x5a>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116a <create_file+0x3a>
mov    %rax,%rbx
test   %r14,%r14
je     115b <create_file+0x2b>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    116c <create_file+0x3c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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