#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;
};
typedef int /*<<< orphan*/ output;

/* Variables and functions */
int /*<<< orphan*/ abort();
struct tm *localtime(int /*<<< orphan*/ *);
char *strdup(char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *datetime_str(time_t t) {
  static char output[32];
  struct tm *tm = localtime(&t);
  if (!tm)
    abort();
  if (!strftime(output, sizeof(output), "%Y-%m-%d %H:%M:%S", tm))
    abort();
  return strdup(output);
}


x86 assembly (clang, -O0):
<datetime_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116a <datetime_str+0x2a>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x10(%rbp),%rcx
lea    0x2edb(%rip),%rdi
mov    $0x20,%esi
lea    0xe7f(%rip),%rdx
call   1050 <strftime@plt>
cmp    $0x0,%eax
jne    1196 <datetime_str+0x56>
mov    $0x0,%al
call   1040 <abort@plt>
lea    0x2eb3(%rip),%rdi
call   1060 <strdup@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<datetime_str>:
push   %rax
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1181 <datetime_str+0x41>
lea    0x2ef5(%rip),%rdi
lea    0xe9e(%rip),%rdx
mov    $0x20,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
test   %eax,%eax
je     1181 <datetime_str+0x41>
lea    0x2ed6(%rip),%rdi
call   1060 <strdup@plt>
pop    %rcx
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@datetime_str.output = internal global [32 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define i8* @datetime_str(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
store i32 %0, i32* %2
%4 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %4, %struct.tm** %3
%5 = load %struct.tm*, %struct.tm** %3
%6 = icmp ne %struct.tm* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %1
%10 = load %struct.tm*, %struct.tm** %3
%11 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @datetime_str.output, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %9
%16 = call i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @datetime_str.output, i64 0, i64 0))
ret i8* %16
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@datetime_str.output = internal global [32 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define noalias i8* @datetime_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call %struct.tm* @localtime(i32* %2)
%4 = icmp eq %struct.tm* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = call i32 (...) @abort()
unreachable
7: ; preds = %1
%8 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @datetime_str.output, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %7
%13 = call i8* @strdup(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @datetime_str.output, i64 0, i64 0))
ret i8* %13
}