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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void convert_time_to_string(struct timeval tv, char *time_buf) {
  time_t sec;
  int msec;
  struct tm *timeinfo;
  char tmp_buf[9];
  sec = tv.tv_sec;
  timeinfo = localtime(&sec);
  msec = tv.tv_usec / 1000;
  strftime(tmp_buf, 9, "%H:%M:%S", timeinfo);
  sprintf(time_buf, "%s:%d", tmp_buf, msec);
}


x86 assembly (clang, -O0):
<convert_time_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
lea    -0x29(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x9,%esi
lea    0xe8b(%rip),%rdx
call   1040 <strftime@plt>
mov    -0x10(%rbp),%rdi
lea    -0x29(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe7d(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_time_to_string>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdi,%rax
shr    $0x20,%rax
mov    %eax,(%rsp)
mov    %rsp,%rdi
call   1030 <localtime@plt>
movslq %ebx,%rcx
imul   $0x10624dd3,%rcx,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rbx
add    %ecx,%ebx
lea    0xe91(%rip),%rdx
lea    0x7(%rsp),%r15
mov    %r15,%rdi
mov    $0x9,%esi
mov    %rax,%rcx
call   1040 <strftime@plt>
lea    0xe7e(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %ebx,%ecx
call   1050 <sprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [9 x i8] c"%H:%M:%S\00"
@.str.1 = [6 x i8] c"%s:%d\00"
define void @convert_time_to_string(i64 %0, i8* %1) {
%3 = alloca %struct.timeval
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm*
%8 = alloca [9 x i8]
%9 = bitcast %struct.timeval* %3 to i64*
store i64 %0, i64* %9
store i8* %1, i8** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%11 = load i32, i32* %10
store i32 %11, i32* %5
%12 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %12, %struct.tm** %7
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
store i32 %15, i32* %6
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%17 = load %struct.tm*, %struct.tm** %7
%18 = call i32 @strftime(i8* %16, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %17)
%19 = load i8*, i8** %4
%20 = getelementptr inbounds [9 x i8], [9 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20, i32 %21)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [9 x i8] c"%H:%M:%S\00"
@.str.1 = [6 x i8] c"%s:%d\00"
define void @convert_time_to_string(i64 %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [9 x i8]
%5 = trunc i64 %0 to i32
%6 = lshr i64 %0, 32
%7 = trunc i64 %6 to i32
%8 = bitcast i32* %3 to i8*
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
store i32 %7, i32* %3
%10 = call %struct.tm* @localtime(i32* %3)
%11 = sdiv i32 %5, 1000
%12 = call i32 @strftime(i8* %9, i32 9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.tm* %10)
%13 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %11)
ret void
}