#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 floor(double);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char *TimeString(long ms) {
  long second, minute, hour, day;
  char *sign = "";
  static char buf[32];
  if (ms > 0 && ms <= 9900) {
    double tenths = floor(((double)(ms + 99L)) / 100.00);
    snprintf(buf, sizeof(buf) / sizeof(buf[0]), " %03.1f ", tenths / 10.0);
    return buf;
  }
  second = (long)floor(((double)(ms + 999L)) / 1000.0);
  if (second < 0) {
    sign = "-";
    second = -second;
  }
  day = second / (60 * 60 * 24);
  second = second % (60 * 60 * 24);
  hour = second / (60 * 60);
  second = second % (60 * 60);
  minute = second / 60;
  second = second % 60;
  if (day > 0)
    snprintf(buf, sizeof(buf) / sizeof(buf[0]), " %s%ld:%02ld:%02ld:%02ld ",
             sign, day, hour, minute, second);
  else if (hour > 0)
    snprintf(buf, sizeof(buf) / sizeof(buf[0]), " %s%ld:%02ld:%02ld ", sign,
             hour, minute, second);
  else
    snprintf(buf, sizeof(buf) / sizeof(buf[0]), " %s%2ld:%02ld ", sign, minute,
             second);
  return buf;
}


x86 assembly (clang, -O0):
<TimeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xf2c(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    11ae <TimeString+0x8e>
cmpq   $0x26ac,-0x10(%rbp)
jg     11ae <TimeString+0x8e>
mov    -0x10(%rbp),%rax
add    $0x63,%rax
cvtsi2sd %rax,%xmm0
movsd  0xeab(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0x2eb5(%rip),%rdi
mov    $0x20,%esi
lea    0xe81(%rip),%rdx
mov    $0x1,%al
call   1030 <snprintf@plt>
lea    0x2e9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    131e <TimeString+0x1fe>
mov    -0x10(%rbp),%rax
add    $0x3e7,%rax
cvtsi2sd %rax,%xmm0
movsd  0xe3b(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11f7 <TimeString+0xd7>
lea    0xe38(%rip),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    12aa <TimeString+0x18a>
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x20(%rbp),%r10
mov    -0x18(%rbp),%rax
lea    0x2db7(%rip),%rdi
mov    $0x20,%esi
lea    0xd8e(%rip),%rdx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1313 <TimeString+0x1f3>
cmpq   $0x0,-0x28(%rbp)
jle    12e8 <TimeString+0x1c8>
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x18(%rbp),%rax
lea    0x2d74(%rip),%rdi
mov    $0x20,%esi
lea    0xd65(%rip),%rdx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    130e <TimeString+0x1ee>
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    0x2d45(%rip),%rdi
mov    $0x20,%esi
lea    0xd4a(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1313 <TimeString+0x1f3>
lea    0x2d26(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TimeString>:
push   %rax
lea    -0x1(%rdi),%rax
cmp    $0x26ab,%rax
ja     116a <TimeString+0x4a>
add    $0x63,%rdi
cvtsi2sd %rdi,%xmm0
divsd  0xeca(%rip),%xmm0
call   1040 <floor@plt>
divsd  0xec5(%rip),%xmm0
lea    0x2eee(%rip),%rdi
lea    0xebf(%rip),%rdx
mov    $0x20,%esi
mov    $0x1,%al
call   1030 <snprintf@plt>
jmp    1271 <TimeString+0x151>
add    $0x3e7,%rdi
cvtsi2sd %rdi,%xmm0
divsd  0xe82(%rip),%xmm0
call   1040 <floor@plt>
cvttsd2si %xmm0,%rax
mov    %rax,%rsi
neg    %rsi
cmovs  %rax,%rsi
test   %rax,%rax
lea    0xe85(%rip),%rax
lea    0xebc(%rip),%rcx
cmovs  %rax,%rcx
movabs $0xc22e450672894ab7,%rdx
45 2e c2
mov    %rsi,%rax
mul    %rdx
mov    %rdx,%r8
shr    $0x10,%r8
imul   $0x15180,%r8,%rdx
mov    %rsi,%rax
sub    %rdx,%rax
mov    $0x91a2b3c5,%r9d
imul   %rax,%r9
shr    $0x2b,%r9
imul   $0xe10,%r9d,%edx
mov    %eax,%edi
sub    %edx,%edi
imul   $0x8889,%edi,%r10d
shr    $0x15,%r10d
imul   $0x3c,%r10d,%edx
sub    %edx,%edi
movzwl %di,%r11d
cmp    $0x15180,%rsi
jl     121d <TimeString+0xfd>
lea    0x2e37(%rip),%rdi
lea    0xe13(%rip),%rdx
mov    $0x20,%esi
xor    %eax,%eax
push   %r11
push   %r10
jmp    1246 <TimeString+0x126>
cmp    $0xe10,%rax
jb     1251 <TimeString+0x131>
sub    $0x8,%rsp
lea    0x2e10(%rip),%rdi
lea    0xe06(%rip),%rdx
mov    $0x20,%esi
mov    %r9,%r8
mov    %r10,%r9
xor    %eax,%eax
push   %r11
call   1030 <snprintf@plt>
add    $0x10,%rsp
jmp    1271 <TimeString+0x151>
lea    0x2de8(%rip),%rdi
lea    0xdf2(%rip),%rdx
mov    $0x20,%esi
mov    %r10,%r8
mov    %r11,%r9
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2dc8(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@TimeString.buf = internal global [32 x i8] zeroinitializer
@.str.1 = [9 x i8] c" %03.1f \00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [26 x i8] c" %s%ld:%02ld:%02ld:%02ld \00"
@.str.4 = [20 x i8] c" %s%ld:%02ld:%02ld \00"
@.str.5 = [15 x i8] c" %s%2ld:%02ld \00"
define i8* @TimeString(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca double
store i64 %0, i64* %3
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i64, i64* %3
%11 = icmp sgt i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %1
%13 = load i64, i64* %3
%14 = icmp sle i64 %13, 9900
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 99
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 1.000000e+02
%20 = call double @llvm.floor.f64(double %19)
store double %20, double* %9
%21 = load double, double* %9
%22 = fdiv double %21, 1.000000e+01
%23 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %22)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i8** %2
br label %74
24: ; preds = %12, %1
%25 = load i64, i64* %3
%26 = add nsw i64 %25, 999
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, 1.000000e+03
%29 = call double @llvm.floor.f64(double %28)
%30 = fptosi double %29 to i64
store i64 %30, i64* %4
%31 = load i64, i64* %4
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8
%34 = load i64, i64* %4
%35 = sub nsw i64 0, %34
store i64 %35, i64* %4
br label %36
36: ; preds = %33, %24
%37 = load i64, i64* %4
%38 = sdiv i64 %37, 86400
store i64 %38, i64* %7
%39 = load i64, i64* %4
%40 = srem i64 %39, 86400
store i64 %40, i64* %4
%41 = load i64, i64* %4
%42 = sdiv i64 %41, 3600
store i64 %42, i64* %6
%43 = load i64, i64* %4
%44 = srem i64 %43, 3600
store i64 %44, i64* %4
%45 = load i64, i64* %4
%46 = sdiv i64 %45, 60
store i64 %46, i64* %5
%47 = load i64, i64* %4
%48 = srem i64 %47, 60
store i64 %48, i64* %4
%49 = load i64, i64* %7
%50 = icmp sgt i64 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %36
%52 = load i8*, i8** %8
%53 = load i64, i64* %7
%54 = load i64, i64* %6
%55 = load i64, i64* %5
%56 = load i64, i64* %4
%57 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %52, i64 %53, i64 %54, i64 %55, i64 %56)
br label %73
58: ; preds = %36
%59 = load i64, i64* %6
%60 = icmp sgt i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %58
%62 = load i8*, i8** %8
%63 = load i64, i64* %6
%64 = load i64, i64* %5
%65 = load i64, i64* %4
%66 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %62, i64 %63, i64 %64, i64 %65)
br label %72
67: ; preds = %58
%68 = load i8*, i8** %8
%69 = load i64, i64* %5
%70 = load i64, i64* %4
%71 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %68, i64 %69, i64 %70)
br label %72
72: ; preds = %67, %61
br label %73
73: ; preds = %72, %51
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i8** %2
br label %74
74: ; preds = %73, %15
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@TimeString.buf = internal global [32 x i8] zeroinitializer
@.str.1 = [9 x i8] c" %03.1f \00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [26 x i8] c" %s%ld:%02ld:%02ld:%02ld \00"
@.str.4 = [20 x i8] c" %s%ld:%02ld:%02ld \00"
@.str.5 = [15 x i8] c" %s%2ld:%02ld \00"
define i8* @TimeString(i64 %0) {
%2 = add i64 %0, -1
%3 = icmp ult i64 %2, 9900
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = add nuw nsw i64 %0, 99
%6 = sitofp i64 %5 to double
%7 = fdiv double %6, 1.000000e+02
%8 = tail call double @llvm.floor.f64(double %7)
%9 = fdiv double %8, 1.000000e+01
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %9)
br label %41
11: ; preds = %1
%12 = add nsw i64 %0, 999
%13 = sitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+03
%15 = tail call double @llvm.floor.f64(double %14)
%16 = fptosi double %15 to i64
%17 = icmp slt i64 %16, 0
%18 = sub nsw i64 0, %16
%19 = select i1 %17, i64 %18, i64 %16
%20 = select i1 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0)
%21 = urem i64 %19, 86400
%22 = udiv i64 %19, 86400
%23 = trunc i64 %21 to i32
%24 = udiv i32 %23, 3600
%25 = zext i32 %24 to i64
%26 = urem i32 %23, 3600
%27 = trunc i32 %26 to i16
%28 = udiv i16 %27, 60
%29 = zext i16 %28 to i64
%30 = urem i16 %27, 60
%31 = zext i16 %30 to i64
%32 = icmp sgt i64 %19, 86399
br i1 %32, label %33, label %35
33: ; preds = %11
%34 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %20, i64 %22, i64 %25, i64 %29, i64 %31)
br label %41
35: ; preds = %11
%36 = icmp ugt i64 %21, 3599
br i1 %36, label %37, label %39
37: ; preds = %35
%38 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %20, i64 %25, i64 %29, i64 %31)
br label %41
39: ; preds = %35
%40 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %20, i64 %29, i64 %31)
br label %41
41: ; preds = %33, %39, %37, %4
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @TimeString.buf, i64 0, i64 0)
}