#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 *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
FILE *open_list(char *mode) {
  FILE *fp;
  char todoFilePath[256];
  sprintf(todoFilePath, "%s/%s", getenv("HOME"), ".todofile");
  fp = fopen(todoFilePath, mode);
  if (fp == NULL) {
    fp = fopen(todoFilePath, "w");
    fclose(fp);
    return open_list(mode);
  }
  return fp;
}


x86 assembly (clang, -O0):
<open_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x128(%rbp),%rdi
mov    %rax,%rdx
lea    0xe76(%rip),%rsi
lea    0xe7a(%rip),%rcx
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e7 <open_list+0x97>
lea    -0x120(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1050 <open_list@plt>
mov    %rax,-0x8(%rbp)
jmp    11ef <open_list+0x9f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_list>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe90(%rip),%rsi
lea    0xe94(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <open_list+0x50>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6e(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1050 <open_list@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [10 x i8] c".todofile\00"
@.str.3 = [2 x i8] c"w\00"
define i32* @open_list(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
store i8* %0, i8** %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %9, i8* %10)
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %21
14: ; preds = %1
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = call i32 @fclose(i32* %17)
%19 = load i8*, i8** %3
%20 = call i32* @open_list(i8* %19)
store i32* %20, i32** %2
br label %23
21: ; preds = %1
%22 = load i32*, i32** %4
store i32* %22, i32** %2
br label %23
23: ; preds = %21, %14
%24 = load i32*, i32** %2
ret i32* %24
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [10 x i8] c".todofile\00"
@.str.3 = [2 x i8] c"w\00"
define noalias i32* @open_list(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%6 = call i32* @fopen(i8* %3, i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %9)
%11 = tail call i32* @open_list(i8* %0)
br label %12
12: ; preds = %1, %8
%13 = phi i32* [ %11, %8 ], [ %6, %1 ]
ret i32* %13
}