#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 */
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
};

/* Variables and functions */
int /*<<< orphan*/ get_local_time(struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int, int, int);
int get_index_folder_name(char *foldername, int index, char *path) {
  struct tm tm;
  int year, month, day;
  get_local_time(&tm);
  year = tm.tm_year % 10;
  month = tm.tm_mon + 1;
  day = tm.tm_mday;
  sprintf(foldername, "%s/%03d%d%02d%02d", path, index, year, month, day);
  return 0;
}


x86 assembly (clang, -O0):
<get_index_folder_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <get_local_time@plt>
mov    -0x28(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x34(%rbp),%eax
lea    0xe8a(%rip),%rsi
mov    %eax,(%rsp)
call   1040 <sprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index_folder_name>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
call   1030 <get_local_time@plt>
movslq 0x10(%rsp),%r8
imul   $0x66666667,%r8,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r8d
mov    0x14(%rsp),%r9d
mov    0x18(%rsp),%eax
add    $0x1,%r9d
mov    %eax,(%rsp)
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <sprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [18 x i8] c"%s/%03d%d%02d%02d\00"
define i32 @get_index_folder_name(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.tm
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 @get_local_time(%struct.tm* %7)
%12 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
%13 = load i32, i32* %12
%14 = srem i32 %13, 10
store i32 %14, i32* %8
%15 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %9
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
%19 = load i32, i32* %18
store i32 %19, i32* %10
%20 = load i8*, i8** %4
%21 = load i8*, i8** %6
%22 = load i32, i32* %5
%23 = load i32, i32* %8
%24 = load i32, i32* %9
%25 = load i32, i32* %10
%26 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22, i32 %23, i32 %24, i32 %25)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [18 x i8] c"%s/%03d%d%02d%02d\00"
define i32 @get_index_folder_name(i8* nocapture writeonly %0, i32 %1, i8* %2) {
%4 = alloca %struct.tm
%5 = bitcast %struct.tm* %4 to i8*
%6 = call i32 @get_local_time(%struct.tm* %4)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = srem i32 %8, 10
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%14 = load i32, i32* %13
%15 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1, i32 %9, i32 %12, i32 %14)
ret i32 0
}