#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 */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *);
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *get_current_time(void) {
  static char output[128];
  time_t t;
  struct tm *ltime;
  t = time(NULL);
  ltime = localtime(&t);
  if (ltime == NULL) {
    sprintf(output, "ERR: localtime(3)");
    return output;
  }
  if (strftime(output, sizeof(output), "%a %d %b %r", ltime) == 0) {
    sprintf(output, "ERR: strfime(3)");
    return output;
  }
  return output;
}


x86 assembly (clang, -O0):
<get_current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
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    118f <get_current_time+0x4f>
lea    0x2edd(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2eca(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <get_current_time+0xa3>
mov    -0x18(%rbp),%rcx
lea    0x2eb6(%rip),%rdi
mov    $0x80,%esi
lea    0xe6c(%rip),%rdx
call   1050 <strftime@plt>
cmp    $0x0,%rax
jne    11d8 <get_current_time+0x98>
lea    0x2e94(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2e81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11e3 <get_current_time+0xa3>
lea    0x2e71(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_time>:
push   %rax
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     117b <get_current_time+0x4b>
lea    0x2efe(%rip),%rdi
lea    0xeb9(%rip),%rdx
mov    $0x80,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
test   %rax,%rax
jne    1192 <get_current_time+0x62>
movups 0xeac(%rip),%xmm0
movaps %xmm0,0x2ed7(%rip)
jmp    1192 <get_current_time+0x62>
movups 0xe7e(%rip),%xmm0
movaps %xmm0,0x2ec7(%rip)
movw   $0x29,0x2ece(%rip)
lea    0x2eb7(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@get_current_time.output = internal global [128 x i8] zeroinitializer
@.str = [18 x i8] c"ERR: localtime(3)\00"
@.str.1 = [12 x i8] c"%a %d %b %r\00"
@.str.2 = [16 x i8] c"ERR: strfime(3)\00"
define i8* @get_current_time() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca %struct.tm*
%4 = call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %5, %struct.tm** %3
%6 = load %struct.tm*, %struct.tm** %3
%7 = icmp eq %struct.tm* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i8** %1
br label %17
10: ; preds = %0
%11 = load %struct.tm*, %struct.tm** %3
%12 = call i64 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @sprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i8** %1
br label %17
16: ; preds = %10
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i8** %1
br label %17
17: ; preds = %16, %14, %8
%18 = load i8*, i8** %1
ret i8* %18
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@get_current_time.output = internal global [128 x i8] zeroinitializer
@.str = [18 x i8] c"ERR: localtime(3)\00"
@.str.1 = [12 x i8] c"%a %d %b %r\00"
@.str.2 = [16 x i8] c"ERR: strfime(3)\00"
define i8* @get_current_time() {
%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 %7
6: ; preds = %0
br label %11
7: ; preds = %0
%8 = call i64 @strftime(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %7
br label %11
11: ; preds = %7, %10, %6
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_current_time.output, i64 0, i64 0)
}