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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct tm *get_time();
scalar_t__ malloc(int);
unsigned long mktime(struct tm *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int get_current_date(char **string, unsigned long *timestamp) {
  struct tm *datetime;
  datetime = get_time();
  *timestamp = mktime(datetime);
  if ((*string = (char *)malloc(20 * sizeof(char))) == NULL) {
    printf("[Error  ]\tInsufficient physical memory");
    exit(-1);
  }
  sprintf(*string, "%d-%02d-%02d %02d.%02d.%02d", (datetime->tm_year + 1900),
          (datetime->tm_mon + 1), datetime->tm_mday, datetime->tm_hour,
          datetime->tm_min, datetime->tm_sec);
  return 0;
}


x86 assembly (clang, -O0):
<get_current_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <get_time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <mktime@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    -0x8(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11bf <get_current_date+0x5f>
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe25(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1070 <sprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_date>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <get_time@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <mktime@plt>
mov    %rax,(%r14)
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11cc <get_current_date+0x6c>
mov    $0x76c,%edx
add    (%rbx),%edx
mov    0x4(%rbx),%ecx
mov    0x8(%rbx),%r8d
add    $0x1,%ecx
mov    0xc(%rbx),%r9d
mov    0x10(%rbx),%r10d
mov    0x14(%rbx),%ebx
lea    0xe72(%rip),%rsi
mov    %rax,%rdi
push   %rbx
push   %r10
call   1070 <sprintf@plt>
add    $0x10,%rsp
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [28 x i8] c"%d-%02d-%02d %02d.%02d.%02d\00"
define i32 @get_current_date(i8** %0, i64* %1) {
%3 = alloca i8**
%4 = alloca i64*
%5 = alloca %struct.tm*
store i8** %0, i8*** %3
store i64* %1, i64** %4
%6 = call %struct.tm* (...) @get_time()
store %struct.tm* %6, %struct.tm** %5
%7 = load %struct.tm*, %struct.tm** %5
%8 = call i64 @mktime(%struct.tm* %7)
%9 = load i64*, i64** %4
store i64 %8, i64* %9
%10 = call i64 @malloc(i32 20)
%11 = inttoptr i64 %10 to i8*
%12 = load i8**, i8*** %3
store i8* %11, i8** %12
%13 = icmp eq i8* %11, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = load %struct.tm*, %struct.tm** %5
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = add nsw i32 %22, 1900
%24 = load %struct.tm*, %struct.tm** %5
%25 = getelementptr inbounds %struct.tm, %struct.tm* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, 1
%28 = load %struct.tm*, %struct.tm** %5
%29 = getelementptr inbounds %struct.tm, %struct.tm* %28, i32 0, i32 2
%30 = load i32, i32* %29
%31 = load %struct.tm*, %struct.tm** %5
%32 = getelementptr inbounds %struct.tm, %struct.tm* %31, i32 0, i32 3
%33 = load i32, i32* %32
%34 = load %struct.tm*, %struct.tm** %5
%35 = getelementptr inbounds %struct.tm, %struct.tm* %34, i32 0, i32 4
%36 = load i32, i32* %35
%37 = load %struct.tm*, %struct.tm** %5
%38 = getelementptr inbounds %struct.tm, %struct.tm* %37, i32 0, i32 5
%39 = load i32, i32* %38
%40 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %27, i32 %30, i32 %33, i32 %36, i32 %39)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [39 x i8] c"[Error ]\09Insufficient physical memory\00"
@.str.1 = [28 x i8] c"%d-%02d-%02d %02d.%02d.%02d\00"
define i32 @get_current_date(i8** nocapture writeonly %0, i64* nocapture writeonly %1) {
%3 = tail call %struct.tm* (...) @get_time()
%4 = tail call i64 @mktime(%struct.tm* %3)
store i64 %4, i64* %1
%5 = tail call i64 @malloc(i32 20)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %0
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1900
%15 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%25 = load i32, i32* %24
%26 = tail call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %17, i32 %19, i32 %21, i32 %23, i32 %25)
ret i32 0
}