#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 int64_t;

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, ...);
int floor(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int ms_to_time(int64_t *ms1, char **dest) {
  int64_t ms = *ms1;
  if (ms >= 86400000000) {
    fprintf(stderr, "Can not convert microseconds >= 24 hours\n");
    return 1;
  }
  if (ms == 0) {
    asprintf(dest, "%s", "00:00:00");
    return 0;
  }
  int64_t hours = ms / 1000 / 1000 / 60 / 60;
  hours = floor(hours);
  ms -= hours * 60 * 60 * 1000 * 1000;
  int64_t minutes = ms / 1000 / 1000 / 60;
  minutes = floor(minutes);
  ms -= minutes * 60 * 1000 * 1000;
  int64_t seconds = ms / 1000 / 1000;
  seconds = floor(seconds);
  asprintf(dest, "%.2lld:%.2lld:%.2lld", hours, minutes, seconds);
  return 0;
}


x86 assembly (clang, -O0):
<ms_to_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
movabs $0x141dd76000,%rcx
cmp    %rcx,%rax
jl     1181 <ms_to_time+0x51>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1281 <ms_to_time+0x151>
cmpl   $0x0,-0x1c(%rbp)
jne    11b0 <ms_to_time+0x80>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
lea    0xe90(%rip),%rdx
mov    $0x0,%al
call   1040 <asprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <ms_to_time+0x151>
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <floor@plt>
mov    %eax,-0x20(%rbp)
imul   $0x3c,-0x20(%rbp),%eax
imul   $0x3c,%eax,%eax
imul   $0x3e8,%eax,%eax
imul   $0x3e8,%eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <floor@plt>
mov    %eax,-0x24(%rbp)
imul   $0x3c,-0x24(%rbp),%eax
imul   $0x3e8,%eax,%eax
imul   $0x3e8,%eax,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <floor@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ms_to_time>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%ebx
test   %ebx,%ebx
je     119f <ms_to_time+0x7f>
xor    %edi,%edi
call   1040 <floor@plt>
mov    %eax,%r15d
imul   $0x296c5c00,%eax,%eax
add    %ebx,%eax
movslq %eax,%rbp
imul   $0x4795319d,%rbp,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x38,%rdi
add    %eax,%edi
call   1040 <floor@plt>
mov    %eax,%ebx
imul   $0xfc6c7900,%eax,%eax
add    %eax,%ebp
movslq %ebp,%rax
imul   $0x431bde83,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x32,%rdi
add    %eax,%edi
call   1040 <floor@plt>
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <asprintf@plt>
jmp    11b7 <ms_to_time+0x97>
lea    0xe5a(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <asprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"Can not convert microseconds >= 24 hours\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"00:00:00\00"
@.str.3 = [21 x i8] c"%.2lld:%.2lld:%.2lld\00"
define i32 @ms_to_time(i32* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i8** %1, i8*** %5
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = icmp sge i64 %13, 86400000000
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %61
18: ; preds = %2
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = call i32 (i8**, i8*, ...) @asprintf(i8** %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %61
24: ; preds = %18
%25 = load i32, i32* %6
%26 = sdiv i32 %25, 1000
%27 = sdiv i32 %26, 1000
%28 = sdiv i32 %27, 60
%29 = sdiv i32 %28, 60
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = call i32 @floor(i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = mul nsw i32 %32, 60
%34 = mul nsw i32 %33, 60
%35 = mul nsw i32 %34, 1000
%36 = mul nsw i32 %35, 1000
%37 = load i32, i32* %6
%38 = sub nsw i32 %37, %36
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = sdiv i32 %39, 1000
%41 = sdiv i32 %40, 1000
%42 = sdiv i32 %41, 60
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = call i32 @floor(i32 %43)
store i32 %44, i32* %8
%45 = load i32, i32* %8
%46 = mul nsw i32 %45, 60
%47 = mul nsw i32 %46, 1000
%48 = mul nsw i32 %47, 1000
%49 = load i32, i32* %6
%50 = sub nsw i32 %49, %48
store i32 %50, i32* %6
%51 = load i32, i32* %6
%52 = sdiv i32 %51, 1000
%53 = sdiv i32 %52, 1000
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = call i32 @floor(i32 %54)
store i32 %55, i32* %9
%56 = load i8**, i8*** %5
%57 = load i32, i32* %7
%58 = load i32, i32* %8
%59 = load i32, i32* %9
%60 = call i32 (i8**, i8*, ...) @asprintf(i8** %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %57, i32 %58, i32 %59)
store i32 0, i32* %3
br label %61
61: ; preds = %24, %21, %15
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"00:00:00\00"
@.str.3 = [21 x i8] c"%.2lld:%.2lld:%.2lld\00"
define i32 @ms_to_time(i32* nocapture %0, i8** %1) {
%3 = load i32, i32* %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8**, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %18
7: ; preds = %2
%8 = tail call i32 @floor(i32 0)
%9 = mul i32 %8, 694967296
%10 = add i32 %9, %3
%11 = sdiv i32 %10, 60000000
%12 = tail call i32 @floor(i32 %11)
%13 = mul i32 %12, -60000000
%14 = add i32 %13, %10
%15 = sdiv i32 %14, 1000000
%16 = tail call i32 @floor(i32 %15)
%17 = tail call i32 (i8**, i8*, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %8, i32 %12, i32 %16)
br label %18
18: ; preds = %7, %5
ret i32 0
}