#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 EINVAL;
int errno;
int /*<<< orphan*/ *fopen(char const *, char *);
int pinelog_set_output_stream(int /*<<< orphan*/ *);
int pinelog_set_output_file(const char *file) {
  FILE *stream;
  if (file == NULL) {
    return EINVAL;
  }
  errno = 0;
  stream = fopen(file, "w");
  if (stream == NULL) {
    return errno;
  }
  return pinelog_set_output_stream(stream);
}


x86 assembly (clang, -O0):
<pinelog_set_output_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <pinelog_set_output_file+0x28>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <pinelog_set_output_file+0x71>
mov    0x2e91(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1185 <pinelog_set_output_file+0x65>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <pinelog_set_output_file+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <pinelog_set_output_stream@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pinelog_set_output_file>:
push   %rbx
test   %rdi,%rdi
je     114d <pinelog_set_output_file+0x2d>
mov    0x2eb3(%rip),%rbx
movl   $0x0,(%rbx)
lea    0xec6(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1158 <pinelog_set_output_file+0x38>
mov    %rax,%rdi
pop    %rbx
jmp    1030 <pinelog_set_output_stream@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    (%rbx),%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [2 x i8] c"w\00"
define i32 @pinelog_set_output_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @EINVAL
store i32 %8, i32* %2
br label %19
9: ; preds = %1
store i32 0, i32* @errno
%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** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = load i32, i32* @errno
store i32 %15, i32* %2
br label %19
16: ; preds = %9
%17 = load i32*, i32** %4
%18 = call i32 @pinelog_set_output_stream(i32* %17)
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %14, %7
%20 = load i32, i32* %2
ret i32 %20
}

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