#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 */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
char *time_string(int time) {
  static char str[16];
  if (time < 60000)
    sprintf(str, "%.3f", (float)time / 1000);
  else if (time < 3600000)
    sprintf(str, "%i:%02i", time / 60000, (time % 60000) / 1000);
  else
    sprintf(str, "%i:%02i:%02i", time / 3600000, (time % 3600000) / 60000,
            (time % 60000) / 1000);
  return str;
}


x86 assembly (clang, -O0):
<time_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xea60,-0x4(%rbp)
jge    1157 <time_string+0x47>
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xecb(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
lea    0x2efc(%rip),%rdi
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1200 <time_string+0xf0>
cmpl   $0x36ee80,-0x4(%rbp)
jge    11a6 <time_string+0x96>
mov    -0x4(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%edx
mov    %eax,%ecx
lea    0x2ead(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11fb <time_string+0xeb>
mov    -0x4(%rbp),%eax
mov    $0x36ee80,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x36ee80,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0xea60,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
mov    -0xc(%rbp),%edx
mov    %eax,%r8d
lea    0x2e53(%rip),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1200 <time_string+0xf0>
lea    0x2e39(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_string>:
push   %rax
cmp    $0xea5f,%edi
jg     1143 <time_string+0x33>
cvtsi2ss %edi,%xmm0
divss  0xedb(%rip),%xmm0
cvttss2si %xmm0,%edx
lea    0x2f10(%rip),%rdi
lea    0xecd(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11e1 <time_string+0xd1>
mov    %edi,%eax
cmp    $0x36ee7f,%edi
ja     1186 <time_string+0x76>
imul   $0x45e7b273,%rax,%rdx
shr    $0x2e,%rdx
imul   $0xea60,%edx,%eax
sub    %eax,%edi
movzwl %di,%eax
shr    $0x3,%eax
imul   $0x20c5,%eax,%ecx
shr    $0x14,%ecx
lea    0x2eca(%rip),%rdi
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11e1 <time_string+0xd1>
mov    $0x95217cb1,%edx
imul   %rax,%rdx
shr    $0x35,%rdx
imul   $0x36ee80,%edx,%ecx
mov    %edi,%esi
sub    %ecx,%esi
imul   $0x45e7b273,%rsi,%rcx
shr    $0x2e,%rcx
imul   $0x45e7b273,%rax,%rax
shr    $0x2e,%rax
imul   $0xea60,%eax,%eax
sub    %eax,%edi
movzwl %di,%eax
shr    $0x3,%eax
imul   $0x20c5,%eax,%r8d
shr    $0x14,%r8d
lea    0x2e6d(%rip),%rdi
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2e58(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@time_string.str = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"%.3f\00"
@.str.1 = [8 x i8] c"%i:%02i\00"
@.str.2 = [13 x i8] c"%i:%02i:%02i\00"
define i8* @time_string(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 60000
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* %2
%7 = sitofp i32 %6 to float
%8 = fdiv float %7, 1.000000e+03
%9 = fptosi float %8 to i32
%10 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %32
11: ; preds = %1
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 3600000
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 60000
%17 = load i32, i32* %2
%18 = srem i32 %17, 60000
%19 = sdiv i32 %18, 1000
%20 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %19)
br label %31
21: ; preds = %11
%22 = load i32, i32* %2
%23 = sdiv i32 %22, 3600000
%24 = load i32, i32* %2
%25 = srem i32 %24, 3600000
%26 = sdiv i32 %25, 60000
%27 = load i32, i32* %2
%28 = srem i32 %27, 60000
%29 = sdiv i32 %28, 1000
%30 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %26, i32 %29)
br label %31
31: ; preds = %21, %14
br label %32
32: ; preds = %31, %5
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0)
}

LLVM IR (-O2):
@time_string.str = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"%.3f\00"
@.str.1 = [8 x i8] c"%i:%02i\00"
@.str.2 = [13 x i8] c"%i:%02i:%02i\00"
define i8* @time_string(i32 %0) {
%2 = icmp slt i32 %0, 60000
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = sitofp i32 %0 to float
%5 = fdiv float %4, 1.000000e+03
%6 = fptosi float %5 to i32
%7 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %26
8: ; preds = %1
%9 = icmp ult i32 %0, 3600000
br i1 %9, label %10, label %17
10: ; preds = %8
%11 = udiv i32 %0, 60000
%12 = urem i32 %0, 60000
%13 = trunc i32 %12 to i16
%14 = udiv i16 %13, 1000
%15 = zext i16 %14 to i32
%16 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %15)
br label %26
17: ; preds = %8
%18 = udiv i32 %0, 3600000
%19 = urem i32 %0, 3600000
%20 = udiv i32 %19, 60000
%21 = urem i32 %0, 60000
%22 = trunc i32 %21 to i16
%23 = udiv i16 %22, 1000
%24 = zext i16 %23 to i32
%25 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %20, i32 %24)
br label %26
26: ; preds = %10, %17, %3
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @time_string.str, i64 0, i64 0)
}