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


x86 assembly (clang, -O0):
<getdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x41,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    119f <getdatetime+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e2 <getdatetime+0x82>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x40,%esi
lea    0xe45(%rip),%rdx
call   1070 <strftime@plt>
cmp    $0x0,%eax
jne    1223 <getdatetime+0xc3>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdatetime>:
push   %rbx
sub    $0x10,%rsp
mov    $0x41,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b5 <getdatetime+0x55>
mov    %rax,%rbx
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     11c7 <getdatetime+0x67>
lea    0xea3(%rip),%rdx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %eax,%eax
je     11d9 <getdatetime+0x79>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
jmp    11e9 <getdatetime+0x89>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    11e9 <getdatetime+0x89>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@stderr = global i32 0
@.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 %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @time(i32* null)
store i32 %11, i32* %2
%12 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %12, %struct.tm** %3
%13 = load %struct.tm*, %struct.tm** %3
%14 = icmp eq %struct.tm* %13, null
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i8*, i8** %1
%21 = load %struct.tm*, %struct.tm** %3
%22 = call i32 @strftime(i8* %20, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i8*, i8** %1
ret i8* %29
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@stderr = global i32 0
@.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 %9
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %1
%11 = call %struct.tm* @localtime(i32* %1)
%12 = icmp eq %struct.tm* %11, null
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = call i32 @strftime(i8* %3, i32 64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17
ret i8* %3
}