#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 *);
struct tm *localtime(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *getdatetime() {
  char *buf;
  time_t result;
  struct tm *resulttm;
  if ((buf = malloc(sizeof(char) * 65)) == NULL) {
    die("Cannot allocate memory for buf.\n");
  }
  result = time(NULL);
  resulttm = localtime(&result);
  if (resulttm == NULL) {
    die("Error getting localtime.\n");
  }
  if (!strftime(buf, sizeof(char) * 65 - 1, "%a %b %d %H:%M:%S", resulttm)) {
    die("strftime is 0.\n");
  }
  return buf;
}


x86 assembly (clang, -O0):
<getdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x41,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    117c <getdatetime+0x2c>
lea    0xe89(%rip),%rdi
call   1070 <die@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <getdatetime+0x5c>
lea    0xe7a(%rip),%rdi
call   1070 <die@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe7b(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%eax
jne    11da <getdatetime+0x8a>
lea    0xe78(%rip),%rdi
call   1070 <die@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdatetime>:
push   %r14
push   %rbx
push   %rax
mov    $0x41,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1172 <getdatetime+0x22>
lea    0xe93(%rip),%rdi
call   1070 <die@plt>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119b <getdatetime+0x4b>
lea    0xe8b(%rip),%rdi
call   1070 <die@plt>
lea    0xe99(%rip),%rdx
mov    %r14,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1060 <strftime@plt>
test   %eax,%eax
jne    11c2 <getdatetime+0x72>
lea    0xe90(%rip),%rdi
call   1070 <die@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [33 x i8] c"Cannot allocate memory for buf.\0A\00"
@.str.1 = [26 x i8] c"Error getting localtime.\0A\00"
@.str.2 = [18 x i8] c"%a %b %d %H:%M:%S\00"
@.str.3 = [16 x i8] c"strftime is 0.\0A\00"
define i8* @getdatetime() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = call i8* @malloc(i32 65)
store i8* %4, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @time(i32* null)
store i32 %9, i32* %2
%10 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %10, %struct.tm** %3
%11 = load %struct.tm*, %struct.tm** %3
%12 = icmp eq %struct.tm* %11, null
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = load i8*, i8** %1
%17 = load %struct.tm*, %struct.tm** %3
%18 = call i32 @strftime(i8* %16, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [33 x i8] c"Cannot allocate memory for buf.\0A\00"
@.str.1 = [26 x i8] c"Error getting localtime.\0A\00"
@.str.2 = [18 x i8] c"%a %b %d %H:%M:%S\00"
@.str.3 = [16 x i8] c"strftime is 0.\0A\00"
define i8* @getdatetime() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call dereferenceable_or_null(65) i8* @malloc(i32 65)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %1
%9 = call %struct.tm* @localtime(i32* %1)
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @die(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = call i32 @strftime(i8* %3, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %9)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
ret i8* %3
}