#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 uint64_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_eta(uint32_t progress, uint64_t now, uint64_t start_time) {
  int hours, minutes, seconds;
  uint64_t tbusy, ttot_est, eta;
  if (progress == 0) {
    printf(" ETA --:--:--");
    return;
  }
  tbusy = now - start_time;
  ttot_est = (tbusy * 0x10000) / progress;
  eta = (ttot_est - tbusy) / 1000000;
  hours = (int)(eta / 3600);
  minutes = (int)(eta / 60) % 60;
  seconds = (int)eta % 60;
  printf(" ETA %02d:%02d:%02d", hours, minutes, seconds);
}


x86 assembly (clang, -O0):
<print_eta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113e <print_eta+0x2e>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ae <print_eta+0x9e>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x10,%eax
cltd
idivl  -0x4(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_eta>:
test   %edi,%edi
je     117c <print_eta+0x6c>
sub    %edx,%esi
mov    %esi,%eax
shl    $0x10,%eax
cltd
idiv   %edi
sub    %esi,%eax
movslq %eax,%rcx
imul   $0x431bde83,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rax
add    %edx,%eax
imul   $0x4795319d,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x38,%rdx
add    %ecx,%edx
imul   $0xffff8889,%eax,%ecx
shr    $0x10,%ecx
add    %eax,%ecx
movzwl %cx,%ecx
movswl %cx,%esi
shr    $0xf,%ecx
sar    $0x5,%esi
add    %ecx,%esi
imul   $0x3c,%esi,%ecx
sub    %ecx,%eax
movswl %ax,%ecx
lea    0xe9b(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c" ETA --:--:--\00"
@.str.1 = [20 x i8] c" ETA %02d:%02d:%02d\00"
define void @print_eta(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
17: ; preds = %3
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = mul nsw i32 %21, 65536
%23 = load i32, i32* %4
%24 = sdiv i32 %22, %23
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = load i32, i32* %10
%27 = sub nsw i32 %25, %26
%28 = sdiv i32 %27, 1000000
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = sdiv i32 %29, 3600
store i32 %30, i32* %7
%31 = load i32, i32* %12
%32 = sdiv i32 %31, 60
%33 = srem i32 %32, 60
store i32 %33, i32* %8
%34 = load i32, i32* %12
%35 = srem i32 %34, 60
store i32 %35, i32* %9
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37, i32 %38)
br label %40
40: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c" ETA --:--:--\00"
@.str.1 = [20 x i8] c" ETA %02d:%02d:%02d\00"
define void @print_eta(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
7: ; preds = %3
%8 = sub nsw i32 %1, %2
%9 = shl nsw i32 %8, 16
%10 = sdiv i32 %9, %0
%11 = sub nsw i32 %10, %8
%12 = sdiv i32 %11, 1000000
%13 = sdiv i32 %11, 60000000
%14 = trunc i32 %12 to i16
%15 = srem i16 %14, 60
%16 = sext i16 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %13, i32 %16)
br label %18
18: ; preds = %7, %5
ret void
}