#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 dummy;
};

/* Variables and functions */
scalar_t__ calloc(int, int);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *get_current_datetime(const char *datetime_format) {
  char *buffer = NULL;
  time_t curtime;
  struct tm *loc_time;
  buffer = (char *)calloc(30, sizeof(char));
  if (!buffer)
    return NULL;
  curtime = time(NULL);
  loc_time = localtime(&curtime);
  strftime(buffer, 30, datetime_format, loc_time);
  return buffer;
}


x86 assembly (clang, -O0):
<get_current_datetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x1e,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <get_current_datetime+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <get_current_datetime+0x76>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1e,%esi
call   1060 <strftime@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_datetime>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x1e,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1188 <get_current_datetime+0x48>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
jmp    118a <get_current_datetime+0x4a>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define i8* @get_current_datetime(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.tm*
store i8* %0, i8** %3
store i8* null, i8** %4
%7 = call i64 @calloc(i32 30, i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %1
store i8* null, i8** %2
br label %20
12: ; preds = %1
%13 = call i32 @time(i32* null)
store i32 %13, i32* %5
%14 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %14, %struct.tm** %6
%15 = load i8*, i8** %4
%16 = load i8*, i8** %3
%17 = load %struct.tm*, %struct.tm** %6
%18 = call i32 @strftime(i8* %15, i32 30, i8* %16, %struct.tm* %17)
%19 = load i8*, i8** %4
store i8* %19, i8** %2
br label %20
20: ; preds = %12, %11
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
%struct.tm = type { i32 }
define i8* @get_current_datetime(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 @calloc(i32 30, i32 1)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %2
%9 = call %struct.tm* @localtime(i32* %2)
%10 = call i32 @strftime(i8* %5, i32 30, i8* %0, %struct.tm* %9)
br label %11
11: ; preds = %1, %7
%12 = phi i8* [ %5, %7 ], [ null, %1 ]
ret i8* %12
}