#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*/ time_t;
struct tm {
  int dummy;
};
struct stat {
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ filepath;
typedef int /*<<< orphan*/ dir;
typedef int /*<<< orphan*/ date;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *create_files() {
  FILE *fp;
  time_t rawtime;
  struct tm *info;
  char dir[80], date[11];
  static char filepath[80];
  struct stat st = {0};
  snprintf(dir, sizeof(dir), "%s/Timesheets", getenv("HOME"));
  if (stat(dir, &st) == -1)
    mkdir(dir, 0700);
  time(&rawtime);
  strftime(date, sizeof(date), "%Y-%m-%d", localtime(&rawtime));
  snprintf(filepath, sizeof(filepath), "%s/timesheet-%s.txt", dir, date);
  if (access(filepath, F_OK) == -1) {
    fp = fopen(filepath, "w");
    fclose(fp);
  }
  return filepath;
}


x86 assembly (clang, -O0):
<create_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    0xe31(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rcx
mov    $0x50,%esi
lea    0xe08(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
lea    -0x70(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    1223 <create_files+0x73>
lea    -0x70(%rbp),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    -0xc(%rbp),%rdi
call   10a0 <time@plt>
lea    -0x7b(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <localtime@plt>
mov    -0x90(%rbp),%rdi
mov    %eax,%ecx
mov    $0xb,%esi
lea    0xdbe(%rip),%rdx
call   10b0 <strftime@plt>
lea    -0x70(%rbp),%rcx
lea    -0x7b(%rbp),%r8
lea    0x2e27(%rip),%rdi
mov    $0x50,%esi
lea    0xda7(%rip),%rdx
mov    $0x0,%al
call   1070 <snprintf@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
lea    0x2e04(%rip),%rdi
call   10c0 <access@plt>
cmp    $0xffffffff,%eax
jne    12ba <create_files+0x10a>
lea    0x2def(%rip),%rdi
lea    0xd88(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fclose@plt>
lea    0x2dcf(%rip),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_files>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movl   $0x0,0x8(%rsp)
lea    0xe58(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe3e(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    11fa <create_files+0x5a>
lea    0x20(%rsp),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
lea    0xdfd(%rip),%rdx
lea    0x15(%rsp),%r14
mov    %r14,%rdi
mov    $0xb,%esi
mov    %eax,%ecx
call   10a0 <strftime@plt>
lea    0x2e4f(%rip),%rbx
lea    0xde4(%rip),%rdx
lea    0x20(%rsp),%rcx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r14,%r8
xor    %eax,%eax
call   1070 <snprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <access@plt>
cmp    $0xffffffff,%eax
jne    1280 <create_files+0xe0>
lea    0x2e14(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rdi
call   1060 <fclose@plt>
lea    0x2df9(%rip),%rax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.stat = type { i32 }
@create_files.filepath = internal global [80 x i8] zeroinitializer
@.str = [14 x i8] c"%s/Timesheets\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [9 x i8] c"%Y-%m-%d\00"
@.str.3 = [20 x i8] c"%s/timesheet-%s.txt\00"
@F_OK = global i32 0
@.str.4 = [2 x i8] c"w\00"
define i8* @create_files() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca [80 x i8]
%5 = alloca [11 x i8]
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %8, i32 80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%12 = call i32 @stat(i8* %11, %struct.stat* %6)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%16 = call i32 @mkdir(i8* %15, i32 448)
br label %17
17: ; preds = %14, %0
%18 = call i32 @time(i32* %2)
%19 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%20 = call i32 @localtime(i32* %2)
%21 = call i32 @strftime(i8* %19, i32 11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i32, i32* @F_OK
%26 = call i32 @access(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %17
%29 = call i32* @fopen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %29, i32** %1
%30 = load i32*, i32** %1
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %28, %17
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.tm = type { i32 }
@create_files.filepath = internal global [80 x i8] zeroinitializer
@.str = [14 x i8] c"%s/Timesheets\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [9 x i8] c"%Y-%m-%d\00"
@.str.3 = [20 x i8] c"%s/timesheet-%s.txt\00"
@F_OK = global i32 0
@.str.4 = [2 x i8] c"w\00"
define i8* @create_files() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [11 x i8]
%4 = alloca %struct.stat
%5 = bitcast i32* %1 to i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.stat* %4 to i8*
%9 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
store i32 0, i32* %9
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %6, i32 80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 @stat(i8* %6, %struct.stat* %4)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @mkdir(i8* %6, i32 448)
br label %16
16: ; preds = %14, %0
%17 = call i32 @time(i32* %1)
%18 = call i32 @localtime(i32* %1)
%19 = call i32 @strftime(i8* %7, i32 11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i32 80, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* %7)
%21 = load i32, i32* @F_OK
%22 = call i32 @access(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = call i32* @fopen(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %24, %16
ret i8* getelementptr inbounds ([80 x i8], [80 x i8]* @create_files.filepath, i64 0, i64 0)
}