#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 */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, size_t, char const *, scalar_t__,
                            scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void timestamp(char *a_result, const char *a_dtformat, size_t a_buffersize) {
  time_t l_time = time(NULL);
  struct tm l_localtime = *localtime(&l_time);
  snprintf(a_result, a_buffersize - 1, a_dtformat, l_localtime.tm_year + 1900,
           l_localtime.tm_mon + 1, l_localtime.tm_mday, l_localtime.tm_hour,
           l_localtime.tm_min, l_localtime.tm_sec);
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x40(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x38(%rbp)
mov    0x10(%rax),%rcx
mov    %rcx,-0x30(%rbp)
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
add    $0x76c,%rcx
mov    -0x30(%rbp),%r8
add    $0x1,%r8
mov    -0x34(%rbp),%r9d
mov    -0x38(%rbp),%r11d
mov    -0x3c(%rbp),%r10d
mov    -0x40(%rbp),%eax
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <snprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%r10d
mov    0x4(%rax),%r11d
mov    0x8(%rax),%r12d
mov    0xc(%rax),%r9d
mov    0x10(%rax),%r8
add    $0xffffffffffffffff,%rbx
mov    $0x76c,%ecx
add    0x18(%rax),%rcx
add    $0x1,%r8
sub    $0x8,%rsp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
push   %r10
push   %r11
push   %r12
call   1040 <snprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
define void @timestamp(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.tm
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = call i32 @time(i32* null)
store i32 %9, i32* %7
%10 = call %struct.tm* @localtime(i32* %7)
%11 = bitcast %struct.tm* %8 to i8*
%12 = bitcast %struct.tm* %10 to i8*
%13 = load i8*, i8** %4
%14 = load i64, i64* %6
%15 = sub i64 %14, 1
%16 = load i8*, i8** %5
%17 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 5
%18 = load i64, i64* %17
%19 = add nsw i64 %18, 1900
%20 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 4
%21 = load i64, i64* %20
%22 = add nsw i64 %21, 1
%23 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 3
%24 = load i32, i32* %23
%25 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 2
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @snprintf(i8* %13, i64 %15, i8* %16, i64 %19, i64 %22, i32 %24, i32 %26, i32 %28, i32 %30)
ret void
}

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