#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*/ curl_msnprintf(char *, int, char *, long, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void time2str(char *r, long t) {
  long h;
  if (!t) {
    strcpy(r, "--:--:--");
    return;
  }
  h = (t / 3600);
  if (h <= 99) {
    long m = (t - (h * 3600)) / 60;
    long s = (t - (h * 3600) - (m * 60));
    curl_msnprintf(r, 9, "%2ld:%02ld:%02ld", h, m, s);
  } else {
    if (h / 24 <= 999)
      curl_msnprintf(r, 9, "%3ldd %02ldh", h / 24, h - (h / 24) * 24);
    else
      curl_msnprintf(r, 9, "%7ldd", h / 24);
  }
}


x86 assembly (clang, -O0):
<time2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1150 <time2str+0x30>
mov    -0x8(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1030 <strcpy@plt>
jmp    125a <time2str+0x13a>
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
cmpq   $0x63,-0x18(%rbp)
jg     11cd <time2str+0xad>
mov    -0x10(%rbp),%rax
imul   $0xe10,-0x18(%rbp),%rcx
sub    %rcx,%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   $0xe10,-0x18(%rbp),%rcx
sub    %rcx,%rax
imul   $0x3c,-0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    $0x9,%esi
lea    0xe48(%rip),%rdx
mov    $0x0,%al
call   1040 <curl_msnprintf@plt>
jmp    125a <time2str+0x13a>
mov    -0x18(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
cmp    $0x3e7,%rax
jg     122d <time2str+0x10d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%r8
mov    -0x18(%rbp),%rax
mov    $0x18,%esi
cqto
idiv   %rsi
imul   $0x18,%rax,%rax
sub    %rax,%r8
mov    $0x9,%esi
lea    0xdf9(%rip),%rdx
mov    $0x0,%al
call   1040 <curl_msnprintf@plt>
jmp    1255 <time2str+0x135>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    $0x9,%esi
lea    0xdd9(%rip),%rdx
mov    $0x0,%al
call   1040 <curl_msnprintf@plt>
jmp    125a <time2str+0x13a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time2str>:
test   %rsi,%rsi
je     1198 <time2str+0x78>
movabs $0x48d159e26af37c05,%rcx
59 d1 48
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%r10
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xa,%r10
add    %rax,%r10
cmp    $0x57e3f,%rsi
jg     11a4 <time2str+0x84>
imul   $0xfffffffffffff1f0,%r10,%rcx
add    %rsi,%rcx
movabs $0x8888888888888889,%rdx
88 88 88
mov    %rcx,%rax
imul   %rdx
lea    (%rdx,%rcx,1),%r8
mov    %r8,%rax
shr    $0x3f,%rax
sar    $0x5,%r8
add    %rax,%r8
imul   $0xffffffffffffffc4,%r8,%r9
add    %rcx,%r9
lea    0xe80(%rip),%rdx
mov    $0x9,%esi
mov    %r10,%rcx
xor    %eax,%eax
jmp    1040 <curl_msnprintf@plt>
lea    0xe61(%rip),%rsi
jmp    1030 <strcpy@plt>
movabs $0xc22e450672894ab7,%rcx
45 2e c2
mov    %rsi,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x10,%rcx
cmp    $0x5265bff,%rsi
ja     11e9 <time2str+0xc9>
lea    0x0(,%rcx,8),%rax
lea    (%rax,%rax,2),%rax
sub    %rax,%r10
lea    0xe40(%rip),%rdx
mov    $0x9,%esi
mov    %r10,%r8
xor    %eax,%eax
jmp    1040 <curl_msnprintf@plt>
lea    0xe37(%rip),%rdx
mov    $0x9,%esi
xor    %eax,%eax
jmp    1040 <curl_msnprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"--:--:--\00"
@.str.1 = [17 x i8] c"%2ld:%02ld:%02ld\00"
@.str.2 = [13 x i8] c"%3ldd %02ldh\00"
@.str.3 = [6 x i8] c"%7ldd\00"
define void @time2str(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = icmp ne i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %56
13: ; preds = %2
%14 = load i64, i64* %4
%15 = sdiv i64 %14, 3600
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = icmp sle i64 %16, 99
br i1 %17, label %18, label %36
18: ; preds = %13
%19 = load i64, i64* %4
%20 = load i64, i64* %5
%21 = mul nsw i64 %20, 3600
%22 = sub nsw i64 %19, %21
%23 = sdiv i64 %22, 60
store i64 %23, i64* %6
%24 = load i64, i64* %4
%25 = load i64, i64* %5
%26 = mul nsw i64 %25, 3600
%27 = sub nsw i64 %24, %26
%28 = load i64, i64* %6
%29 = mul nsw i64 %28, 60
%30 = sub nsw i64 %27, %29
store i64 %30, i64* %7
%31 = load i8*, i8** %3
%32 = load i64, i64* %5
%33 = load i64, i64* %6
%34 = load i64, i64* %7
%35 = call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %31, i32 9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %32, i64 %33, i64 %34)
br label %56
36: ; preds = %13
%37 = load i64, i64* %5
%38 = sdiv i64 %37, 24
%39 = icmp sle i64 %38, 999
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i8*, i8** %3
%42 = load i64, i64* %5
%43 = sdiv i64 %42, 24
%44 = load i64, i64* %5
%45 = load i64, i64* %5
%46 = sdiv i64 %45, 24
%47 = mul nsw i64 %46, 24
%48 = sub nsw i64 %44, %47
%49 = call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %41, i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %43, i64 %48)
br label %55
50: ; preds = %36
%51 = load i8*, i8** %3
%52 = load i64, i64* %5
%53 = sdiv i64 %52, 24
%54 = call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %51, i32 9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %53)
br label %55
55: ; preds = %50, %40
br label %56
56: ; preds = %10, %55, %18
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"--:--:--\00"
@.str.1 = [17 x i8] c"%2ld:%02ld:%02ld\00"
@.str.2 = [13 x i8] c"%3ldd %02ldh\00"
@.str.3 = [6 x i8] c"%7ldd\00"
define void @time2str(i8* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %25
6: ; preds = %2
%7 = sdiv i64 %1, 3600
%8 = icmp slt i64 %1, 360000
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = mul nsw i64 %7, -3600
%11 = add i64 %10, %1
%12 = sdiv i64 %11, 60
%13 = mul nsw i64 %12, -60
%14 = add i64 %13, %11
%15 = tail call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %0, i32 9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64 %7, i64 %12, i64 %14)
br label %25
16: ; preds = %6
%17 = udiv i64 %1, 86400
%18 = icmp ult i64 %1, 86400000
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = mul nsw i64 %17, -24
%21 = add nsw i64 %20, %7
%22 = tail call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %0, i32 9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %17, i64 %21)
br label %25
23: ; preds = %16
%24 = tail call i32 (i8*, i32, i8*, i64, ...) @curl_msnprintf(i8* %0, i32 9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %17)
br label %25
25: ; preds = %9, %23, %19, %4
ret void
}