#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 dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, long);
int /*<<< orphan*/ strftime(char *, size_t, char *, struct tm *);
void getTimestamp(const struct timeval *time, char *timestamp, size_t size) {
  time_t sec = time->tv_sec;
  struct tm calendar;
  assert(size >= 25);
  localtime_r(&sec, &calendar);
  strftime(timestamp, size, "%y-%m-%d %H:%M:%S", &calendar);
  sprintf(&timestamp[17], ".%06ld", (long)time->tv_usec);
}


x86 assembly (clang, -O0):
<getTimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x19,-0x18(%rbp)
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe74(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <strftime@plt>
mov    -0x10(%rbp),%rdi
add    $0x11,%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
lea    0xe67(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTimestamp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x8(%rdi),%eax
mov    %eax,0xc(%rsp)
xor    %edi,%edi
cmp    $0x19,%rdx
setae  %dil
call   1040 <assert@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r12
mov    %r12,%rsi
call   1030 <localtime_r@plt>
lea    0xe7d(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rcx
call   1050 <strftime@plt>
add    $0x11,%rbx
mov    (%r15),%rdx
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%y-%m-%d %H:%M:%S\00"
@.str.1 = [7 x i8] c".%06ld\00"
define void @getTimestamp(%struct.timeval* %0, i8* %1, i64 %2) {
%4 = alloca %struct.timeval*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.tm
store %struct.timeval* %0, %struct.timeval** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%11 = load i32, i32* %10
store i32 %11, i32* %7
%12 = load i64, i64* %6
%13 = icmp uge i64 %12, 25
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @localtime_r(i32* %7, %struct.tm* %8)
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 @strftime(i8* %17, i64 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %8)
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 17
%22 = load %struct.timeval*, %struct.timeval** %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %24)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str = [18 x i8] c"%y-%m-%d %H:%M:%S\00"
@.str.1 = [7 x i8] c".%06ld\00"
define void @getTimestamp(%struct.timeval* nocapture %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.tm
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%8 = load i32, i32* %7
store i32 %8, i32* %4
%9 = bitcast %struct.tm* %5 to i8*
%10 = icmp ugt i64 %2, 24
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = call i32 @localtime_r(i32* %4, %struct.tm* %5)
%14 = call i32 @strftime(i8* %1, i64 %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), %struct.tm* %5)
%15 = getelementptr inbounds i8, i8* %1, i64 17
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%17 = load i64, i64* %16
%18 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %17)
ret void
}