#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fputs(char *, int /*<<< orphan*/ *);
int writeTextFile(char *path, char *data) {
  FILE *f = fopen(path, "w");
  if (!f)
    return 0;
  int res = fputs(data, f) != EOF;
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<writeTextFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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 <writeTextFile+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    119c <writeTextFile+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeTextFile>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xec3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116f <writeTextFile+0x3f>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    0x2e8c(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1171 <writeTextFile+0x41>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@EOF = global i64 0
define i32 @writeTextFile(i8* nocapture %0, i8* nocapture %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 = tail call i64 @fputs(i8* %1, i32* %3)
%7 = load i64, i64* @EOF
%8 = icmp ne i64 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %2, %5
%12 = phi i32 [ %9, %5 ], [ 0, %2 ]
ret i32 %12
}