#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 */
double floor(double);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, double, double, double);
char *format_time(double seconds) {
  char *return_value = malloc(32);
  double hours = floor(seconds / 3600.0);
  double minutes = floor(seconds / 60.0) - hours * 60.0;
  seconds = seconds - minutes * 60.0 - hours * 60.0 * 60.0;
  sprintf(return_value, "%02.0f:%02.0f:%02.0f", hours, minutes, seconds);
  return return_value;
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe8d(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe5d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe27(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe17(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xdf3(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm2
lea    0xddc(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movsd  (%rsp),%xmm0
divsd  0xeac(%rip),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
divsd  0xe9c(%rip),%xmm0
call   1050 <floor@plt>
movapd %xmm0,%xmm1
movsd  0xe93(%rip),%xmm3
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm3
addsd  (%rsp),%xmm3
mulsd  0xe68(%rip),%xmm2
addsd  %xmm3,%xmm2
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%02.0f:%02.0f:%02.0f\00"
define i8* @format_time(double %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
store double %0, double* %2
%6 = call i8* @malloc(i32 32)
store i8* %6, i8** %3
%7 = load double, double* %2
%8 = fdiv double %7, 3.600000e+03
%9 = call double @llvm.floor.f64(double %8)
store double %9, double* %4
%10 = load double, double* %2
%11 = fdiv double %10, 6.000000e+01
%12 = call double @llvm.floor.f64(double %11)
%13 = load double, double* %4
%14 = fneg double %13
%15 = call double @llvm.fmuladd.f64(double %14, double 6.000000e+01, double %12)
store double %15, double* %5
%16 = load double, double* %2
%17 = load double, double* %5
%18 = fneg double %17
%19 = call double @llvm.fmuladd.f64(double %18, double 6.000000e+01, double %16)
%20 = load double, double* %4
%21 = fmul double %20, 6.000000e+01
%22 = fneg double %21
%23 = call double @llvm.fmuladd.f64(double %22, double 6.000000e+01, double %19)
store double %23, double* %2
%24 = load i8*, i8** %3
%25 = load double, double* %4
%26 = load double, double* %5
%27 = load double, double* %2
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %25, double %26, double %27)
%29 = load i8*, i8** %3
ret i8* %29
}

LLVM IR (-O2):
@.str = [21 x i8] c"%02.0f:%02.0f:%02.0f\00"
define noalias i8* @format_time(double %0) {
%2 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%3 = fdiv double %0, 3.600000e+03
%4 = tail call double @llvm.floor.f64(double %3)
%5 = fdiv double %0, 6.000000e+01
%6 = tail call double @llvm.floor.f64(double %5)
%7 = fneg double %4
%8 = tail call double @llvm.fmuladd.f64(double %7, double 6.000000e+01, double %6)
%9 = fneg double %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double 6.000000e+01, double %0)
%11 = fmul double %4, -6.000000e+01
%12 = tail call double @llvm.fmuladd.f64(double %11, double 6.000000e+01, double %10)
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %4, double %8, double %12)
ret i8* %2
}