#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 *);
char *datetime_to_string(const time_t time_input, const char *datetime_format) {
  char *buffer = NULL;
  time_t curtime;
  struct tm *loc_time = NULL;
  buffer = (char *)calloc(30, sizeof(char));
  if (!buffer)
    return NULL;
  curtime = time_input;
  loc_time = localtime(&curtime);
  strftime(buffer, 30, datetime_format, loc_time);
  return buffer;
}


x86 assembly (clang, -O0):
<datetime_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x1e,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    117a <datetime_to_string+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    11ab <datetime_to_string+0x7b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1e,%esi
call   1050 <strftime@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<datetime_to_string>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x1e,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     1177 <datetime_to_string+0x47>
mov    %rax,%rbx
mov    %ebp,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <strftime@plt>
jmp    1179 <datetime_to_string+0x49>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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