#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 */
struct tm *localtime(int /*<<< orphan*/ *);
size_t strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *currTime() {
  static char buf[(1024)];
  time_t t;
  size_t s;
  struct tm *tm;
  t = time(NULL);
  tm = localtime(&t);
  if (tm == NULL)
    return NULL;
  s = strftime(buf, (1024), "%Y-%m-%d %H:%M:%S", tm);
  return (s == 0) ? NULL : buf;
}


x86 assembly (clang, -O0):
<currTime>:
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,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1169 <currTime+0x39>
movq   $0x0,-0x8(%rbp)
jmp    11a2 <currTime+0x72>
mov    -0x20(%rbp),%rcx
lea    0x2edc(%rip),%rdi
mov    $0x400,%esi
lea    0xe80(%rip),%rdx
call   1050 <strftime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdx
lea    0x2ebc(%rip),%rax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<currTime>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     1176 <currTime+0x46>
lea    0x2ef8(%rip),%rbx
lea    0xea1(%rip),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@currTime.buf = internal global [1024 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define i8* @currTime() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i64
%4 = alloca %struct.tm*
%5 = call i32 @time(i32* null)
store i32 %5, i32* %2
%6 = call %struct.tm* @localtime(i32* %2)
store %struct.tm* %6, %struct.tm** %4
%7 = load %struct.tm*, %struct.tm** %4
%8 = icmp eq %struct.tm* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i8* null, i8** %1
br label %17
10: ; preds = %0
%11 = load %struct.tm*, %struct.tm** %4
%12 = call i64 @strftime(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @currTime.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
store i64 %12, i64* %3
%13 = load i64, i64* %3
%14 = icmp eq i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* null, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @currTime.buf, i64 0, i64 0)
store i8* %16, i8** %1
br label %17
17: ; preds = %10, %9
%18 = load i8*, i8** %1
ret i8* %18
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@currTime.buf = internal global [1024 x i8] zeroinitializer
@.str = [18 x i8] c"%Y-%m-%d %H:%M:%S\00"
define i8* @currTime() {
%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 %10, label %6
6: ; preds = %0
%7 = call i64 @strftime(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @currTime.buf, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %4)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8* null, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @currTime.buf, i64 0, i64 0)
br label %10
10: ; preds = %0, %6
%11 = phi i8* [ %9, %6 ], [ null, %0 ]
ret i8* %11
}