#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, ...);
void format_time(char *str, int seconds, int accurate) {
  int hour, min, sec;
  if (seconds > 86400 && accurate == 0) {
    sprintf(str, "~%uh", (unsigned int)(seconds / 3600.0));
  } else {
    sec = seconds % 3600;
    hour = (seconds - sec) / 3600;
    min = sec / 60;
    sec = sec % 60;
    if (hour == 0) {
      sprintf(str, "%02d:%02d", min, sec);
    } else {
      sprintf(str, "%02d:%02d:%02d", hour, min, sec);
    }
  }
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x15180,-0xc(%rbp)
jle    1168 <format_time+0x58>
cmpl   $0x0,-0x10(%rbp)
jne    1168 <format_time+0x58>
mov    -0x8(%rbp),%rdi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xeb6(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%edx
lea    0xeac(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11eb <format_time+0xdb>
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ca <format_time+0xba>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11e6 <format_time+0xd6>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11eb <format_time+0xdb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
cmp    $0x15181,%esi
jl     113b <format_time+0x2b>
test   %edx,%edx
jne    113b <format_time+0x2b>
cvtsi2sd %esi,%xmm0
divsd  0xed8(%rip),%xmm0
cvttsd2si %xmm0,%rdx
lea    0xed4(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
movslq %esi,%rax
imul   $0xffffffff91a2b3c5,%rax,%rdx
shr    $0x20,%rdx
add    %esi,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0xb,%edx
add    %eax,%edx
imul   $0xe10,%edx,%ecx
mov    %esi,%r8d
sub    %ecx,%r8d
movswl %r8w,%ecx
imul   $0xffff8889,%ecx,%ecx
shr    $0x10,%ecx
add    %r8d,%ecx
movzwl %cx,%ecx
movswl %cx,%eax
shr    $0xf,%ecx
sar    $0x5,%eax
add    %ecx,%eax
movswl %ax,%ecx
imul   $0x3c,%eax,%eax
sub    %eax,%r8d
movswl %r8w,%r8d
add    $0xe0f,%esi
cmp    $0x1c1e,%esi
ja     11ad <format_time+0x9d>
lea    0xe71(%rip),%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe59(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"~%uh\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [15 x i8] c"%02d:%02d:%02d\00"
define void @format_time(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 86400
br i1 %11, label %12, label %22
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, 3.600000e+03
%20 = fptoui double %19 to i32
%21 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %47
22: ; preds = %12, %3
%23 = load i32, i32* %5
%24 = srem i32 %23, 3600
store i32 %24, i32* %9
%25 = load i32, i32* %5
%26 = load i32, i32* %9
%27 = sub nsw i32 %25, %26
%28 = sdiv i32 %27, 3600
store i32 %28, i32* %7
%29 = load i32, i32* %9
%30 = sdiv i32 %29, 60
store i32 %30, i32* %8
%31 = load i32, i32* %9
%32 = srem i32 %31, 60
store i32 %32, i32* %9
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %22
%36 = load i8*, i8** %4
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %38)
br label %46
40: ; preds = %22
%41 = load i8*, i8** %4
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43, i32 %44)
br label %46
46: ; preds = %40, %35
br label %47
47: ; preds = %46, %15
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"~%uh\00"
@.str.1 = [10 x i8] c"%02d:%02d\00"
@.str.2 = [15 x i8] c"%02d:%02d:%02d\00"
define void @format_time(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 86400
%5 = icmp eq i32 %2, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = sitofp i32 %1 to double
%9 = fdiv double %8, 3.600000e+03
%10 = fptoui double %9 to i32
%11 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %26
12: ; preds = %3
%13 = srem i32 %1, 3600
%14 = sdiv i32 %1, 3600
%15 = trunc i32 %13 to i16
%16 = sdiv i16 %15, 60
%17 = sext i16 %16 to i32
%18 = srem i16 %15, 60
%19 = sext i16 %18 to i32
%20 = add i32 %1, 3599
%21 = icmp ult i32 %20, 7199
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
br label %26
24: ; preds = %12
%25 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %17, i32 %19)
br label %26
26: ; preds = %22, %24, %7
ret void
}