#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 const *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *current_time(const char *format) {
  static char buf[256];
  time_t t;
  size_t s;
  struct tm *tm;
  t = time(NULL);
  tm = localtime(&t);
  if (tm == NULL)
    return NULL;
  s = strftime(buf, 256, (format != NULL) ? format : "%c", tm);
  return (s == 0) ? NULL : buf;
}


x86 assembly (clang, -O0):
<current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116d <current_time+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    11cb <current_time+0x9b>
cmpq   $0x0,-0x10(%rbp)
je     1185 <current_time+0x55>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1195 <current_time+0x65>
lea    0xe74(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1195 <current_time+0x65>
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0x2eac(%rip),%rdi
mov    $0x100,%esi
call   1050 <strftime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    0x2e93(%rip),%rax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
test   %rax,%rax
je     117f <current_time+0x4f>
test   %r14,%r14
lea    0xea3(%rip),%rdx
cmovne %r14,%rdx
lea    0x2ee8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rcx
call   1050 <strftime@plt>
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@current_time.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%c\00"
define i8* @current_time(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.tm*
store i8* %0, i8** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %4
%8 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %8, %struct.tm** %6
%9 = load %struct.tm*, %struct.tm** %6
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %26
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load i8*, i8** %3
br label %18
17: ; preds = %12
br label %18
18: ; preds = %17, %15
%19 = phi i8* [ %16, %15 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %17 ]
%20 = load %struct.tm*, %struct.tm** %6
%21 = call i64 @strftime(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @current_time.buf, i64 0, i64 0), i32 256, i8* %19, %struct.tm* %20)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i8* null, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @current_time.buf, i64 0, i64 0)
store i8* %25, i8** %2
br label %26
26: ; preds = %18, %11
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@current_time.buf = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"%c\00"
define i8* @current_time(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @time(i32* null)
store i32 %4, i32* %2
%5 = call %struct.tm* @localtime(i32* %2)
%6 = icmp eq %struct.tm* %5, null
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = icmp eq i8* %0, null
%9 = select i1 %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0
%10 = call i64 @strftime(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @current_time.buf, i64 0, i64 0), i32 256, i8* %9, %struct.tm* %5)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* null, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @current_time.buf, i64 0, i64 0)
br label %13
13: ; preds = %1, %7
%14 = phi i8* [ %12, %7 ], [ null, %1 ]
ret i8* %14
}