#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 {
  scalar_t__ tm_sec;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};
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);
void z_ms_day_sprint(struct timeval *t, char *buf) {
  struct tm *ti;
  ti = localtime(&t->tv_sec);
  sprintf(buf, "%02d:%02d:%02d.%03d", (int)ti->tm_hour, (int)ti->tm_min,
          (int)ti->tm_sec, (int)(t->tv_usec / 1000));
}


x86 assembly (clang, -O0):
<z_ms_day_sprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    0x10(%rax),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%r8d
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    -0x1c(%rbp),%edx
mov    %eax,%r9d
lea    0xe81(%rip),%rsi
call   1040 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<z_ms_day_sprint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    0x10(%rax),%edx
mov    (%rax),%r8d
mov    0x8(%rax),%ecx
movslq (%rbx),%rax
imul   $0x10624dd3,%rax,%r9
mov    %r9,%rax
shr    $0x3f,%rax
sar    $0x26,%r9
add    %eax,%r9d
lea    0xea5(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i64, i64, i64 }
@.str = [20 x i8] c"%02d:%02d:%02d.%03d\00"
define void @z_ms_day_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 2
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = load %struct.tm*, %struct.tm** %5
%15 = getelementptr inbounds %struct.tm, %struct.tm* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = load %struct.tm*, %struct.tm** %5
%19 = getelementptr inbounds %struct.tm, %struct.tm* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = load %struct.timeval*, %struct.timeval** %3
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = sdiv i32 %24, 1000
%26 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %17, i32 %21, i32 %25)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i64, i64, i64 }
@.str = [20 x i8] c"%02d:%02d:%02d.%03d\00"
define void @z_ms_day_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 2
%6 = load i64, i64* %5
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 1000
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10, i32 %13, i32 %16)
ret void
}