#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *get_filename();
char *strdup(char *);
char *get_default(void) {
  char *path;
  FILE *file;
  char tmp[100];
  path = get_filename();
  if (path == NULL) {
    free(path);
    return NULL;
  }
  file = fopen(path, "r");
  free(path);
  if (file == NULL)
    return strdup("");
  tmp[0] = '\0';
  fgets(tmp, 100, file);
  fclose(file);
  return strdup(tmp);
}


x86 assembly (clang, -O0):
<get_default>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    $0x0,%al
call   1040 <get_filename@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <get_default+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1200 <get_default+0xa0>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11d4 <get_default+0x74>
lea    0xe3b(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1200 <get_default+0xa0>
movb   $0x0,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x80(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_default>:
push   %r14
push   %rbx
sub    $0x68,%rsp
xor    %eax,%eax
call   1040 <get_filename@plt>
test   %rax,%rax
je     11c1 <get_default+0x61>
mov    %rax,%rbx
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11d5 <get_default+0x75>
movb   $0x0,(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%rbx
jmp    11ca <get_default+0x6a>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe25(%rip),%rdi
add    $0x68,%rsp
pop    %rbx
pop    %r14
jmp    1080 <strdup@plt>

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

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