#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*/ buf;

/* Variables and functions */
double fmod(double, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, double);
const char *format_timestamp(double t) {
  t = ((int)(t * 100)) * 0.01;
  double s = fmod(t, 60);
  int m = (int)(t / 60);
  int h = m / 60 % 99;
  m %= 60;
  static char buf[12];
  snprintf(buf, sizeof(buf), "%02d:%02d:%05.2f", h, m, s);
  return buf;
}


x86 assembly (clang, -O0):
<format_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xedb(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
movsd  0xebe(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    $0x3c,%edi
call   1030 <fmod@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x63,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%r8d
movsd  -0x10(%rbp),%xmm0
lea    0x2e7b(%rip),%rdi
mov    $0xc,%esi
lea    0xe56(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2e63(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_timestamp>:
push   %rbx
sub    $0x10,%rsp
mulsd  0xed3(%rip),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
mulsd  0xecb(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    $0x3c,%edi
call   1030 <fmod@plt>
movapd (%rsp),%xmm1
divsd  0xeb7(%rip),%xmm1
cvttsd2si %xmm1,%eax
movslq %eax,%r8
imul   $0xffffffff88888889,%r8,%rax
shr    $0x20,%rax
add    %r8d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
movslq %eax,%rcx
imul   $0xffffffffa57eb503,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x6,%eax
add    %edx,%eax
imul   $0x63,%eax,%eax
imul   $0x3c,%ecx,%edx
sub    %eax,%ecx
sub    %edx,%r8d
lea    0x2e8d(%rip),%rbx
lea    0xe6d(%rip),%rdx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@format_timestamp.buf = internal global [12 x i8] zeroinitializer
@.str = [17 x i8] c"%02d:%02d:%05.2f\00"
define i8* @format_timestamp(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = fmul double %6, 1.000000e+02
%8 = fptosi double %7 to i32
%9 = sitofp i32 %8 to double
%10 = fmul double %9, 1.000000e-02
store double %10, double* %2
%11 = load double, double* %2
%12 = call double @fmod(double %11, i32 60)
store double %12, double* %3
%13 = load double, double* %2
%14 = fdiv double %13, 6.000000e+01
%15 = fptosi double %14 to i32
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = sdiv i32 %16, 60
%18 = srem i32 %17, 99
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = srem i32 %19, 60
store i32 %20, i32* %4
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = load double, double* %3
%24 = call i32 @snprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @format_timestamp.buf, i64 0, i64 0), i32 12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22, double %23)
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @format_timestamp.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@format_timestamp.buf = internal global [12 x i8] zeroinitializer
@.str = [17 x i8] c"%02d:%02d:%05.2f\00"
define i8* @format_timestamp(double %0) {
%2 = fmul double %0, 1.000000e+02
%3 = fptosi double %2 to i32
%4 = sitofp i32 %3 to double
%5 = fmul double %4, 1.000000e-02
%6 = tail call double @fmod(double %5, i32 60)
%7 = fdiv double %5, 6.000000e+01
%8 = fptosi double %7 to i32
%9 = sdiv i32 %8, 60
%10 = srem i32 %9, 99
%11 = srem i32 %8, 60
%12 = tail call i32 @snprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @format_timestamp.buf, i64 0, i64 0), i32 12, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11, double %6)
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @format_timestamp.buf, i64 0, i64 0)
}