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

/* Variables and functions */
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
size_t ulz_snprintf(char *, size_t, char *, scalar_t__, scalar_t__,
                    int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
                    int /*<<< orphan*/);
size_t timestamp(char *buffer, size_t bufsize) {
  time_t secs = time(NULL);
  struct tm tim;
  localtime_r(&secs, &tim);
  return ulz_snprintf(buffer, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
                      1900 + tim.tm_year, tim.tm_mon + 1, tim.tm_mday,
                      tim.tm_hour, tim.tm_min, tim.tm_sec);
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
add    $0x76c,%rcx
mov    -0x28(%rbp),%r8
add    $0x1,%r8
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%r11d
mov    -0x34(%rbp),%r10d
mov    -0x38(%rbp),%eax
lea    0xe76(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <ulz_snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x28(%rsp),%rcx
mov    0x20(%rsp),%r8
add    $0x1,%r8
mov    0x1c(%rsp),%r9d
mov    0x18(%rsp),%r10d
mov    0x10(%rsp),%ebx
mov    0x14(%rsp),%eax
sub    $0x8,%rsp
lea    0xe77(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
push   %rbx
push   %rax
push   %r10
call   1050 <ulz_snprintf@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
@.str = [30 x i8] c"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\00"
define i64 @timestamp(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = bitcast %struct.tm* %4 to i8*
%8 = call i32 @localtime_r(i32* %3, %struct.tm* %4)
%9 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%10 = load i64, i64* %9
%11 = add nsw i64 %10, 1900
%12 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%13 = load i64, i64* %12
%14 = add nsw i64 %13, 1
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @ulz_snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %11, i64 %14, i32 %16, i32 %18, i32 %20, i32 %22)
ret i64 %23
}