#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, ...);
size_t strlen(char *);
char *sprint_timestamp_short(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 (ts >= 3600)
    sprintf(string, "%d:%02d:%02d", ts / 3600, (ts / 60) % 60, ts % 60);
  else if (ts >= 60)
    sprintf(string, "%d:%02d", ts / 60, ts % 60);
  else
    sprintf(string, "%d", ts);
  if (prec > 0)
    sprintf(&string[strlen(string)], ".%0*d", prec, ti % pm);
  return string;
}


x86 assembly (clang, -O0):
<sprint_timestamp_short>:
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    119e <sprint_timestamp_short+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   1050 <pow@plt>
mov    %eax,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <nearbyint@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,-0x28(%rbp)
cmpl   $0xe10,-0x28(%rbp)
jl     1226 <sprint_timestamp_short+0xe6>
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    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    127f <sprint_timestamp_short+0x13f>
cmpl   $0x3c,-0x28(%rbp)
jl     1265 <sprint_timestamp_short+0x125>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x34(%rbp),%edx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    127a <sprint_timestamp_short+0x13a>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
jmp    127f <sprint_timestamp_short+0x13f>
cmpl   $0x0,-0x14(%rbp)
jle    12c1 <sprint_timestamp_short+0x181>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %edx,%ecx
mov    -0x38(%rbp),%edx
lea    0xd5e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprint_timestamp_short>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1165 <sprint_timestamp_short+0x25>
movb   $0x2d,(%rbx)
xorpd  0xe9b(%rip),%xmm0
movapd %xmm0,(%rsp)
mov    $0xa,%edi
mov    %r15d,%esi
call   1050 <pow@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  (%rsp),%xmm0
call   1040 <nearbyint@plt>
cltd
idiv   %ebp
mov    %edx,%r14d
cmp    $0xe10,%eax
jl     11e0 <sprint_timestamp_short+0xa0>
mov    %eax,%ecx
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
mov    $0x88888889,%esi
imul   %rsi,%rcx
shr    $0x25,%rcx
imul   %rcx,%rsi
shr    $0x25,%rsi
imul   $0x3c,%esi,%esi
imul   $0x3c,%ecx,%edi
sub    %esi,%ecx
sub    %edi,%eax
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %r15d,%r15d
jg     1229 <sprint_timestamp_short+0xe9>
jmp    1249 <sprint_timestamp_short+0x109>
cmp    $0x3c,%eax
jl     1211 <sprint_timestamp_short+0xd1>
movzwl %ax,%ecx
imul   $0x8889,%ecx,%edx
shr    $0x15,%edx
imul   $0x3c,%edx,%ecx
sub    %ecx,%eax
movzwl %ax,%ecx
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %r15d,%r15d
jg     1229 <sprint_timestamp_short+0xe9>
jmp    1249 <sprint_timestamp_short+0x109>
lea    0xe0d(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
test   %r15d,%r15d
jle    1249 <sprint_timestamp_short+0x109>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%rax,%rbx,1),%rdi
lea    0xdec(%rip),%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"%d:%02d:%02d\00"
@.str.1 = [8 x i8] c"%d:%02d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c".%0*d\00"
define i8* @sprint_timestamp_short(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* %9
%33 = icmp sge i32 %32, 3600
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, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %37, i32 %40, i32 %42)
br label %59
44: ; preds = %21
%45 = load i32, i32* %9
%46 = icmp sge i32 %45, 60
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = load i32, i32* %9
%50 = sdiv i32 %49, 60
%51 = load i32, i32* %9
%52 = srem i32 %51, 60
%53 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %52)
br label %58
54: ; preds = %44
%55 = load i8*, i8** %4
%56 = load i32, i32* %9
%57 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %54, %47
br label %59
59: ; preds = %58, %34
%60 = load i32, i32* %6
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %72
62: ; preds = %59
%63 = load i8*, i8** %4
%64 = load i8*, i8** %4
%65 = call i64 @strlen(i8* %64)
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i32, i32* %6
%68 = load i32, i32* %8
%69 = load i32, i32* %10
%70 = srem i32 %68, %69
%71 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %67, i32 %70)
br label %72
72: ; preds = %62, %59
%73 = load i8*, i8** %4
ret i8* %73
}

LLVM IR (-O2):
@.str = [13 x i8] c"%d:%02d:%02d\00"
@.str.1 = [8 x i8] c"%d:%02d\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [6 x i8] c".%0*d\00"
define i8* @sprint_timestamp_short(i8* returned %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 sgt i32 %13, 3599
br i1 %15, label %16, label %22
16: ; preds = %7
%17 = udiv i32 %13, 3600
%18 = udiv i32 %13, 60
%19 = urem i32 %18, 60
%20 = urem i32 %13, 60
%21 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %20)
br label %33
22: ; preds = %7
%23 = icmp sgt i32 %13, 59
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = trunc i32 %13 to i16
%26 = udiv i16 %25, 60
%27 = zext i16 %26 to i32
%28 = urem i16 %25, 60
%29 = zext i16 %28 to i32
%30 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29)
br label %33
31: ; preds = %22
%32 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %33
33: ; preds = %24, %31, %16
%34 = icmp sgt i32 %2, 0
br i1 %34, label %35, label %39
35: ; preds = %33
%36 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %37, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %14)
br label %39
39: ; preds = %35, %33
ret i8* %0
}