#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 *, char *);
int fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
char *get_filename();
int set_default(char *u) {
  char *path;
  FILE *file;
  int result;
  path = get_filename();
  if (path == NULL) {
    free(path);
    return false;
  }
  file = fopen(path, "w");
  free(path);
  result = true;
  if (u != NULL && u[0] != '\0')
    result = fprintf(file, "%s", u);
  fclose(file);
  return result;
}


x86 assembly (clang, -O0):
<set_default>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <get_filename@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <set_default+0x37>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ec <set_default+0x9c>
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11dd <set_default+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11dd <set_default+0x8d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe2d(%rip),%rsi
call   1060 <fprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_default>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <get_filename@plt>
test   %rax,%rax
je     11b7 <set_default+0x67>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%r12d
test   %r14,%r14
je     11ad <set_default+0x5d>
cmpb   $0x0,(%r14)
je     11ad <set_default+0x5d>
lea    0xe63(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1050 <fclose@plt>
jmp    11be <set_default+0x6e>
xor    %edi,%edi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @set_default(i8* %0) {
%2 = tail call i8* (...) @get_filename()
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @free(i8* null)
br label %18
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @free(i8* %2)
%9 = icmp eq i8* %0, null
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %10, %6
%16 = phi i32 [ %14, %13 ], [ 1, %10 ], [ 1, %6 ]
%17 = tail call i32 @fclose(i32* %7)
br label %18
18: ; preds = %15, %4
%19 = phi i32 [ 0, %4 ], [ %16, %15 ]
ret i32 %19
}