#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, int, ...);
char *Time2String(double time, char *buf) {
  int hour, min, secFull, sec100;
  double sec;
  hour = (int)(time / 3600.0);
  min = (int)((time - 3600.0 * hour) / 60.0);
  sec = time - 3600.0 * hour - 60.0 * min;
  secFull = (int)sec;
  sec100 = (int)((sec - secFull) * 100.0);
  if (hour != 0)
    sprintf(buf, "%d:%02d:%02d.%02dh", hour, min, secFull, sec100);
  else if (min != 0)
    sprintf(buf, "%d:%02d.%02dm", min, secFull, sec100);
  else
    sprintf(buf, "%d.%02ds", secFull, sec100);
  return buf;
}


x86 assembly (clang, -O0):
<Time2String>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xef2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xec5(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xebd(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe98(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe7b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvttsd2si -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe48(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f2 <Time2String+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    123a <Time2String+0x12a>
cmpl   $0x0,-0x18(%rbp)
je     121d <Time2String+0x10d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1235 <Time2String+0x125>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    123a <Time2String+0x12a>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Time2String>:
push   %rbx
movapd %xmm0,%xmm1
divsd  0xee3(%rip),%xmm1
cvttsd2si %xmm1,%edx
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
mulsd  0xed7(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
divsd  0xecf(%rip),%xmm0
cvttsd2si %xmm0,%ecx
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
mulsd  0xec3(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r8d
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
subsd  %xmm1,%xmm0
mulsd  0xeae(%rip),%xmm0
mov    %rdi,%rbx
cvttsd2si %xmm0,%r9d
test   %edx,%edx
je     1191 <Time2String+0x81>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c7 <Time2String+0xb7>
test   %ecx,%ecx
je     11b0 <Time2String+0xa0>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11c7 <Time2String+0xb7>
lea    0xe92(%rip),%rsi
mov    %rbx,%rdi
mov    %r8d,%edx
mov    %r9d,%ecx
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"%d:%02d:%02d.%02dh\00"
@.str.1 = [14 x i8] c"%d:%02d.%02dm\00"
@.str.2 = [9 x i8] c"%d.%02ds\00"
define i8* @Time2String(double %0, i8* %1) {
%3 = alloca double
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double %0, double* %3
store i8* %1, i8** %4
%10 = load double, double* %3
%11 = fdiv double %10, 3.600000e+03
%12 = fptosi double %11 to i32
store i32 %12, i32* %5
%13 = load double, double* %3
%14 = load i32, i32* %5
%15 = sitofp i32 %14 to double
%16 = call double @llvm.fmuladd.f64(double -3.600000e+03, double %15, double %13)
%17 = fdiv double %16, 6.000000e+01
%18 = fptosi double %17 to i32
store i32 %18, i32* %6
%19 = load double, double* %3
%20 = load i32, i32* %5
%21 = sitofp i32 %20 to double
%22 = call double @llvm.fmuladd.f64(double -3.600000e+03, double %21, double %19)
%23 = load i32, i32* %6
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double -6.000000e+01, double %24, double %22)
store double %25, double* %9
%26 = load double, double* %9
%27 = fptosi double %26 to i32
store i32 %27, i32* %7
%28 = load double, double* %9
%29 = load i32, i32* %7
%30 = sitofp i32 %29 to double
%31 = fsub double %28, %30
%32 = fmul double %31, 1.000000e+02
%33 = fptosi double %32 to i32
store i32 %33, i32* %8
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %2
%37 = load i8*, i8** %4
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = load i32, i32* %8
%42 = call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39, i32 %40, i32 %41)
br label %58
43: ; preds = %2
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %43
%47 = load i8*, i8** %4
%48 = load i32, i32* %6
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %48, i32 %49, i32 %50)
br label %57
52: ; preds = %43
%53 = load i8*, i8** %4
%54 = load i32, i32* %7
%55 = load i32, i32* %8
%56 = call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %54, i32 %55)
br label %57
57: ; preds = %52, %46
br label %58
58: ; preds = %57, %36
%59 = load i8*, i8** %4
ret i8* %59
}

LLVM IR (-O2):
@.str = [19 x i8] c"%d:%02d:%02d.%02dh\00"
@.str.1 = [14 x i8] c"%d:%02d.%02dm\00"
@.str.2 = [9 x i8] c"%d.%02ds\00"
define i8* @Time2String(double %0, i8* returned writeonly %1) {
%3 = fdiv double %0, 3.600000e+03
%4 = fptosi double %3 to i32
%5 = sitofp i32 %4 to double
%6 = tail call double @llvm.fmuladd.f64(double %5, double -3.600000e+03, double %0)
%7 = fdiv double %6, 6.000000e+01
%8 = fptosi double %7 to i32
%9 = sitofp i32 %8 to double
%10 = tail call double @llvm.fmuladd.f64(double %9, double -6.000000e+01, double %6)
%11 = fptosi double %10 to i32
%12 = sitofp i32 %11 to double
%13 = fsub double %10, %12
%14 = fmul double %13, 1.000000e+02
%15 = fptosi double %14 to i32
%16 = icmp eq i32 %4, 0
br i1 %16, label %19, label %17
17: ; preds = %2
%18 = tail call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %8, i32 %11, i32 %15)
br label %25
19: ; preds = %2
%20 = icmp eq i32 %8, 0
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = tail call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %11, i32 %15)
br label %25
23: ; preds = %19
%24 = tail call i32 (i8*, i8*, i32, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %15)
br label %25
25: ; preds = %21, %23, %17
ret i8* %1
}