#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 */
char *two_digits(char *, int);
void ASAP_DurationToString(char *s, int duration) {
  if (duration >= 0 && duration < 100 * 60 * 1000) {
    int seconds = duration / 1000;
    s = two_digits(s, seconds / 60);
    *s++ = ':';
    s = two_digits(s, seconds % 60);
    duration %= 1000;
    if (duration != 0) {
      *s++ = '.';
      s = two_digits(s, duration / 10);
      duration %= 10;
      if (duration != 0)
        *s++ = '0' + duration;
    }
  }
  *s = '\0';
}


x86 assembly (clang, -O0):
<ASAP_DurationToString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1209 <ASAP_DurationToString+0xf9>
cmpl   $0x5b8d80,-0xc(%rbp)
jge    1209 <ASAP_DurationToString+0xf9>
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1030 <two_digits@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x3a,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
call   1030 <two_digits@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1204 <ASAP_DurationToString+0xf4>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x2e,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1030 <two_digits@plt>
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ff <ASAP_DurationToString+0xef>
mov    -0xc(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1204 <ASAP_DurationToString+0xf4>
jmp    1209 <ASAP_DurationToString+0xf9>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASAP_DurationToString>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x5b8d7f,%esi
ja     11a5 <ASAP_DurationToString+0x95>
mov    %esi,%ebx
mov    %esi,%ebp
imul   $0x45e7b273,%rbp,%rsi
shr    $0x2e,%rsi
call   1030 <two_digits@plt>
movb   $0x3a,(%rax)
lea    0x1(%rax),%rdi
imul   $0x10624dd3,%rbp,%rbp
shr    $0x26,%rbp
movzwl %bp,%eax
imul   $0x8889,%eax,%eax
shr    $0x15,%eax
imul   $0x3c,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
movzwl %cx,%esi
call   1030 <two_digits@plt>
mov    %rax,%rdi
imul   $0x3e8,%ebp,%eax
sub    %eax,%ebx
je     11a5 <ASAP_DurationToString+0x95>
mov    %rdi,%rax
add    $0x1,%rax
movb   $0x2e,(%rdi)
movzwl %bx,%ebp
imul   $0xcccd,%ebp,%ebx
shr    $0x13,%ebx
mov    %rax,%rdi
mov    %ebx,%esi
call   1030 <two_digits@plt>
mov    %rax,%rdi
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
sub    %ax,%bp
je     11a5 <ASAP_DurationToString+0x95>
or     $0x30,%bpl
mov    %bpl,(%rdi)
add    $0x1,%rdi
movb   $0x0,(%rdi)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @ASAP_DurationToString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %47
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 6000000
br i1 %10, label %11, label %47
11: ; preds = %8
%12 = load i32, i32* %4
%13 = sdiv i32 %12, 1000
store i32 %13, i32* %5
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sdiv i32 %15, 60
%17 = call i8* @two_digits(i8* %14, i32 %16)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %3
store i8 58, i8* %18
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = srem i32 %21, 60
%23 = call i8* @two_digits(i8* %20, i32 %22)
store i8* %23, i8** %3
%24 = load i32, i32* %4
%25 = srem i32 %24, 1000
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %11
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
store i8 46, i8* %29
%31 = load i8*, i8** %3
%32 = load i32, i32* %4
%33 = sdiv i32 %32, 10
%34 = call i8* @two_digits(i8* %31, i32 %33)
store i8* %34, i8** %3
%35 = load i32, i32* %4
%36 = srem i32 %35, 10
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %28
%40 = load i32, i32* %4
%41 = add nsw i32 48, %40
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
store i8 %42, i8* %43
br label %45
45: ; preds = %39, %28
br label %46
46: ; preds = %45, %11
br label %47
47: ; preds = %46, %8, %2
%48 = load i8*, i8** %3
store i8 0, i8* %48
ret void
}

LLVM IR (-O2):
define void @ASAP_DurationToString(i8* %0, i32 %1) {
%3 = icmp ult i32 %1, 6000000
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = udiv i32 %1, 1000
%6 = udiv i32 %1, 60000
%7 = tail call i8* @two_digits(i8* %0, i32 %6)
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 58, i8* %7
%9 = trunc i32 %5 to i16
%10 = urem i16 %9, 60
%11 = zext i16 %10 to i32
%12 = tail call i8* @two_digits(i8* %8, i32 %11)
%13 = urem i32 %1, 1000
%14 = icmp eq i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %4
%16 = getelementptr inbounds i8, i8* %12, i64 1
store i8 46, i8* %12
%17 = trunc i32 %13 to i16
%18 = udiv i16 %17, 10
%19 = zext i16 %18 to i32
%20 = tail call i8* @two_digits(i8* %16, i32 %19)
%21 = urem i16 %17, 10
%22 = icmp eq i16 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %15
%24 = trunc i16 %21 to i8
%25 = or i8 %24, 48
%26 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %25, i8* %20
br label %27
27: ; preds = %4, %23, %15, %2
%28 = phi i8* [ %0, %2 ], [ %26, %23 ], [ %20, %15 ], [ %12, %4 ]
store i8 0, i8* %28
ret void
}