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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int, int);
void z_ms_sprint(struct timeval *t, char *buf) {
  struct tm *ti;
  ti = localtime(&t->tv_sec);
  sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d.%03d", 1900 + ti->tm_year,
          1 + (int)ti->tm_mon, (int)ti->tm_mday, (int)ti->tm_hour,
          (int)ti->tm_min, (int)ti->tm_sec, (int)(t->tv_usec / 1000));
}


x86 assembly (clang, -O0):
<z_ms_sprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x76c,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%rax
mov    %eax,%r8d
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %eax,%r9d
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rax
mov    %eax,%r11d
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%r10d
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    -0x1c(%rbp),%edx
lea    0xe5c(%rip),%rsi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1040 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<z_ms_sprint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    $0x76c,%edx
add    (%rax),%edx
mov    0x28(%rax),%ecx
add    $0x1,%ecx
mov    0x20(%rax),%r8d
mov    0x18(%rax),%r9d
mov    0x8(%rax),%r10d
mov    0x10(%rax),%eax
movslq (%rbx),%rsi
imul   $0x10624dd3,%rsi,%rbx
mov    %rbx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rbx
add    %esi,%ebx
sub    $0x8,%rsp
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
push   %rbx
push   %r10
push   %rax
call   1040 <sprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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