#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 Print(char *, int, ...);
int PrintElapsedTime(long long time) {
  if (time < 1000) {
    return Print("%8lld us", time);
  }
  double msTime = (double)time / 1000;
  if (msTime < 1000) {
    return Print("% 8.3f ms", msTime);
  }
  double seconds = msTime / 1000;
  if (seconds < 60) {
    return Print("% 8.3f s", seconds);
  }
  int minutes = (int)seconds / 60;
  seconds = seconds - (minutes * 60);
  int hours = minutes / 60;
  minutes = minutes % 60;
  return Print("%02d:%02d:%06.3f", hours, minutes, seconds);
}


x86 assembly (clang, -O0):
<PrintElapsedTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x3e8,-0x10(%rbp)
jge    1146 <PrintElapsedTime+0x36>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <Print@plt>
mov    %eax,-0x4(%rbp)
jmp    122d <PrintElapsedTime+0x11d>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xeac(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe9b(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    118b <PrintElapsedTime+0x7b>
cvttsd2si -0x18(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <Print@plt>
mov    %eax,-0x4(%rbp)
jmp    122d <PrintElapsedTime+0x11d>
movsd  -0x18(%rbp),%xmm0
movsd  0xe68(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe5f(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11cf <PrintElapsedTime+0xbf>
cvttsd2si -0x20(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <Print@plt>
mov    %eax,-0x4(%rbp)
jmp    122d <PrintElapsedTime+0x11d>
cvttsd2si -0x20(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
imul   $0x3c,-0x24(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xe09(%rip),%rdi
mov    $0x1,%al
call   1030 <Print@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintElapsedTime>:
mov    %rdi,%rsi
cmp    $0x3e7,%rdi
jg     112a <PrintElapsedTime+0x1a>
lea    0xeed(%rip),%rdi
xor    %eax,%eax
jmp    1030 <Print@plt>
cvtsi2sd %rsi,%xmm0
movsd  0xec9(%rip),%xmm1
divsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm1
jbe    1153 <PrintElapsedTime+0x43>
cvttsd2si %xmm0,%esi
lea    0xecd(%rip),%rdi
xor    %eax,%eax
jmp    1030 <Print@plt>
divsd  0xea5(%rip),%xmm0
movsd  0xea5(%rip),%xmm1
ucomisd %xmm0,%xmm1
cvttsd2si %xmm0,%eax
jbe    117d <PrintElapsedTime+0x6d>
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
jmp    1030 <Print@plt>
movslq %eax,%rcx
imul   $0xffffffff88888889,%rcx,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x5,%edx
add    %esi,%edx
imul   $0x3c,%edx,%esi
xorps  %xmm1,%xmm1
cvtsi2sd %esi,%xmm1
subsd  %xmm1,%xmm0
imul   $0xffffffff91a2b3c5,%rcx,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%eax
shr    $0x1f,%eax
sar    $0xb,%esi
add    %eax,%esi
movslq %edx,%rdx
imul   $0xffffffff88888889,%rdx,%rax
shr    $0x20,%rax
add    %edx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%edx
lea    0xe4a(%rip),%rdi
mov    $0x1,%al
jmp    1030 <Print@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%8lld us\00"
@.str.1 = [10 x i8] c"% 8.3f ms\00"
@.str.2 = [9 x i8] c"% 8.3f s\00"
@.str.3 = [17 x i8] c"%02d:%02d:%06.3f\00"
define i32 @PrintElapsedTime(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store i64 %0, i64* %3
%8 = load i64, i64* %3
%9 = icmp slt i64 %8, 1000
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i64, i64* %3
%12 = trunc i64 %11 to i32
%13 = call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %2
br label %50
14: ; preds = %1
%15 = load i64, i64* %3
%16 = sitofp i64 %15 to double
%17 = fdiv double %16, 1.000000e+03
store double %17, double* %4
%18 = load double, double* %4
%19 = fcmp olt double %18, 1.000000e+03
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load double, double* %4
%22 = fptosi double %21 to i32
%23 = call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 %23, i32* %2
br label %50
24: ; preds = %14
%25 = load double, double* %4
%26 = fdiv double %25, 1.000000e+03
store double %26, double* %5
%27 = load double, double* %5
%28 = fcmp olt double %27, 6.000000e+01
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load double, double* %5
%31 = fptosi double %30 to i32
%32 = call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %31)
store i32 %32, i32* %2
br label %50
33: ; preds = %24
%34 = load double, double* %5
%35 = fptosi double %34 to i32
%36 = sdiv i32 %35, 60
store i32 %36, i32* %6
%37 = load double, double* %5
%38 = load i32, i32* %6
%39 = mul nsw i32 %38, 60
%40 = sitofp i32 %39 to double
%41 = fsub double %37, %40
store double %41, double* %5
%42 = load i32, i32* %6
%43 = sdiv i32 %42, 60
store i32 %43, i32* %7
%44 = load i32, i32* %6
%45 = srem i32 %44, 60
store i32 %45, i32* %6
%46 = load i32, i32* %7
%47 = load i32, i32* %6
%48 = load double, double* %5
%49 = call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %47, double %48)
store i32 %49, i32* %2
br label %50
50: ; preds = %33, %29, %20, %10
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [9 x i8] c"%8lld us\00"
@.str.1 = [10 x i8] c"% 8.3f ms\00"
@.str.2 = [9 x i8] c"% 8.3f s\00"
@.str.3 = [17 x i8] c"%02d:%02d:%06.3f\00"
define i32 @PrintElapsedTime(i64 %0) {
%2 = icmp slt i64 %0, 1000
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = trunc i64 %0 to i32
%5 = tail call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %27
6: ; preds = %1
%7 = sitofp i64 %0 to double
%8 = fdiv double %7, 1.000000e+03
%9 = fcmp olt double %8, 1.000000e+03
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = fptosi double %8 to i32
%12 = tail call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %27
13: ; preds = %6
%14 = fdiv double %8, 1.000000e+03
%15 = fcmp olt double %14, 6.000000e+01
%16 = fptosi double %14 to i32
br i1 %15, label %17, label %19
17: ; preds = %13
%18 = tail call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %27
19: ; preds = %13
%20 = sdiv i32 %16, 60
%21 = mul nsw i32 %20, 60
%22 = sitofp i32 %21 to double
%23 = fsub double %14, %22
%24 = sdiv i32 %16, 3600
%25 = srem i32 %20, 60
%26 = tail call i32 (i8*, i32, ...) @Print(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %25, double %23)
br label %27
27: ; preds = %10, %19, %17, %3
%28 = phi i32 [ %5, %3 ], [ %12, %10 ], [ %18, %17 ], [ %26, %19 ]
ret i32 %28
}