#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*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *getdatetime() {
  static char buf[64];
  time_t result;
  struct tm *resulttm;
  result = time(NULL);
  resulttm = localtime(&result);
  if (resulttm == NULL) {
    fprintf(stderr, "Error getting localtime.\n");
    exit(1);
  }
  if (!strftime(buf, sizeof(char) * 64 - 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    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <getdatetime+0x4b>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rcx
lea    0x2eba(%rip),%rdi
mov    $0x3f,%esi
lea    0xe68(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%eax
jne    11df <getdatetime+0x8f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0x2e7a(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdatetime>:
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1193 <getdatetime+0x43>
lea    0x2eee(%rip),%rdi
lea    0xea1(%rip),%rdx
mov    $0x3f,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %eax,%eax
je     11a5 <getdatetime+0x55>
lea    0x2ecf(%rip),%rax
pop    %rcx
ret
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
jmp    11b5 <getdatetime+0x65>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
%struct.tm = type { i32 }
@getdatetime.buf = internal global [64 x i8] zeroinitializer
@stderr = global i32 0
@.str = [26 x i8] c"Error getting localtime.\0A\00"
@.str.1 = [18 x i8] c"%a %b %d %H:%M:%S\00"
@.str.2 = [16 x i8] c"strftime is 0.\0A\00"
define i8* @getdatetime() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @time(i32* null)
store i32 %3, i32* %1
%4 = call %struct.tm* @localtime(i32* %1)
%5 = icmp eq %struct.tm* %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 ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 @strftime(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getdatetime.buf, i64 0, i64 0), i32 63, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @getdatetime.buf, i64 0, i64 0)
}