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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char *, int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *print_time(char *buf, size_t bufsize) {
  int millisec;
  struct tm *tm_info;
  struct timeval tv;
  char temp[10];
  gettimeofday(&tv, NULL);
  millisec = tv.tv_usec / 1000.0;
  if (millisec >= 1000) {
    millisec -= 1000;
    tv.tv_sec++;
  }
  tm_info = localtime(&tv.tv_sec);
  strftime(temp, 10, "%H:%M:%S", tm_info);
  snprintf(buf, bufsize, "%s.%03d", temp, millisec);
  return buf;
}


x86 assembly (clang, -O0):
<print_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xe96(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jl     1196 <print_time+0x56>
mov    -0x14(%rbp),%eax
sub    $0x3e8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
add    $0x8,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
lea    -0x3a(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0xa,%esi
lea    0xe4d(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x3a(%rbp),%rcx
mov    -0x14(%rbp),%r8d
lea    0xe3a(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe96(%rip),%xmm0
cvttsd2si %xmm0,%ebp
cmp    $0x3e8,%ebp
jl     1181 <print_time+0x41>
add    $0xfffffc18,%ebp
addl   $0x1,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe76(%rip),%rdx
lea    0x1e(%rsp),%r15
mov    %r15,%rdi
mov    $0xa,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
lea    0xe63(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rcx
mov    %ebp,%r8d
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
%struct.timeval = type { double, i32 }
@.str = [9 x i8] c"%H:%M:%S\00"
@.str.1 = [8 x i8] c"%s.%03d\00"
define i8* @print_time(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.tm*
%7 = alloca %struct.timeval
%8 = alloca [10 x i8]
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%11 = load double, double* %10
%12 = fdiv double %11, 1.000000e+03
%13 = fptosi double %12 to i32
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 1000
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* %5
%18 = sub nsw i32 %17, 1000
store i32 %18, i32* %5
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
br label %22
22: ; preds = %16, %2
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%24 = call %struct.tm* @localtime(i32* %23)
store %struct.tm* %24, %struct.tm** %6
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%26 = load %struct.tm*, %struct.tm** %6
%27 = call i32 @strftime(i8* %25, i32 10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %26)
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* %5
%32 = call i32 @snprintf(i8* %28, i64 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
%struct.tm = type { i32 }
@.str = [9 x i8] c"%H:%M:%S\00"
@.str.1 = [8 x i8] c"%s.%03d\00"
define i8* @print_time(i8* returned %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca [10 x i8]
%5 = bitcast %struct.timeval* %3 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load double, double* %8
%10 = fdiv double %9, 1.000000e+03
%11 = fptosi double %10 to i32
%12 = icmp sgt i32 %11, 999
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = add nsw i32 %11, -1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %15
br label %18
18: ; preds = %13, %2
%19 = phi i32 [ %14, %13 ], [ %11, %2 ]
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%21 = call %struct.tm* @localtime(i32* %20)
%22 = call i32 @strftime(i8* %6, i32 10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %21)
%23 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 %19)
ret i8* %0
}