#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 */
char *calloc(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *m_current_timestamp() {
  char *timestamp = calloc(1, 20);
  if (timestamp == NULL)
    return NULL;
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  snprintf(timestamp, 20, "%04d-%02d-%02d %02d:%02d:%02d",
           timeinfo->tm_year + 1900, timeinfo->tm_mon, timeinfo->tm_mday,
           timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
  return timestamp;
}


x86 assembly (clang, -O0):
<m_current_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x1,%edi
mov    $0x14,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1173 <m_current_timestamp+0x33>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <m_current_timestamp+0xa6>
lea    -0x14(%rbp),%rdi
call   1060 <time@plt>
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%r11d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
mov    $0x14,%esi
lea    0xe34(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_current_timestamp>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
mov    $0x14,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ab <m_current_timestamp+0x6b>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1060 <time@plt>
mov    %r14,%rdi
call   1030 <localtime@plt>
mov    $0x76c,%ecx
add    (%rax),%ecx
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%r11d
mov    0x14(%rax),%eax
sub    $0x8,%rsp
lea    0xe6b(%rip),%rdx
mov    %rbx,%rdi
mov    $0x14,%esi
push   %rax
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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