#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 */
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ free(char *);
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *timestamp(const char *fmt) {
  struct tm *stmp;
  char *stamp;
  time_t ts;
  time(&ts);
  stmp = localtime(&ts);
  stamp = malloc(21 * sizeof(char));
  if (stamp)
    strftime(stamp, 21, fmt, stmp);
  else
    die("Memory error.");
  return stamp;
  free(stamp);
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <time@plt>
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a6 <timestamp+0x56>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x15,%esi
call   1060 <strftime@plt>
jmp    11b2 <timestamp+0x62>
lea    0xe53(%rip),%rdi
call   1070 <die@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%r15
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119b <timestamp+0x4b>
mov    %rbx,%rdi
mov    $0x15,%esi
mov    %r14,%rdx
mov    %r15,%rcx
call   1060 <strftime@plt>
jmp    11a7 <timestamp+0x57>
lea    0xe5e(%rip),%rdi
call   1070 <die@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [14 x i8] c"Memory error.\00"
define i8* @timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @time(i32* %5)
%7 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %7, %struct.tm** %3
%8 = call i8* @malloc(i32 21)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8*, i8** %2
%14 = load %struct.tm*, %struct.tm** %3
%15 = call i32 @strftime(i8* %12, i32 21, i8* %13, %struct.tm* %14)
br label %18
16: ; preds = %1
%17 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i8*, i8** %4
ret i8* %19
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [14 x i8] c"Memory error.\00"
define i8* @timestamp(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @time(i32* %2)
%5 = call %struct.tm* @localtime(i32* %2)
%6 = call dereferenceable_or_null(21) i8* @malloc(i32 21)
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @strftime(i8* %6, i32 21, i8* %0, %struct.tm* %5)
br label %12
10: ; preds = %1
%11 = call i32 @die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
ret i8* %6
}