#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 tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            int);
char *timestamp() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  time_t t = tv.tv_sec;
  struct tm tm;
  localtime_r(&t, &tm);
  static char ts[32];
  snprintf(ts, 32, "%04d-%02d-%02d %02d:%02d:%02d.%06d", 1900 + tm.tm_year,
           1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
           (int)tv.tv_usec);
  return ts;
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x38(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x34(%rbp),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%r9d
mov    -0x2c(%rbp),%ebx
mov    -0x28(%rbp),%r11d
mov    -0x24(%rbp),%r10d
mov    -0x18(%rbp),%rax
lea    0x2ecc(%rip),%rdi
mov    $0x20,%esi
lea    0xe70(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <snprintf@plt>
lea    0x2ea3(%rip),%rax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0x28(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x30(%rsp),%eax
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x18(%rsp),%r9d
add    $0x1,%r8d
mov    0x1c(%rsp),%r10d
mov    0x20(%rsp),%r11d
mov    0x24(%rsp),%eax
mov    0x28(%rsp),%ebx
lea    0x2ec6(%rip),%r14
lea    0xe6f(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
push   %rbx
push   %rax
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@timestamp.ts = internal global [32 x i8] zeroinitializer
@.str = [35 x i8] c"%04d-%02d-%02d %02d:%02d:%02d.%06d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca %struct.tm
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%6 = load i32, i32* %5
store i32 %6, i32* %2
%7 = call i32 @localtime_r(i32* %2, %struct.tm* %3)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 1900, %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 1, %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i32 0, i32 5
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestamp.ts, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %24)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestamp.ts, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@timestamp.ts = internal global [32 x i8] zeroinitializer
@.str = [35 x i8] c"%04d-%02d-%02d %02d:%02d:%02d.%06d\00"
define i8* @timestamp() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca %struct.tm
%4 = bitcast %struct.timeval* %1 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i32, i32* %7
store i32 %8, i32* %2
%9 = bitcast %struct.tm* %3 to i8*
%10 = call i32 @localtime_r(i32* %2, %struct.tm* %3)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1900
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%26 = load i64, i64* %25
%27 = trunc i64 %26 to i32
%28 = call i32 @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestamp.ts, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %18, i32 %20, i32 %22, i32 %24, i32 %27)
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestamp.ts, i64 0, i64 0)
}