#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
void fprintTimeSeconds(FILE *out, double seconds, int precision) {
  double totalseconds = seconds;
  int hours = seconds / 3600.;
  if (hours > 0) {
    seconds -= hours * 3600;
    fprintf(out, "%dH", hours);
  }
  int minutes = seconds / 60.;
  if (minutes > 0) {
    seconds -= minutes * 60;
    fprintf(out, "%dM", minutes);
  }
  if (hours + minutes > 0) {
    fprintf(out, "%.0fS", seconds);
    fprintf(out, "(%.*fS)", precision, totalseconds);
  } else
    fprintf(out, "%.*fS", precision, totalseconds);
}


x86 assembly (clang, -O0):
<fprintTimeSeconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xec5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    117e <fprintTimeSeconds+0x6e>
imul   $0xe10,-0x24(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11cb <fprintTimeSeconds+0xbb>
imul   $0x3c,-0x28(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
cmp    $0x0,%eax
jle    1210 <fprintTimeSeconds+0x100>
mov    -0x8(%rbp),%rdi
cvttsd2si -0x10(%rbp),%edx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xe1a(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
jmp    122a <fprintTimeSeconds+0x11a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
movsd  -0x20(%rbp),%xmm0
lea    0xe03(%rip),%rsi
mov    $0x1,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprintTimeSeconds>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movapd %xmm0,%xmm1
divsd  0xeda(%rip),%xmm1
mov    %esi,%r14d
mov    %rdi,%r15
cvttsd2si %xmm1,%ebp
movapd %xmm0,%xmm1
test   %ebp,%ebp
movsd  %xmm0,0x10(%rsp)
jle    116e <fprintTimeSeconds+0x5e>
imul   $0xe10,%ebp,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xeb4(%rip),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm0
divsd  0xe8e(%rip),%xmm0
cvttsd2si %xmm0,%ebx
test   %ebx,%ebx
jle    11cd <fprintTimeSeconds+0xbd>
imul   $0x3c,%ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xe77(%rip),%rsi
mov    %r15,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
add    %ebp,%ebx
jle    11d7 <fprintTimeSeconds+0xc7>
cvttsd2si 0x8(%rsp),%edx
lea    0xe5e(%rip),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe53(%rip),%rsi
jmp    11de <fprintTimeSeconds+0xce>
movsd  %xmm1,0x8(%rsp)
add    %ebp,%ebx
jg     11ad <fprintTimeSeconds+0x9d>
lea    0xe48(%rip),%rsi
mov    %r15,%rdi
mov    %r14d,%edx
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%dH\00"
@.str.1 = [4 x i8] c"%dM\00"
@.str.2 = [6 x i8] c"%.0fS\00"
@.str.3 = [8 x i8] c"(%.*fS)\00"
@.str.4 = [6 x i8] c"%.*fS\00"
define void @fprintTimeSeconds(i32* nocapture %0, double %1, i32 %2) {
%4 = fdiv double %1, 3.600000e+03
%5 = fptosi double %4 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = mul nsw i32 %5, 3600
%9 = sitofp i32 %8 to double
%10 = fsub double %1, %9
%11 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %12
12: ; preds = %7, %3
%13 = phi double [ %10, %7 ], [ %1, %3 ]
%14 = fdiv double %13, 6.000000e+01
%15 = fptosi double %14 to i32
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = mul nsw i32 %15, 60
%19 = sitofp i32 %18 to double
%20 = fsub double %13, %19
%21 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %22
22: ; preds = %17, %12
%23 = phi double [ %20, %17 ], [ %13, %12 ]
%24 = add nsw i32 %15, %5
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = fptosi double %23 to i32
%28 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22, %26
%30 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %22 ]
%31 = tail call i32 (i32*, i8*, i32, ...) @fprintf(i32* %0, i8* %30, i32 %2, double %1)
ret void
}