#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 nearbyint(double);
int pow(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, ...);
char *sprint_timestamp(char *string, double t, int prec) {
  char *p = string;
  int ti, ts, pm;
  if (t < 0.) {
    p[0] = '-';
    p = &p[1];
    t = -t;
  }
  pm = pow(10., prec);
  ti = nearbyint(t * pm);
  ts = ti / pm;
  if (prec == 0)
    sprintf(string, "%02d:%02d:%02d", ts / 3600, (ts / 60) % 60, ts % 60);
  else
    sprintf(string, "%02d:%02d:%02d.%0*d", ts / 3600, (ts / 60) % 60, ts % 60,
            prec, ti % pm);
  return string;
}


x86 assembly (clang, -O0):
<sprint_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118e <sprint_timestamp+0x5e>
mov    -0x20(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    $0xa,%edi
call   1040 <pow@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <nearbyint@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1213 <sprint_timestamp+0xe3>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x28(%rbp),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    -0x30(%rbp),%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1269 <sprint_timestamp+0x139>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x28(%rbp),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    -0x14(%rbp),%r9d
mov    -0x24(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %edx,%eax
mov    -0x34(%rbp),%edx
lea    0xdb0(%rip),%rsi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_timestamp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1153 <sprint_timestamp+0x23>
movb   $0x2d,(%r14)
xorpd  0xead(%rip),%xmm0
movapd %xmm0,0x10(%rsp)
mov    $0xa,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
mov    %eax,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
call   1030 <nearbyint@plt>
cltd
idiv   %ebx
mov    %edx,%esi
movslq %eax,%r8
imul   $0xffffffff91a2b3c5,%r8,%rdx
shr    $0x20,%rdx
add    %r8d,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0xb,%edx
add    %eax,%edx
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   $0xffffffff88888889,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0x5,%eax
add    %edi,%eax
imul   $0x3c,%eax,%eax
imul   $0x3c,%ecx,%edi
sub    %eax,%ecx
sub    %edi,%r8d
test   %ebp,%ebp
je     11f3 <sprint_timestamp+0xc3>
mov    %esi,(%rsp)
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%r9d
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1204 <sprint_timestamp+0xd4>
lea    0xe16(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%02d:%02d:%02d\00"
@.str.1 = [20 x i8] c"%02d:%02d:%02d.%0*d\00"
define i8* @sprint_timestamp(i8* %0, double %1, i32 %2) {
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store double %1, double* %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
store i8* %11, i8** %7
%12 = load double, double* %5
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 45, i8* %16
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8* %18, i8** %7
%19 = load double, double* %5
%20 = fneg double %19
store double %20, double* %5
br label %21
21: ; preds = %14, %3
%22 = load i32, i32* %6
%23 = call i32 @pow(i32 10, i32 %22)
store i32 %23, i32* %10
%24 = load double, double* %5
%25 = load i32, i32* %10
%26 = sitofp i32 %25 to double
%27 = fmul double %24, %26
%28 = call i32 @nearbyint(double %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = load i32, i32* %10
%31 = sdiv i32 %29, %30
store i32 %31, i32* %9
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %21
%35 = load i8*, i8** %4
%36 = load i32, i32* %9
%37 = sdiv i32 %36, 3600
%38 = load i32, i32* %9
%39 = sdiv i32 %38, 60
%40 = srem i32 %39, 60
%41 = load i32, i32* %9
%42 = srem i32 %41, 60
%43 = call i32 (i8*, i8*, i32, i32, i32, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %37, i32 %40, i32 %42)
br label %58
44: ; preds = %21
%45 = load i8*, i8** %4
%46 = load i32, i32* %9
%47 = sdiv i32 %46, 3600
%48 = load i32, i32* %9
%49 = sdiv i32 %48, 60
%50 = srem i32 %49, 60
%51 = load i32, i32* %9
%52 = srem i32 %51, 60
%53 = load i32, i32* %6
%54 = load i32, i32* %8
%55 = load i32, i32* %10
%56 = srem i32 %54, %55
%57 = call i32 (i8*, i8*, i32, i32, i32, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %47, i32 %50, i32 %52, i32 %53, i32 %56)
br label %58
58: ; preds = %44, %34
%59 = load i8*, i8** %4
ret i8* %59
}

LLVM IR (-O2):
@.str = [15 x i8] c"%02d:%02d:%02d\00"
@.str.1 = [20 x i8] c"%02d:%02d:%02d.%0*d\00"
define i8* @sprint_timestamp(i8* returned writeonly %0, double %1, i32 %2) {
%4 = fcmp olt double %1, 0.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
store i8 45, i8* %0
%6 = fneg double %1
br label %7
7: ; preds = %5, %3
%8 = phi double [ %6, %5 ], [ %1, %3 ]
%9 = tail call i32 @pow(i32 10, i32 %2)
%10 = sitofp i32 %9 to double
%11 = fmul double %8, %10
%12 = tail call i32 @nearbyint(double %11)
%13 = sdiv i32 %12, %9
%14 = srem i32 %12, %9
%15 = icmp eq i32 %2, 0
%16 = sdiv i32 %13, 3600
%17 = sdiv i32 %13, 60
%18 = srem i32 %17, 60
%19 = srem i32 %13, 60
br i1 %15, label %20, label %22
20: ; preds = %7
%21 = tail call i32 (i8*, i8*, i32, i32, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %19)
br label %24
22: ; preds = %7
%23 = tail call i32 (i8*, i8*, i32, i32, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18, i32 %19, i32 %2, i32 %14)
br label %24
24: ; preds = %22, %20
ret i8* %0
}