#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 mysprintf(char *, int, char *, scalar_t__, scalar_t__, int /*<<< orphan*/,
              int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void get_timestamp(char *buffer) {
  time_t t;
  struct tm *p;
  int len;
  t = time(NULL);
  p = localtime(&t);
  len = mysprintf(buffer, 22, "[%04d/%02d/%02d %02d:%02d:%02d]",
                  p->tm_year + 1900, p->tm_mon + 1, p->tm_mday, p->tm_hour,
                  p->tm_min, p->tm_sec);
  buffer[len] = '\0';
}


x86 assembly (clang, -O0):
<get_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rcx
add    $0x76c,%rcx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r8
add    $0x1,%r8
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%r11d
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x16,%esi
lea    0xe62(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1050 <mysprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timestamp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
mov    $0x76c,%ecx
add    0x18(%rax),%rcx
mov    0x10(%rax),%r8
add    $0x1,%r8
mov    0xc(%rax),%r9d
mov    0x8(%rax),%r10d
mov    (%rax),%ebx
mov    0x4(%rax),%eax
sub    $0x8,%rsp
lea    0xe8b(%rip),%rdx
mov    %r14,%rdi
mov    $0x16,%esi
push   %rbx
push   %rax
push   %r10
call   1050 <mysprintf@plt>
add    $0x20,%rsp
cltq
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
@.str = [32 x i8] c"[%04d/%02d/%02d %02d:%02d:%02d]\00"
define void @get_timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %7, %struct.tm** %4
%8 = load i8*, i8** %2
%9 = load %struct.tm*, %struct.tm** %4
%10 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 5
%11 = load i64, i64* %10
%12 = add nsw i64 %11, 1900
%13 = load %struct.tm*, %struct.tm** %4
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 4
%15 = load i64, i64* %14
%16 = add nsw i64 %15, 1
%17 = load %struct.tm*, %struct.tm** %4
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 3
%19 = load i32, i32* %18
%20 = load %struct.tm*, %struct.tm** %4
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = load %struct.tm*, %struct.tm** %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.tm*, %struct.tm** %4
%27 = getelementptr inbounds %struct.tm, %struct.tm* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @mysprintf(i8* %8, i32 22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %12, i64 %16, i32 %19, i32 %22, i32 %25, i32 %28)
store i32 %29, i32* %5
%30 = load i8*, i8** %2
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i64, i64 }
@.str = [32 x i8] c"[%04d/%02d/%02d %02d:%02d:%02d]\00"
define void @get_timestamp(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 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 5
%7 = load i64, i64* %6
%8 = add nsw i64 %7, 1900
%9 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 4
%10 = load i64, i64* %9
%11 = add nsw i64 %10, 1
%12 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 3
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @mysprintf(i8* %0, i32 22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %11, i32 %13, i32 %15, i32 %17, i32 %19)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
ret void
}