#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;
typedef scalar_t__ suseconds_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gen_tm(int /*<<< orphan*/ *, struct tm *);
size_t snprintf(char *, size_t, char *, int, int, int, int, int, int,
                unsigned int);
size_t fmt_tstamp_date(char *buf, size_t buf_len, time_t sec,
                       suseconds_t usec) {
  struct tm tm;
  gen_tm(&sec, &tm);
  return snprintf(buf, buf_len, "%04u-%02u-%02u %02u:%02u:%02u.%06u",
                  1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour,
                  tm.tm_min, tm.tm_sec, (unsigned)usec);
}


x86 assembly (clang, -O0):
<fmt_tstamp_date>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1030 <gen_tm@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x3c(%rbp),%r8d
add    $0x1,%r8d
mov    -0x38(%rbp),%r9d
mov    -0x34(%rbp),%ebx
mov    -0x30(%rbp),%r11d
mov    -0x2c(%rbp),%r10d
mov    -0x28(%rbp),%rax
lea    0xe88(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <snprintf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_tstamp_date>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gen_tm@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),%eax
mov    0x24(%rsp),%ebx
lea    0xe8e(%rip),%rdx
mov    %r12,%rdi
mov    %r15,%rsi
push   %r14
push   %rbx
push   %rax
push   %r10
call   1040 <snprintf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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