#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*/ strcpy(char *, char *);
char *fixtime(long long int elap) {
  int num = elap / 1000;
  int hor = 0;
  int min = 0;
  int sec = 0;
  static char buf[12];
  hor = num / 3600;
  min = (num % 3600) / 60;
  sec = num % 60;
  if (hor == 0 && min == 0 && sec == 0)
    strcpy(buf, "0");
  else
    sprintf(buf, "%d:%02d:%02d", hor, min, sec);
  return buf;
}


x86 assembly (clang, -O0):
<fixtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    11bc <fixtime+0x9c>
cmpl   $0x0,-0x14(%rbp)
jne    11bc <fixtime+0x9c>
cmpl   $0x0,-0x18(%rbp)
jne    11bc <fixtime+0x9c>
lea    0x2e86(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d9 <fixtime+0xb9>
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0x2e64(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2e51(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixtime>:
push   %rax
mov    %rdi,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
imul   %rcx
mov    %rdx,%rax
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x7,%rax
add    %rcx,%rax
movslq %eax,%rsi
imul   $0xffffffff91a2b3c5,%rsi,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
sar    $0xb,%edx
add    %ecx,%edx
imul   $0xe10,%edx,%ecx
imul   $0xffffffff88888889,%rsi,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%edi
shr    $0x1f,%edi
sar    $0x5,%esi
add    %edi,%esi
imul   $0x3c,%esi,%esi
mov    %eax,%r8d
sub    %esi,%r8d
jne    11b5 <fixtime+0x95>
lea    0xe0f(%rax),%esi
cmp    $0x1c1e,%esi
ja     11b5 <fixtime+0x95>
mov    %ecx,%esi
neg    %esi
add    %eax,%esi
add    $0x3b,%esi
cmp    $0x76,%esi
ja     11b5 <fixtime+0x95>
lea    0x2e8a(%rip),%rdi
lea    0xe52(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11e9 <fixtime+0xc9>
sub    %ecx,%eax
movswl %ax,%ecx
imul   $0xffff8889,%ecx,%ecx
shr    $0x10,%ecx
add    %eax,%ecx
movzwl %cx,%eax
movswl %ax,%ecx
shr    $0xf,%eax
sar    $0x5,%ecx
add    %eax,%ecx
movswl %cx,%ecx
lea    0x2e54(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   1040 <sprintf@plt>
lea    0x2e41(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@fixtime.buf = internal global [12 x i8] zeroinitializer
@.str = [2 x i8] c"0\00"
@.str.1 = [13 x i8] c"%d:%02d:%02d\00"
define i8* @fixtime(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = sdiv i64 %7, 1000
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 3600
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = srem i32 %12, 3600
%14 = sdiv i32 %13, 60
store i32 %14, i32* %5
%15 = load i32, i32* %3
%16 = srem i32 %15, 60
store i32 %16, i32* %6
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %1
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @strcpy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %32
27: ; preds = %22, %19, %1
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @sprintf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %29, i32 %30)
br label %32
32: ; preds = %27, %25
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@fixtime.buf = internal global [12 x i8] zeroinitializer
@.str = [2 x i8] c"0\00"
@.str.1 = [13 x i8] c"%d:%02d:%02d\00"
define i8* @fixtime(i64 %0) {
%2 = sdiv i64 %0, 1000
%3 = trunc i64 %2 to i32
%4 = srem i32 %3, 3600
%5 = sdiv i32 %3, 3600
%6 = srem i32 %3, 60
%7 = add i32 %3, 3599
%8 = icmp ult i32 %7, 7199
%9 = add nsw i32 %4, 59
%10 = icmp ult i32 %9, 119
%11 = select i1 %8, i1 %10, i1 false
%12 = icmp eq i32 %6, 0
%13 = and i1 %12, %11
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = tail call i32 @strcpy(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %21
16: ; preds = %1
%17 = trunc i32 %4 to i16
%18 = sdiv i16 %17, 60
%19 = sext i16 %18 to i32
%20 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %19, i32 %6)
br label %21
21: ; preds = %16, %14
ret i8* getelementptr inbounds ([12 x i8], [12 x i8]* @fixtime.buf, i64 0, i64 0)
}