#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;
};
typedef int /*<<< orphan*/ hourDir;
typedef int /*<<< orphan*/ file;
typedef int /*<<< orphan*/ dayDir;

/* Variables and functions */
char *calloc(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *, ...);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *pathForImage() {
  const char *basePath = "/jobe/vids";
  time_t rawtime = time(NULL);
  struct tm *curtime = localtime(&rawtime);
  const char *dayDirFormat = "%Y%m%d";
  char dayDir[15] = {0};
  (void)strftime(dayDir, sizeof(dayDir), dayDirFormat, curtime);
  const char *hourFormat = "%H";
  char hourDir[4] = {0};
  (void)strftime(hourDir, sizeof(hourDir), hourFormat, curtime);
  const char *fileFormat = "driveway_snap_%Y%m%d_%H%M%S.jpg";
  char file[40] = {0};
  (void)strftime(file, sizeof(file), fileFormat, curtime);
  char *fullPath = calloc(sizeof(char), 75);
  sprintf(fullPath, "%s/%s", basePath, dayDir);
  mkdir(fullPath, 0755);
  sprintf(fullPath, "%s/%s/%s", basePath, dayDir, hourDir);
  mkdir(fullPath, 0755);
  sprintf(fullPath, "%s/%s/%s/%s", basePath, dayDir, hourDir, file);
  return fullPath;
}


x86 assembly (clang, -O0):
<pathForImage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe7e(%rip),%rax
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
lea    0xe65(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x2f(%rbp),%rdi
xor    %esi,%esi
mov    $0xf,%edx
call   1050 <memset@plt>
lea    -0x2f(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0xf,%esi
call   1080 <strftime@plt>
lea    0xe3b(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x3c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x3c(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
call   1080 <strftime@plt>
lea    0xe0d(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    -0x70(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x28,%esi
call   1080 <strftime@plt>
mov    $0x1,%edi
mov    $0x4b,%esi
call   1060 <calloc@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x2f(%rbp),%rcx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x78(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
mov    -0x78(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x2f(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x78(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
mov    -0x78(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x2f(%rbp),%rcx
lea    -0x3c(%rbp),%r8
lea    -0x70(%rbp),%r9
lea    0xd81(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x78(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathForImage>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x50,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
movq   $0x0,0x17(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe6d(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0xf,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
movl   $0x0,0x8(%rsp)
lea    0xe50(%rip),%rdx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    %rbx,%rcx
call   1070 <strftime@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xe21(%rip),%rdx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x28,%esi
mov    %rbx,%rcx
call   1070 <strftime@plt>
mov    $0x1,%edi
mov    $0x4b,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe19(%rip),%rsi
lea    0xdd7(%rip),%r13
mov    %rax,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
lea    0xdeb(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
lea    0xdc1(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [11 x i8] c"/jobe/vids\00"
@.str.1 = [7 x i8] c"%Y%m%d\00"
@.str.2 = [3 x i8] c"%H\00"
@.str.3 = [32 x i8] c"driveway_snap_%Y%m%d_%H%M%S.jpg\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [9 x i8] c"%s/%s/%s\00"
@.str.6 = [12 x i8] c"%s/%s/%s/%s\00"
define i8* @pathForImage() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca [15 x i8]
%6 = alloca i8*
%7 = alloca [4 x i8]
%8 = alloca i8*
%9 = alloca [40 x i8]
%10 = alloca i8*
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %1
%11 = call i32 @time(i32* null)
store i32 %11, i32* %2
%12 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %12, %struct.tm** %3
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %4
%13 = bitcast [15 x i8]* %5 to i8*
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %4
%16 = load %struct.tm*, %struct.tm** %3
%17 = call i32 @strftime(i8* %14, i32 15, i8* %15, %struct.tm* %16)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6
%18 = bitcast [4 x i8]* %7 to i8*
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%20 = load i8*, i8** %6
%21 = load %struct.tm*, %struct.tm** %3
%22 = call i32 @strftime(i8* %19, i32 4, i8* %20, %struct.tm* %21)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8** %8
%23 = bitcast [40 x i8]* %9 to i8*
%24 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %8
%26 = load %struct.tm*, %struct.tm** %3
%27 = call i32 @strftime(i8* %24, i32 40, i8* %25, %struct.tm* %26)
%28 = call i8* @calloc(i32 1, i32 75)
store i8* %28, i8** %10
%29 = load i8*, i8** %10
%30 = load i8*, i8** %1
%31 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%32 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i8*, i8** %10
%34 = call i32 @mkdir(i8* %33, i32 493)
%35 = load i8*, i8** %10
%36 = load i8*, i8** %1
%37 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%39 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* %36, i8* %37, i8* %38)
%40 = load i8*, i8** %10
%41 = call i32 @mkdir(i8* %40, i32 493)
%42 = load i8*, i8** %10
%43 = load i8*, i8** %1
%44 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %7, i64 0, i64 0
%46 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%47 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %43, i8* %44, i8* %45, i8* %46)
%48 = load i8*, i8** %10
ret i8* %48
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [11 x i8] c"/jobe/vids\00"
@.str.1 = [7 x i8] c"%Y%m%d\00"
@.str.2 = [3 x i8] c"%H\00"
@.str.3 = [32 x i8] c"driveway_snap_%Y%m%d_%H%M%S.jpg\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [9 x i8] c"%s/%s/%s\00"
@.str.6 = [12 x i8] c"%s/%s/%s/%s\00"
define noalias i8* @pathForImage() {
%1 = alloca i32
%2 = alloca [15 x i8]
%3 = alloca i32
%4 = alloca [40 x i8]
%5 = bitcast i32* %1 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %1
%7 = call %struct.tm* @localtime(i32* %1)
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%9 = call i32 @strftime(i8* %8, i32 15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %7)
%10 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%11 = call i32 @strftime(i8* %10, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %7)
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%13 = call i32 @strftime(i8* %12, i32 40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %7)
%14 = call dereferenceable_or_null(75) i8* @calloc(i32 1, i32 75)
%15 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
%16 = call i32 @mkdir(i8* %14, i32 493)
%17 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8, i32* %3)
%18 = call i32 @mkdir(i8* %14, i32 493)
%19 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8, i32* %3, i8* %12)
ret i8* %14
}