#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__ pce_log_add_fp(int /*<<< orphan*/ *, int, unsigned int);
int pce_log_add_fname(const char *fname, unsigned level) {
  FILE *fp;
  fp = fopen(fname, "a");
  if (fp == NULL) {
    return (1);
  }
  if (pce_log_add_fp(fp, 1, level)) {
    fclose(fp);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<pce_log_add_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb6(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116a <pce_log_add_fname+0x3a>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <pce_log_add_fname+0x71>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1040 <pce_log_add_fp@plt>
cmp    $0x0,%rax
je     119a <pce_log_add_fname+0x6a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <pce_log_add_fname+0x71>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pce_log_add_fname>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
lea    0xec2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     116f <pce_log_add_fname+0x3f>
mov    %rax,%rbx
mov    $0x1,%ebp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   1040 <pce_log_add_fp@plt>
test   %rax,%rax
je     1176 <pce_log_add_fname+0x46>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1178 <pce_log_add_fname+0x48>
mov    $0x1,%ebp
jmp    1178 <pce_log_add_fname+0x48>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
define i32 @pce_log_add_fname(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %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 1, i32* %3
br label %21
12: ; preds = %2
%13 = load i32*, i32** %6
%14 = load i32, i32* %5
%15 = call i64 @pce_log_add_fp(i32* %13, i32 1, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32*, i32** %6
%19 = call i32 @fclose(i32* %18)
store i32 1, i32* %3
br label %21
20: ; preds = %12
store i32 0, i32* %3
br label %21
21: ; preds = %20, %17, %11
%22 = load i32, i32* %3
ret i32 %22
}

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