#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;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *bench_get_current_date() {
  time_t t = time(NULL);
  struct tm tm = *localtime(&t);
  char *out = (char *)malloc(sizeof(char) * 50);
  sprintf(out, "%d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1,
          tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  return out;
}


x86 assembly (clang, -O0):
<bench_get_current_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x18(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    $0x32,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x76c,%edx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x10(%rbp),%r10d
mov    -0xc(%rbp),%eax
lea    0xe55(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_get_current_date>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    0x4(%rax),%ebx
mov    0x8(%rax),%r15d
mov    0xc(%rax),%r14d
mov    0x10(%rax),%ecx
mov    %rcx,0x10(%rsp)
mov    0x14(%rax),%r13d
mov    $0x76c,%ebp
add    (%rax),%ebp
mov    $0x32,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
add    $0x1,%ebx
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
mov    %r14d,%r9d
push   %r13
push   0x18(%rsp)
call   1060 <sprintf@plt>
add    $0x10,%rsp
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"%d-%d-%d %d:%d:%d\0A\00"
define i8* @bench_get_current_date() {
%1 = alloca i32
%2 = alloca %struct.tm
%3 = alloca i8*
%4 = call i32 @time(i32* null)
store i32 %4, i32* %1
%5 = call %struct.tm* @localtime(i32* %1)
%6 = bitcast %struct.tm* %2 to i8*
%7 = bitcast %struct.tm* %5 to i8*
%8 = call i64 @malloc(i32 50)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1900
%14 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 4
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %2, i32 0, i32 5
%24 = load i32, i32* %23
%25 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %18, i32 %20, i32 %22, i32 %24)
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"%d-%d-%d %d:%d:%d\0A\00"
define i8* @bench_get_current_date() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = call %struct.tm* @localtime(i32* %1)
%5 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%16 = load i32, i32* %15
%17 = call i64 @malloc(i32 50)
%18 = inttoptr i64 %17 to i8*
%19 = add nsw i32 %6, 1900
%20 = add nsw i32 %8, 1
%21 = call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i32 %10, i32 %12, i32 %14, i32 %16)
ret i8* %18
}