#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*/ sprintf(char *, char *, int, int, int);
int /*<<< orphan*/ strcat(char *, char *);
void format_timeline(char *output, int index) {
  int minute = index / 60000;
  int second = index % 60000 / 1000;
  int frame = index % 60000 % 1000 * 75 / 1000;
  char format[16] = {0};
  if (minute < 10) {
    strcat(format, "0%d:");
  } else {
    strcat(format, "%d:");
  }
  if (second < 10) {
    strcat(format, "0%d:");
  } else {
    strcat(format, "%d:");
  }
  if (frame < 10) {
    strcat(format, "0%d");
  } else {
    strcat(format, "%d");
  }
  sprintf(output, format, minute, second, frame);
}


x86 assembly (clang, -O0):
<format_timeline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x4b,%edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
cmpl   $0xa,-0x10(%rbp)
jge    11b7 <format_timeline+0x87>
lea    -0x30(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1040 <strcat@plt>
jmp    11c7 <format_timeline+0x97>
lea    -0x30(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1040 <strcat@plt>
cmpl   $0xa,-0x14(%rbp)
jge    11e6 <format_timeline+0xb6>
lea    -0x30(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1040 <strcat@plt>
jmp    11f6 <format_timeline+0xc6>
lea    -0x30(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1040 <strcat@plt>
cmpl   $0xa,-0x18(%rbp)
jge    1215 <format_timeline+0xe5>
lea    -0x30(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1040 <strcat@plt>
jmp    1225 <format_timeline+0xf5>
lea    -0x30(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_timeline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x8(%rsp)
movslq %esi,%rax
imul   $0x45e7b273,%rax,%r15
mov    %r15,%rcx
shr    $0x3f,%rcx
sar    $0x2e,%r15
add    %ecx,%r15d
imul   $0xea60,%r15d,%ecx
mov    %eax,%edx
sub    %ecx,%edx
movslq %edx,%r14
imul   $0x10624dd3,%r14,%r13
mov    %r13,%rcx
shr    $0x3f,%rcx
sar    $0x26,%r13
add    %ecx,%r13d
imul   $0x3e8,%r13d,%ecx
mov    %r14d,%edx
sub    %ecx,%edx
imul   $0x4b,%edx,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
cmp    $0x927c0,%eax
lea    0xe6f(%rip),%rax
lea    0xe69(%rip),%rbx
mov    %rbx,%rsi
cmovl  %rax,%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
call   1030 <strcat@plt>
cmp    $0x2710,%r14d
lea    0xe46(%rip),%rax
cmovl  %rax,%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <strcat@plt>
cmp    $0x2710,%ebp
lea    0xe2f(%rip),%rax
lea    0xe29(%rip),%rsi
cmovl  %rax,%rsi
mov    %r12,%rdi
call   1030 <strcat@plt>
movslq %ebp,%rax
imul   $0x10624dd3,%rax,%r8
mov    %r8,%rax
shr    $0x3f,%rax
sar    $0x26,%r8
add    %eax,%r8d
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r15d,%edx
mov    %r13d,%ecx
call   1040 <sprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0%d:\00"
@.str.1 = [4 x i8] c"%d:\00"
@.str.2 = [4 x i8] c"0%d\00"
@.str.3 = [3 x i8] c"%d\00"
define void @format_timeline(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [16 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = sdiv i32 %9, 60000
store i32 %10, i32* %5
%11 = load i32, i32* %4
%12 = srem i32 %11, 60000
%13 = sdiv i32 %12, 1000
store i32 %13, i32* %6
%14 = load i32, i32* %4
%15 = srem i32 %14, 60000
%16 = srem i32 %15, 1000
%17 = mul nsw i32 %16, 75
%18 = sdiv i32 %17, 1000
store i32 %18, i32* %7
%19 = bitcast [16 x i8]* %8 to i8*
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %28
25: ; preds = %2
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 10
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %37
34: ; preds = %28
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %34, %31
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 10
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %46
43: ; preds = %37
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %3
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* %5
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call i32 @sprintf(i8* %47, i8* %48, i32 %49, i32 %50, i32 %51)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"0%d:\00"
@.str.1 = [4 x i8] c"%d:\00"
@.str.2 = [4 x i8] c"0%d\00"
@.str.3 = [3 x i8] c"%d\00"
define void @format_timeline(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = srem i32 %1, 60000
%5 = srem i32 %4, 1000
%6 = mul nsw i32 %5, 75
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = icmp slt i32 %1, 600000
%9 = select i1 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%10 = call i32 @strcat(i8* %7, i8* %9)
%11 = icmp slt i32 %4, 10000
%12 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0)
%13 = call i32 @strcat(i8* %7, i8* %12)
%14 = icmp slt i32 %6, 10000
%15 = select i1 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0)
%16 = call i32 @strcat(i8* %7, i8* %15)
%17 = sdiv i32 %6, 1000
%18 = sdiv i32 %4, 1000
%19 = sdiv i32 %1, 60000
%20 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* %7, i32 %19, i32 %18, i32 %17)
ret void
}