#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 *);
scalar_t__ fwrite(char const *, int, scalar_t__, int /*<<< orphan*/ *);
scalar_t__ strlen(char const *);
int textFileWrite(const char *fn, const char *s) {
  FILE *fp;
  int status = 0;
  if (fn != NULL) {
    fp = fopen(fn, "w");
    if (fp != NULL) {
      if (fwrite(s, sizeof(char), strlen(s), fp) == strlen(s))
        status = 1;
      fclose(fp);
    }
  }
  return (status);
}


x86 assembly (clang, -O0):
<textFileWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11d9 <textFileWrite+0x99>
mov    -0x8(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d4 <textFileWrite+0x94>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    11cb <textFileWrite+0x8b>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d9 <textFileWrite+0x99>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<textFileWrite>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     119c <textFileWrite+0x5c>
mov    %rsi,%rbx
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119c <textFileWrite+0x5c>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ebp,%ebp
cmp    %rax,%r15
sete   %bpl
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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