#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 const *, char *);
scalar_t__ fputs(char const *, int /*<<< orphan*/ *);
int file_puts(const char *str, const char *path) {
  FILE *fp;
  int rc;
  fp = fopen(path, "w");
  if (!fp)
    return -1;
  if (fputs(str, fp) == EOF) {
    rc = -1;
    goto out_fclose;
  }
  rc = 0;
out_fclose:
  fclose(fp);
  return rc;
}


x86 assembly (clang, -O0):
<file_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <file_puts+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <file_puts+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <file_puts+0x64>
movl   $0xffffffff,-0x24(%rbp)
jmp    119b <file_puts+0x6b>
movl   $0x0,-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):
<file_puts>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xec0(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1177 <file_puts+0x47>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    0x2e86(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%rax
sete   %bpl
neg    %ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    117c <file_puts+0x4c>
mov    $0xffffffff,%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 @file_puts(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** %5
%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 -1, i32* %3
br label %25
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32*, i32** %6
%16 = call i64 @fputs(i8* %14, i32* %15)
%17 = load i64, i64* @EOF
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %7
br label %21
20: ; preds = %13
store i32 0, i32* %7
br label %21
21: ; preds = %20, %19
%22 = load i32*, i32** %6
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %7
store i32 %24, i32* %3
br label %25
25: ; preds = %21, %12
%26 = load i32, i32* %3
ret i32 %26
}

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