#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 tm_year;
  int tm_mon;
  int tm_mday;
};

/* Variables and functions */
int /*<<< orphan*/ get_local_time(struct tm *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int);
int get_date_folder_name(char *foldername, char *path, time_t t) {
  struct tm tm;
  int year, month, day;
  if (!t)
    get_local_time(&tm);
  else
    tm = *localtime(&t);
  year = tm.tm_year + 1900;
  month = tm.tm_mon + 1;
  day = tm.tm_mday;
  sprintf(foldername, "%s/%4d%02d%02d", path, year, month, day);
  return 0;
}


x86 assembly (clang, -O0):
<get_date_folder_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    115b <get_date_folder_name+0x2b>
lea    -0x20(%rbp),%rdi
call   1040 <get_local_time@plt>
jmp    1171 <get_date_folder_name+0x41>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x76c,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    0xe5b(%rip),%rsi
call   1050 <sprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_date_folder_name>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,0x14(%rsp)
test   %edx,%edx
je     1160 <get_date_folder_name+0x30>
lea    0x14(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    0x8(%rax),%eax
mov    %eax,0x10(%rsp)
jmp    116a <get_date_folder_name+0x3a>
lea    0x8(%rsp),%rdi
call   1040 <get_local_time@plt>
mov    $0x76c,%ecx
add    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
add    $0x1,%r8d
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [15 x i8] c"%s/%4d%02d%02d\00"
define i32 @get_date_folder_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = call i32 @get_local_time(%struct.tm* %7)
br label %19
15: ; preds = %3
%16 = call %struct.tm* @localtime(i32* %6)
%17 = bitcast %struct.tm* %7 to i8*
%18 = bitcast %struct.tm* %16 to i8*
br label %19
19: ; preds = %15, %13
%20 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
store i32 %22, i32* %8
%23 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
%26 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%27 = load i32, i32* %26
store i32 %27, i32* %10
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = load i32, i32* %10
%33 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30, i32 %31, i32 %32)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [15 x i8] c"%s/%4d%02d%02d\00"
define i32 @get_date_folder_name(i8* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
store i32 %2, i32* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @get_local_time(%struct.tm* %5)
br label %13
10: ; preds = %3
%11 = call %struct.tm* @localtime(i32* %4)
%12 = bitcast %struct.tm* %11 to i8*
br label %13
13: ; preds = %10, %8
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1900
%17 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
%20 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%21 = load i32, i32* %20
%22 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %16, i32 %19, i32 %21)
ret i32 0
}