#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;
};
struct timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
char *calloc(int, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
char *post_time(const char *fmt, int nano) {
  static char *str = NULL;
  struct timespec ts;
  time_t t;
  struct tm *tmp;
  if (!str)
    str = calloc(32, sizeof(char));
  clock_gettime(CLOCK_REALTIME, &ts);
  t = ts.tv_sec;
  tmp = localtime(&t);
  strftime(str, 32, fmt, tmp);
  if (nano)
    sprintf(str, "%s%09ld", str, ts.tv_nsec);
  return str;
}


x86 assembly (clang, -O0):
<post_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,0x2ee9(%rip)
jne    1183 <post_time+0x33>
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2ecd(%rip)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    0x2ea1(%rip),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x20,%esi
call   1060 <strftime@plt>
cmpl   $0x0,-0xc(%rbp)
je     11e8 <post_time+0x98>
mov    0x2e7e(%rip),%rdi
mov    0x2e77(%rip),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe1d(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2e61(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<post_time>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
cmpq   $0x0,0x2eed(%rip)
jne    117b <post_time+0x2b>
mov    $0x20,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2ed5(%rip)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    0x14(%rsp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    0x2ea9(%rip),%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <strftime@plt>
test   %ebp,%ebp
je     11d5 <post_time+0x85>
mov    0x2e8e(%rip),%rdi
mov    0x10(%rsp),%ecx
lea    0xe33(%rip),%rsi
mov    %rdi,%rdx
call   1070 <sprintf@plt>
mov    0x2e74(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.tm = type { i32 }
@post_time.str = internal global i8* null
@CLOCK_REALTIME = global i32 0
@.str = [8 x i8] c"%s%09ld\00"
define i8* @post_time(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = alloca i32
%7 = alloca %struct.tm*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** @post_time.str
%9 = icmp ne i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = call i8* @calloc(i32 32, i32 1)
store i8* %11, i8** @post_time.str
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* @CLOCK_REALTIME
%14 = call i32 @clock_gettime(i32 %13, %struct.timespec* %5)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%16 = load i32, i32* %15
store i32 %16, i32* %6
%17 = call %struct.tm* @localtime(i32* %6)
store %struct.tm* %17, %struct.tm** %7
%18 = load i8*, i8** @post_time.str
%19 = load i8*, i8** %3
%20 = load %struct.tm*, %struct.tm** %7
%21 = call i32 @strftime(i8* %18, i32 32, i8* %19, %struct.tm* %20)
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %12
%25 = load i8*, i8** @post_time.str
%26 = load i8*, i8** @post_time.str
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %28)
br label %30
30: ; preds = %24, %12
%31 = load i8*, i8** @post_time.str
ret i8* %31
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.tm = type { i32 }
@post_time.str = internal unnamed_addr global i8* null
@CLOCK_REALTIME = global i32 0
@.str = [8 x i8] c"%s%09ld\00"
define i8* @post_time(i8* %0, i32 %1) {
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = load i8*, i8** @post_time.str
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call dereferenceable_or_null(32) i8* @calloc(i32 32, i32 1)
store i8* %10, i8** @post_time.str
br label %11
11: ; preds = %9, %2
%12 = load i32, i32* @CLOCK_REALTIME
%13 = call i32 @clock_gettime(i32 %12, %struct.timespec* %3)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%15 = load i32, i32* %14
store i32 %15, i32* %4
%16 = call %struct.tm* @localtime(i32* %4)
%17 = load i8*, i8** @post_time.str
%18 = call i32 @strftime(i8* %17, i32 32, i8* %0, %struct.tm* %16)
%19 = icmp eq i32 %1, 0
br i1 %19, label %25, label %20
20: ; preds = %11
%21 = load i8*, i8** @post_time.str
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %23)
br label %25
25: ; preds = %20, %11
%26 = load i8*, i8** @post_time.str
ret i8* %26
}