#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 fabs(double);
int sprintf(char *, char *, char *, int, int, double);
int cmml_npt_snprint(char *buf, int n, double seconds) {
  int hrs, min;
  double sec;
  char *sign;
  sign = (seconds < 0.0) ? "-" : "";
  if (seconds < 0.0)
    seconds = -seconds;
  hrs = (int)(seconds / 3600.0);
  min = (int)((seconds - ((double)hrs * 3600.0)) / 60.0);
  sec = fabs(seconds - ((double)hrs * 3600.0) - ((double)min * 60.0));
  if (sec < 10.0) {
    return sprintf(buf, "%s%d:%0d:0%2.3f", sign, hrs, min, sec);
  } else {
    return sprintf(buf, "%s%d:%02d:%02.3f", sign, hrs, min, sec);
  }
}


x86 assembly (clang, -O0):
<cmml_npt_snprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
xorps  %xmm0,%xmm0
lea    0xefe(%rip),%rax
lea    0xef6(%rip),%rcx
ucomisd %xmm1,%xmm0
cmova  %rcx,%rax
mov    %rax,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1175 <cmml_npt_snprint+0x65>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe5a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe42(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe16(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
cvtsi2sdl -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xde2(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps 0xdeb(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xdba(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1279 <cmml_npt_snprint+0x169>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xdc6(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    129c <cmml_npt_snprint+0x18c>
mov    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
movsd  -0x30(%rbp),%xmm0
lea    0xdae(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmml_npt_snprint>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
lea    0xf19(%rip),%rax
lea    0xf13(%rip),%rdx
cmova  %rax,%rdx
jbe    1134 <cmml_npt_snprint+0x24>
xorpd  0xecc(%rip),%xmm0
movsd  0xee4(%rip),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
cvttsd2si %xmm2,%ecx
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
movsd  0xec8(%rip),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
cvttsd2si %xmm2,%r8d
cvttpd2dq %xmm2,%xmm2
cvtdq2pd %xmm2,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
andpd  0xe8b(%rip),%xmm0
movsd  0xea3(%rip),%xmm1
ucomisd %xmm0,%xmm1
lea    0xea2(%rip),%rax
lea    0xeab(%rip),%rsi
cmova  %rax,%rsi
jmp    1030 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [16 x i8] c"%s%d:%0d:0%2.3f\00"
@.str.3 = [17 x i8] c"%s%d:%02d:%02.3f\00"
define i32 @cmml_npt_snprint(i8* nocapture writeonly %0, i32 %1, double %2) {
%4 = fcmp olt double %2, 0.000000e+00
%5 = select i1 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%6 = fneg double %2
%7 = select i1 %4, double %6, double %2
%8 = fdiv double %7, 3.600000e+03
%9 = fptosi double %8 to i32
%10 = sitofp i32 %9 to double
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double 3.600000e+03, double %7)
%13 = fdiv double %12, 6.000000e+01
%14 = fptosi double %13 to i32
%15 = sitofp i32 %14 to double
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double 6.000000e+01, double %12)
%18 = tail call double @llvm.fabs.f64(double %17)
%19 = fcmp olt double %18, 1.000000e+01
%20 = select i1 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0)
%21 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %20, i8* %5, i32 %9, i32 %14, double %18)
ret i32 %21
}