#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 /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
char *timestring(int ms) {
  int h = 0, m = 0, s = 0;
  static char t[32];
  while (ms > 3600000) {
    h++;
    ms -= 3600000;
  }
  while (ms > 60000) {
    m++;
    ms -= 60000;
  }
  while (ms > 1000) {
    s++;
    ms -= 1000;
  }
  if (h) {
    snprintf(t, 31, "%d:%02d:%02d", h, m, s);
  } else if (m) {
    snprintf(t, 31, "%02d:%02d", m, s);
  } else {
    snprintf(t, 31, "%ds", s);
  }
  return t;
}


x86 assembly (clang, -O0):
<timestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x36ee80,-0x4(%rbp)
jle    1156 <timestring+0x46>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x36ee80,%eax
mov    %eax,-0x4(%rbp)
jmp    1130 <timestring+0x20>
jmp    115b <timestring+0x4b>
cmpl   $0xea60,-0x4(%rbp)
jle    1181 <timestring+0x71>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
sub    $0xea60,%eax
mov    %eax,-0x4(%rbp)
jmp    115b <timestring+0x4b>
jmp    1186 <timestring+0x76>
cmpl   $0x3e8,-0x4(%rbp)
jle    11ac <timestring+0x9c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x3e8,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <timestring+0x76>
cmpl   $0x0,-0x8(%rbp)
je     11e0 <timestring+0xd0>
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0x2e78(%rip),%rdi
mov    $0x1f,%esi
lea    0xe2c(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1232 <timestring+0x122>
cmpl   $0x0,-0xc(%rbp)
je     1210 <timestring+0x100>
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0x2e48(%rip),%rdi
mov    $0x1f,%esi
lea    0xdff(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122d <timestring+0x11d>
mov    -0x10(%rbp),%ecx
lea    0x2e26(%rip),%rdi
mov    $0x1f,%esi
lea    0xde7(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1232 <timestring+0x122>
lea    0x2e07(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestring>:
xor    %r8d,%r8d
cmp    $0x36ee81,%edi
jl     115a <timestring+0x4a>
cmp    $0x6ddd00,%edi
mov    $0x6ddd00,%eax
cmovl  %edi,%eax
neg    %eax
add    %edi,%eax
add    $0x36ee7f,%eax
mov    $0x95217cb1,%ecx
imul   %rax,%rcx
shr    $0x35,%rcx
imul   $0xffc91180,%ecx,%eax
add    $0x1,%ecx
add    %eax,%edi
add    $0xffc91180,%edi
cmp    $0xea61,%edi
jge    1164 <timestring+0x54>
jmp    1199 <timestring+0x89>
xor    %ecx,%ecx
cmp    $0xea61,%edi
jl     1199 <timestring+0x89>
cmp    $0x1d4c0,%edi
mov    $0x1d4c0,%eax
cmovl  %edi,%eax
neg    %eax
add    %edi,%eax
add    $0xea5f,%eax
imul   $0x45e7b273,%rax,%r8
shr    $0x2e,%r8
imul   $0xffff15a0,%r8d,%eax
add    $0x1,%r8d
add    %eax,%edi
add    $0xffff15a0,%edi
xor    %r9d,%r9d
cmp    $0x3e9,%edi
jl     11ca <timestring+0xba>
cmp    $0x7d0,%edi
mov    $0x7d0,%eax
cmovl  %edi,%eax
neg    %eax
add    %edi,%eax
add    $0x3e7,%eax
imul   $0x10624dd3,%rax,%r9
shr    $0x26,%r9
add    $0x1,%r9d
push   %rax
lea    0x2e6e(%rip),%rdi
test   %ecx,%ecx
je     11eb <timestring+0xdb>
lea    0xe23(%rip),%rdx
mov    $0x1f,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1221 <timestring+0x111>
test   %r8d,%r8d
je     120b <timestring+0xfb>
lea    0xe0c(%rip),%rdx
mov    $0x1f,%esi
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1221 <timestring+0x111>
lea    0xdfb(%rip),%rdx
mov    $0x1f,%esi
mov    %r9d,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2e18(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@timestring.t = internal global [32 x i8] zeroinitializer
@.str = [13 x i8] c"%d:%02d:%02d\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [4 x i8] c"%ds\00"
define i8* @timestring(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %9, %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 3600000
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load i32, i32* %3
%11 = add nsw i32 %10, 1
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 3600000
store i32 %13, i32* %2
br label %6
14: ; preds = %6
br label %15
15: ; preds = %18, %14
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 60000
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = sub nsw i32 %21, 60000
store i32 %22, i32* %2
br label %15
23: ; preds = %15
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 1000
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
%30 = load i32, i32* %2
%31 = sub nsw i32 %30, 1000
store i32 %31, i32* %2
br label %24
32: ; preds = %24
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = load i32, i32* %5
%39 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
br label %51
40: ; preds = %32
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* %4
%45 = load i32, i32* %5
%46 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
br label %50
47: ; preds = %40
%48 = load i32, i32* %5
%49 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %47, %43
br label %51
51: ; preds = %50, %35
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0)
}

LLVM IR (-O2):
@timestring.t = internal global [32 x i8] zeroinitializer
@.str = [13 x i8] c"%d:%02d:%02d\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [4 x i8] c"%ds\00"
define i8* @timestring(i32 %0) {
%2 = icmp sgt i32 %0, 3600000
br i1 %2, label %3, label %12
3: ; preds = %1
%4 = add nuw i32 %0, 3599999
%5 = call i32 @llvm.smin.i32(i32 %0, i32 7200000)
%6 = sub nuw i32 %4, %5
%7 = udiv i32 %6, 3600000
%8 = add nuw nsw i32 %7, 1
%9 = mul nsw i32 %7, -3600000
%10 = add nsw i32 %0, -3600000
%11 = add nsw i32 %9, %10
br label %12
12: ; preds = %3, %1
%13 = phi i32 [ %0, %1 ], [ %11, %3 ]
%14 = phi i32 [ 0, %1 ], [ %8, %3 ]
%15 = icmp sgt i32 %13, 60000
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = add nuw nsw i32 %13, 59999
%18 = call i32 @llvm.smin.i32(i32 %13, i32 120000)
%19 = sub nuw nsw i32 %17, %18
%20 = udiv i32 %19, 60000
%21 = add nuw nsw i32 %20, 1
%22 = mul nsw i32 %20, -60000
%23 = add nsw i32 %13, -60000
%24 = add nsw i32 %22, %23
br label %25
25: ; preds = %16, %12
%26 = phi i32 [ %13, %12 ], [ %24, %16 ]
%27 = phi i32 [ 0, %12 ], [ %21, %16 ]
%28 = icmp sgt i32 %26, 1000
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = add nuw nsw i32 %26, 999
%31 = call i32 @llvm.smin.i32(i32 %26, i32 2000)
%32 = sub nuw nsw i32 %30, %31
%33 = udiv i32 %32, 1000
%34 = add nuw nsw i32 %33, 1
br label %35
35: ; preds = %29, %25
%36 = phi i32 [ 0, %25 ], [ %34, %29 ]
%37 = icmp eq i32 %14, 0
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %27, i32 %36)
br label %46
40: ; preds = %35
%41 = icmp eq i32 %27, 0
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %36)
br label %46
44: ; preds = %40
%45 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %46
46: ; preds = %42, %44, %38
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @timestring.t, i64 0, i64 0)
}