#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 *duration_to_string(float seconds) {
  static char buffer[1000];
  int hours, minutes;
  if (seconds < 60)
    sprintf(buffer, "%.3fs", seconds);
  else if (seconds < 3600) {
    minutes = seconds / 60;
    seconds -= 60 * minutes;
    sprintf(buffer, "%dm%06.3fs", minutes, seconds);
  } else {
    minutes = seconds / 60;
    seconds -= 60 * minutes;
    hours = minutes / 60;
    minutes -= 60 * hours;
    sprintf(buffer, "%dh%02dm%06.3fs", hours, minutes, seconds);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<duration_to_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xedb(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    114e <duration_to_string+0x3e>
cvttss2si -0x4(%rbp),%edx
lea    0x2f05(%rip),%rdi
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1225 <duration_to_string+0x115>
movss  0xeae(%rip),%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    11b4 <duration_to_string+0xa4>
movss  -0x4(%rbp),%xmm0
movss  0xe93(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
imul   $0x3c,-0xc(%rbp),%eax
cvtsi2ss %eax,%xmm1
movss  -0x4(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0xc(%rbp),%edx
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2e9f(%rip),%rdi
lea    0xe66(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1220 <duration_to_string+0x110>
movss  -0x4(%rbp),%xmm0
movss  0xe3f(%rip),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
imul   $0x3c,-0xc(%rbp),%eax
cvtsi2ss %eax,%xmm1
movss  -0x4(%rbp),%xmm0
subss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
imul   $0x3c,-0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0x2e2e(%rip),%rdi
lea    0xe00(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1225 <duration_to_string+0x115>
lea    0x2e14(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<duration_to_string>:
push   %rax
movss  0xee7(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1139 <duration_to_string+0x29>
cvttss2si %xmm0,%edx
lea    0x2f17(%rip),%rdi
lea    0xed8(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11b8 <duration_to_string+0xa8>
movaps %xmm0,%xmm1
divss  0xebc(%rip),%xmm1
cvttss2si %xmm1,%edx
imul   $0x3c,%edx,%eax
movss  0xeb1(%rip),%xmm1
ucomiss %xmm0,%xmm1
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
jbe    117e <duration_to_string+0x6e>
cvtss2sd %xmm0,%xmm0
lea    0x2ed2(%rip),%rdi
lea    0xe99(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11b8 <duration_to_string+0xa8>
movslq %edx,%rax
imul   $0xffffffff88888889,%rax,%rax
shr    $0x20,%rax
add    %edx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0xffffffc4,%eax,%ecx
add    %edx,%ecx
cvtss2sd %xmm0,%xmm0
lea    0x2e98(%rip),%rdi
lea    0xe6a(%rip),%rsi
mov    %eax,%edx
mov    $0x1,%al
call   1030 <sprintf@plt>
lea    0x2e81(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@duration_to_string.buffer = internal global [1000 x i8] zeroinitializer
@.str = [6 x i8] c"%.3fs\00"
@.str.1 = [11 x i8] c"%dm%06.3fs\00"
@.str.2 = [16 x i8] c"%dh%02dm%06.3fs\00"
define i8* @duration_to_string(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
store float %0, float* %2
%5 = load float, float* %2
%6 = fcmp olt float %5, 6.000000e+01
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load float, float* %2
%9 = fptosi float %8 to i32
%10 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %48
11: ; preds = %1
%12 = load float, float* %2
%13 = fcmp olt float %12, 3.600000e+03
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = load float, float* %2
%16 = fdiv float %15, 6.000000e+01
%17 = fptosi float %16 to i32
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = mul nsw i32 60, %18
%20 = sitofp i32 %19 to float
%21 = load float, float* %2
%22 = fsub float %21, %20
store float %22, float* %2
%23 = load i32, i32* %4
%24 = load float, float* %2
%25 = fpext float %24 to double
%26 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %23, double %25)
br label %47
27: ; preds = %11
%28 = load float, float* %2
%29 = fdiv float %28, 6.000000e+01
%30 = fptosi float %29 to i32
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = mul nsw i32 60, %31
%33 = sitofp i32 %32 to float
%34 = load float, float* %2
%35 = fsub float %34, %33
store float %35, float* %2
%36 = load i32, i32* %4
%37 = sdiv i32 %36, 60
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = mul nsw i32 60, %38
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, %39
store i32 %41, i32* %4
%42 = load i32, i32* %3
%43 = load i32, i32* %4
%44 = load float, float* %2
%45 = fpext float %44 to double
%46 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43, double %45)
br label %47
47: ; preds = %27, %14
br label %48
48: ; preds = %47, %7
ret i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@duration_to_string.buffer = internal global [1000 x i8] zeroinitializer
@.str = [6 x i8] c"%.3fs\00"
@.str.1 = [11 x i8] c"%dm%06.3fs\00"
@.str.2 = [16 x i8] c"%dh%02dm%06.3fs\00"
define i8* @duration_to_string(float %0) {
%2 = fcmp olt float %0, 6.000000e+01
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = fptosi float %0 to i32
%5 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %22
6: ; preds = %1
%7 = fcmp olt float %0, 3.600000e+03
%8 = fdiv float %0, 6.000000e+01
%9 = fptosi float %8 to i32
%10 = mul nsw i32 %9, 60
%11 = sitofp i32 %10 to float
%12 = fsub float %0, %11
br i1 %7, label %13, label %16
13: ; preds = %6
%14 = fpext float %12 to double
%15 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %9, double %14)
br label %22
16: ; preds = %6
%17 = sdiv i32 %9, 60
%18 = mul nsw i32 %17, -60
%19 = add i32 %18, %9
%20 = fpext float %12 to double
%21 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %19, double %20)
br label %22
22: ; preds = %13, %16, %3
ret i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @duration_to_string.buffer, i64 0, i64 0)
}