#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 *, double, ...);
char *Time2StringLong(double time, char *buf) {
  int hour, min;
  double sec;
  hour = (int)(time / 3600.0);
  min = (int)((time - 3600.0 * hour) / 60.0);
  sec = time - 3600.0 * hour - 60.0 * min;
  if (hour != 0)
    sprintf(buf, "%d:%02d:%#.8fh", hour, min, sec);
  else if (min != 0)
    sprintf(buf, "%d:%#.8fm", min, sec);
  else
    sprintf(buf, "%#.8fs", sec);
  return buf;
}


x86 assembly (clang, -O0):
<Time2StringLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeea(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xebd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xeb5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe90(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xe73(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c8 <Time2StringLong+0xb8>
mov    -0x10(%rbp),%rdi
cvtsi2sdl -0x14(%rbp),%xmm0
mov    -0x18(%rbp),%edx
movsd  -0x20(%rbp),%xmm1
lea    0xe64(%rip),%rsi
mov    $0x2,%al
call   1030 <sprintf@plt>
jmp    120f <Time2StringLong+0xff>
cmpl   $0x0,-0x18(%rbp)
je     11f3 <Time2StringLong+0xe3>
mov    -0x10(%rbp),%rdi
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xe48(%rip),%rsi
mov    $0x2,%al
call   1030 <sprintf@plt>
jmp    120a <Time2StringLong+0xfa>
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
lea    0xe36(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    120f <Time2StringLong+0xff>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Time2StringLong>:
push   %rbx
movapd %xmm0,%xmm1
divsd  0xee3(%rip),%xmm0
cvttsd2si %xmm0,%eax
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
mov    %rdi,%rbx
movsd  0xed4(%rip),%xmm3
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
movapd %xmm3,%xmm1
divsd  0xec8(%rip),%xmm1
cvttsd2si %xmm1,%edx
cvttpd2dq %xmm1,%xmm1
cvtdq2pd %xmm1,%xmm2
movsd  0xebc(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
test   %eax,%eax
je     117b <Time2StringLong+0x6b>
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%al
call   1030 <sprintf@plt>
jmp    11ab <Time2StringLong+0x9b>
test   %edx,%edx
je     1196 <Time2StringLong+0x86>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
movapd %xmm2,%xmm0
mov    $0x2,%al
call   1030 <sprintf@plt>
jmp    11ab <Time2StringLong+0x9b>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"%d:%02d:%#.8fh\00"
@.str.1 = [10 x i8] c"%d:%#.8fm\00"
@.str.2 = [7 x i8] c"%#.8fs\00"
define i8* @Time2StringLong(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 = icmp eq i32 %4, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %5, i32 %8, double %10)
br label %20
14: ; preds = %2
%15 = icmp eq i32 %8, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %9, double %10)
br label %20
18: ; preds = %14
%19 = tail call i32 (i8*, i8*, double, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %10)
br label %20
20: ; preds = %16, %18, %12
ret i8* %1
}