#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 */
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            int);
void get_timestamp(struct timeval *tv, struct tm *tm, char *buff,
                   int buff_size) {
  snprintf(buff, buff_size, "%d-%02d-%02d %02d:%02d:%02d.%03d",
           tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour,
           tm->tm_min, tm->tm_sec, (int)(tv->tv_usec / 1000));
}


x86 assembly (clang, -O0):
<get_timestamp>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %ecx,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%ebx
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r11d
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%r10d
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%r14d
cltd
idiv   %r14d
lea    0xe81(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1030 <snprintf@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_timestamp>:
push   %r15
push   %r14
push   %rbx
mov    $0x76c,%eax
add    (%rsi),%eax
mov    %rdx,%r10
mov    0x4(%rsi),%r8d
mov    0x8(%rsi),%r9d
add    $0x1,%r8d
mov    0xc(%rsi),%r11d
mov    0x10(%rsi),%r14d
mov    0x14(%rsi),%r15d
movslq (%rdi),%rdx
imul   $0x10624dd3,%rdx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rbx
add    %edx,%ebx
lea    0xeab(%rip),%rdx
mov    %r10,%rdi
mov    %ecx,%esi
mov    %eax,%ecx
push   %rbx
push   %r15
push   %r14
push   %r11
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [33 x i8] c"%d-%02d-%02d %02d:%02d:%02d.%03d\00"
define void @get_timestamp(%struct.timeval* nocapture %0, %struct.tm* nocapture %1, i8* %2, i32 %3) {
%5 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = add nsw i32 %6, 1900
%8 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
%11 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 3
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 4
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %1, i64 0, i32 5
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 1000
%22 = tail call i32 @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %12, i32 %14, i32 %16, i32 %18, i32 %21)
ret void
}