#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 uint64_t;
typedef int time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ localtime_r(int *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            int);
char *msec_to_timestring(uint64_t msec) {
  static char buf[512];
  time_t t;
  struct tm tm;
  t = msec / 1000;
  localtime_r(&t, &tm);
  snprintf(buf, sizeof(buf), "[%04d/%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)(msec % 1000));
  return buf;
}


x86 assembly (clang, -O0):
<msec_to_timestring>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    -0x28(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x24(%rbp),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%ebx
mov    -0x18(%rbp),%r11d
mov    -0x14(%rbp),%r10d
mov    -0xc(%rbp),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    %edx,%eax
lea    0x2ec5(%rip),%rdi
mov    $0x200,%esi
lea    0xe79(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %eax,0x18(%rsp)
call   1040 <snprintf@plt>
lea    0x2e9c(%rip),%rax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<msec_to_timestring>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movslq %edi,%r15
imul   $0x10624dd3,%r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
mov    %ebx,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    $0x76c,%ecx
add    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
add    $0x1,%r8d
mov    0x14(%rsp),%r10d
mov    0x18(%rsp),%r11d
mov    0x1c(%rsp),%eax
imul   $0x3e8,%ebx,%edx
sub    %edx,%r15d
lea    0x2eb8(%rip),%r14
lea    0xe71(%rip),%rdx
mov    %r14,%rdi
mov    $0x200,%esi
push   %r15
push   %rax
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@msec_to_timestring.buf = internal global [512 x i8] zeroinitializer
@.str = [37 x i8] c"[%04d/%02d/%02d-%02d:%02d:%02d.%03d]\00"
define i8* @msec_to_timestring(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.tm
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = sdiv i32 %5, 1000
store i32 %6, i32* %3
%7 = call i32 @localtime_r(i32* %3, %struct.tm* %4)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 5
%21 = load i32, i32* %20
%22 = load i32, i32* %2
%23 = srem i32 %22, 1000
%24 = call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @msec_to_timestring.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @msec_to_timestring.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@msec_to_timestring.buf = internal global [512 x i8] zeroinitializer
@.str = [37 x i8] c"[%04d/%02d/%02d-%02d:%02d:%02d.%03d]\00"
define i8* @msec_to_timestring(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.tm
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.tm* %3 to i8*
%6 = sdiv i32 %0, 1000
store i32 %6, i32* %2
%7 = call i32 @localtime_r(i32* %2, %struct.tm* %3)
%8 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1900
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1
%14 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 3
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 4
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 5
%21 = load i32, i32* %20
%22 = srem i32 %0, 1000
%23 = call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @msec_to_timestring.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %22)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @msec_to_timestring.buf, i64 0, i64 0)
}