#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 */
double estimate(size_t, double);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ format_ETA(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ progress_elapsed();
double rate(size_t, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void progress_gauge_xxx(size_t total, size_t done) {
  if (total > 0) {
    double speed = rate(done, progress_elapsed());
    double eta = estimate(total - done, speed);
    printf("XXX\n");
    printf("%.0f\n", (float)done / total * 100);
    if (done < total)
      printf("%zu of %zu, %.1f kB/s, ETA %s\n", done, total,
             ((double)(speed) / 1000.), format_ETA(eta));
    else
      printf("Done: %.1f kB, at %.1f kB/s\n", ((double)(done) / 1000.),
             ((double)(speed) / 1000.));
    printf("XXX\n");
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<progress_gauge_xxx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    1344 <progress_gauge_xxx+0x1e4>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1070 <progress_elapsed@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <rate@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
sub    %rax,%rdi
movsd  -0x18(%rbp),%xmm0
call   1080 <estimate@plt>
mov    -0x29(%rbp),%al
movsd  %xmm0,-0x20(%rbp)
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x28(%rbp)
test   %rax,%rax
movss  %xmm0,-0x24(%rbp)
js     1203 <progress_gauge_xxx+0xa3>
movss  -0x28(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x40(%rbp)
test   %rax,%rax
movss  %xmm0,-0x3c(%rbp)
js     124a <progress_gauge_xxx+0xea>
movss  -0x40(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x44(%rbp),%xmm0
movss  -0x3c(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xda0(%rip),%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    12d6 <progress_gauge_xxx+0x176>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xd67(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <format_ETA@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
movsd  -0x50(%rbp),%xmm0
mov    %eax,%ecx
lea    0xd71(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1328 <progress_gauge_xxx+0x1c8>
movaps 0xd33(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd32(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd03(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xcf2(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xd39(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
lea    0xd01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress_gauge_xxx>:
test   %rdi,%rdi
je     11e1 <progress_gauge_xxx+0x71>
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <progress_elapsed@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <rate@plt>
mov    %rbx,%rdi
sub    %r14,%rdi
movsd  %xmm0,0x8(%rsp)
call   1090 <estimate@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xec9(%rip),%rdi
call   1040 <puts@plt>
test   %r14,%r14
js     11e2 <progress_gauge_xxx+0x72>
xorps  %xmm0,%xmm0
cvtsi2ss %r14,%xmm0
test   %rbx,%rbx
jns    1202 <progress_gauge_xxx+0x92>
mov    %rbx,%rax
shr    %rax
mov    %ebx,%ecx
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm1
addss  %xmm1,%xmm1
jmp    1207 <progress_gauge_xxx+0x97>
ret
mov    %r14,%rax
shr    %rax
mov    %r14d,%ecx
and    $0x1,%ecx
or     %rax,%rcx
xorps  %xmm0,%xmm0
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
test   %rbx,%rbx
js     11c8 <progress_gauge_xxx+0x58>
cvtsi2ss %rbx,%xmm1
divss  %xmm1,%xmm0
mulss  0xded(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe1a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cmp    %r14,%rbx
jbe    1267 <progress_gauge_xxx+0xf7>
movsd  0x8(%rsp),%xmm0
divsd  0xdf8(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <format_ETA@plt>
lea    0xdee(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
movsd  0x8(%rsp),%xmm0
mov    %eax,%ecx
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12ac <progress_gauge_xxx+0x13c>
movq   %r14,%xmm1
punpckldq 0xd9c(%rip),%xmm1
subpd  0xda4(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  0xda0(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
divsd  %xmm2,%xmm1
lea    0xdb8(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
lea    0xdc7(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
add    $0x18,%rsp
pop    %rbx
pop    %r14
jmp    1070 <fflush@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"XXX\0A\00"
@.str.1 = [6 x i8] c"%.0f\0A\00"
@.str.2 = [31 x i8] c"%zu of %zu, %.1f kB/s, ETA %s\0A\00"
@.str.3 = [29 x i8] c"Done: %.1f kB, at %.1f kB/s\0A\00"
@stdout = global i32 0
define void @progress_gauge_xxx(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
%6 = alloca double
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = icmp ugt i64 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %2
%10 = load i64, i64* %4
%11 = call i32 (...) @progress_elapsed()
%12 = call double @rate(i64 %10, i32 %11)
store double %12, double* %5
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = sub i64 %13, %14
%16 = load double, double* %5
%17 = call double @estimate(i64 %15, double %16)
store double %17, double* %6
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i64, i64* %4
%20 = uitofp i64 %19 to float
%21 = load i64, i64* %3
%22 = uitofp i64 %21 to float
%23 = fdiv float %20, %22
%24 = fmul float %23, 1.000000e+02
%25 = fpext float %24 to double
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %25)
%27 = load i64, i64* %4
%28 = load i64, i64* %3
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %9
%31 = load i64, i64* %4
%32 = load i64, i64* %3
%33 = load double, double* %5
%34 = fdiv double %33, 1.000000e+03
%35 = load double, double* %6
%36 = call i32 @format_ETA(double %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %31, i64 %32, double %34, i32 %36)
br label %45
38: ; preds = %9
%39 = load i64, i64* %4
%40 = uitofp i64 %39 to double
%41 = fdiv double %40, 1.000000e+03
%42 = load double, double* %5
%43 = fdiv double %42, 1.000000e+03
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %41, double %43)
br label %45
45: ; preds = %38, %30
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
br label %49
49: ; preds = %45, %2
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%.0f\0A\00"
@.str.2 = [31 x i8] c"%zu of %zu, %.1f kB/s, ETA %s\0A\00"
@.str.3 = [29 x i8] c"Done: %.1f kB, at %.1f kB/s\0A\00"
@stdout = global i32 0
@str.4 = [4 x i8] c"XXX\00"
define void @progress_gauge_xxx(i64 %0, i64 %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %30, label %4
4: ; preds = %2
%5 = tail call i32 (...) @progress_elapsed()
%6 = tail call double @rate(i64 %1, i32 %5)
%7 = sub i64 %0, %1
%8 = tail call double @estimate(i64 %7, double %6)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0))
%10 = uitofp i64 %1 to float
%11 = uitofp i64 %0 to float
%12 = fdiv float %10, %11
%13 = fmul float %12, 1.000000e+02
%14 = fpext float %13 to double
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %14)
%16 = icmp ugt i64 %0, %1
br i1 %16, label %17, label %21
17: ; preds = %4
%18 = fdiv double %6, 1.000000e+03
%19 = tail call i32 @format_ETA(double %8)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %1, i64 %0, double %18, i32 %19)
br label %26
21: ; preds = %4
%22 = uitofp i64 %1 to double
%23 = fdiv double %22, 1.000000e+03
%24 = fdiv double %6, 1.000000e+03
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), double %23, double %24)
br label %26
26: ; preds = %21, %17
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.4, i64 0, i64 0))
%28 = load i32, i32* @stdout
%29 = tail call i32 @fflush(i32 %28)
br label %30
30: ; preds = %26, %2
ret void
}