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

/* Variables and functions */
int /*<<< orphan*/ gen_tm(int /*<<< orphan*/ *, struct tm *);
size_t snprintf(char *, size_t, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                int /*<<< orphan*/, unsigned int);
size_t fmt_tstamp_time(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" + 15),
                  tm.tm_hour, tm.tm_min, tm.tm_sec, (unsigned)usec);
}


x86 assembly (clang, -O0):
<fmt_tstamp_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x14(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <gen_tm@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x20(%rbp),%rax
lea    0xe9e(%rip),%rdx
add    $0xf,%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_tstamp_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gen_tm@plt>
mov    0x18(%rsp),%ecx
mov    0x10(%rsp),%r9d
mov    0x14(%rsp),%r8d
mov    %r15d,(%rsp)
lea    0xeb1(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [35 x i8] c"%04u-%02u-%02u %02u:%02u:%02u.%06u\00"
define i64 @fmt_tstamp_time(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 2
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i64, i64* %8
%20 = trunc i64 %19 to i32
%21 = call i64 @snprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 15), i32 %14, i32 %16, i32 %18, i32 %20)
ret i64 %21
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [35 x i8] c"%04u-%02u-%02u %02u:%02u:%02u.%06u\00"
define i64 @fmt_tstamp_time(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 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%14 = load i32, i32* %13
%15 = trunc i64 %3 to i32
%16 = call i64 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 15), i32 %10, i32 %12, i32 %14, i32 %15)
ret i64 %16
}