#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 /*<<< orphan*/ result;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
const char *format_ETA(double remaining) {
  static char result[6] = "";
  int seconds = remaining + 0.5;
  if (seconds >= 0 && seconds < 6000) {
    snprintf(result, sizeof(result), "%02d:%02d", seconds / 60, seconds % 60);
    return result;
  }
  return "--:--";
}


x86 assembly (clang, -O0):
<format_ETA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xedb(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     118b <format_ETA+0x7b>
cmpl   $0x1770,-0x14(%rbp)
jge    118b <format_ETA+0x7b>
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r8d
lea    0x2ebf(%rip),%rdi
mov    $0x6,%esi
lea    0xe92(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2ea7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <format_ETA+0x86>
lea    0xe80(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_ETA>:
push   %rbx
addsd  0xee7(%rip),%xmm0
cvttsd2si %xmm0,%eax
cmp    $0x176f,%eax
ja     1156 <format_ETA+0x46>
movzwl %ax,%ecx
imul   $0x8889,%ecx,%ecx
shr    $0x15,%ecx
imul   $0x3c,%ecx,%edx
sub    %edx,%eax
movzwl %ax,%r8d
lea    0x2ee9(%rip),%rbx
lea    0xec1(%rip),%rdx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <snprintf@plt>
jmp    115d <format_ETA+0x4d>
lea    0xeb5(%rip),%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@format_ETA.result = internal global [6 x i8] zeroinitializer
@.str = [10 x i8] c"%02d:%02d\00"
@.str.1 = [6 x i8] c"--:--\00"
define i8* @format_ETA(double %0) {
%2 = alloca i8*
%3 = alloca double
%4 = alloca i32
store double %0, double* %3
%5 = load double, double* %3
%6 = fadd double %5, 5.000000e-01
%7 = fptosi double %6 to i32
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 6000
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sdiv i32 %14, 60
%16 = load i32, i32* %4
%17 = srem i32 %16, 60
%18 = call i32 @snprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @format_ETA.result, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @format_ETA.result, i64 0, i64 0), i8** %2
br label %20
19: ; preds = %10, %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %20
20: ; preds = %19, %13
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@format_ETA.result = internal global [6 x i8] zeroinitializer
@.str = [10 x i8] c"%02d:%02d\00"
@.str.1 = [6 x i8] c"--:--\00"
define i8* @format_ETA(double %0) {
%2 = fadd double %0, 5.000000e-01
%3 = fptosi double %2 to i32
%4 = icmp ult i32 %3, 6000
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = trunc i32 %3 to i16
%7 = udiv i16 %6, 60
%8 = zext i16 %7 to i32
%9 = urem i16 %6, 60
%10 = zext i16 %9 to i32
%11 = tail call i32 @snprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @format_ETA.result, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %10)
br label %12
12: ; preds = %1, %5
%13 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @format_ETA.result, i64 0, i64 0), %5 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %13
}