#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 scalar_t__ time_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewriteLine();
int /*<<< orphan*/ stdout;
scalar_t__ time(int /*<<< orphan*/ *);
void progress(float ratio) {
  static time_t started = 0;
  static time_t last = 0;
  if (!started) {
    started = time(NULL);
    return;
  }
  time_t cur = time(NULL);
  if (last == cur)
    return;
  last = cur;
  time_t seconds = (cur - started) * (1 / ratio - 1);
  time_t minutes = seconds / 60;
  seconds %= 60;
  time_t hours = minutes / 60;
  minutes %= 60;
  time_t days = hours / 24;
  hours %= 24;
  time_t weeks = days / 7;
  days %= 7;
  rewriteLine();
  printf("Progress: %.2f%% (ETA:", 100 * ratio);
  if (weeks) {
    printf(" %lu weeks", weeks);
    hours = 0;
    minutes = 0;
    seconds = 0;
  }
  if (days) {
    printf(" %lu days", days);
    minutes = 0;
    seconds = 0;
  }
  if (hours) {
    printf(" %lu hours", hours);
    seconds = 0;
  }
  if (minutes) {
    printf(" %lu minutes", minutes);
  }
  if (seconds) {
    printf(" %lu seconds", seconds);
  }
  printf(")");
  fflush(stdout);
}


x86 assembly (clang, -O0):
<progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
cmpq   $0x0,0x2ef3(%rip)
jne    1170 <progress+0x30>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,0x2edd(%rip)
jmp    1367 <progress+0x227>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %rax,-0x10(%rbp)
mov    0x2ecc(%rip),%rax
cmp    -0x10(%rbp),%rax
jne    1193 <progress+0x53>
jmp    1367 <progress+0x227>
mov    -0x10(%rbp),%rax
mov    %rax,0x2eb2(%rip)
mov    -0x10(%rbp),%rax
sub    0x2e9f(%rip),%rax
cvtsi2ss %rax,%xmm0
movss  0xe4e(%rip),%xmm1
divss  -0x4(%rbp),%xmm1
movss  0xe41(%rip),%xmm2
subss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x7,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rewriteLine@plt>
movss  0xd8d(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd85(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x38(%rbp)
je     12bf <progress+0x17f>
mov    -0x38(%rbp),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12ec <progress+0x1ac>
mov    -0x30(%rbp),%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1311 <progress+0x1d1>
mov    -0x28(%rbp),%rsi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     132e <progress+0x1ee>
mov    -0x20(%rbp),%rsi
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     134b <progress+0x20b>
mov    -0x18(%rbp),%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
mov    0x2ee8(%rip),%rbx
xor    %edi,%edi
call   1060 <time@plt>
test   %rbx,%rbx
je     12e9 <progress+0x199>
cmp    %rax,0x2ed9(%rip)
je     12f0 <progress+0x1a0>
mov    %rax,0x2ecc(%rip)
mov    0x2ebd(%rip),%rcx
sub    %rcx,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movss  0xe5a(%rip),%xmm1
divss  0x4(%rsp),%xmm1
addss  0xe50(%rip),%xmm1
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%r14
movabs $0x8888888888888889,%rcx
88 88 88
mov    %r14,%rax
imul   %rcx
mov    %rdx,%r12
add    %r14,%r12
mov    %r12,%rsi
shr    $0x3f,%rsi
sar    $0x5,%r12
movabs $0x48d159e26af37c05,%rdx
59 d1 48
mov    %r14,%rax
imul   %rdx
mov    %rdx,%r15
add    %rsi,%r12
mov    %rdx,%rsi
shr    $0x3f,%rsi
mov    %r12,%rax
imul   %rcx
mov    %rdx,%r13
sar    $0xa,%r15
movabs $0x1845c8a0ce512957,%rcx
c8 45 18
mov    %r14,%rax
imul   %rcx
mov    %rdx,%rcx
add    %rsi,%r15
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xd,%rcx
add    %rax,%rcx
movabs $0x2aaaaaaaaaaaaaab,%rdx
aa aa 2a
mov    %r15,%rax
imul   %rdx
mov    %rdx,%rbp
movabs $0x4924924924924925,%rdx
92 24 49
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    %rbx
add    %rax,%rbx
lea    0x0(,%rbx,8),%rax
sub    %rax,%rbx
add    %rcx,%rbx
xor    %eax,%eax
call   1040 <rewriteLine@plt>
movss  0x4(%rsp),%xmm0
mulss  0xd86(%rip),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd7f(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0x93a7f(%r14),%rax
cmp    $0x1274ff,%rax
jae    12ff <progress+0x1af>
imul   $0x3c,%r12,%rax
sub    %rax,%r14
add    %r12,%r13
mov    %r13,%rax
shr    $0x3f,%rax
sar    $0x5,%r13
add    %rax,%r13
imul   $0x3c,%r13,%rax
sub    %rax,%r12
mov    %rbp,%rax
shr    $0x3f,%rax
shr    $0x2,%rbp
add    %rax,%rbp
shl    $0x3,%rbp
lea    0x0(,%rbp,2),%rax
add    %rbp,%rax
sub    %rax,%r15
test   %rbx,%rbx
jne    1339 <progress+0x1e9>
jmp    1350 <progress+0x200>
mov    %rax,0x2d60(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0x377aef2669de1559,%rcx
ef 7a 37
mov    %r14,%rax
imul   %rcx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x11,%rdx
add    %rdx,%rsi
lea    0xcff(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r12d,%r12d
xor    %r15d,%r15d
test   %rbx,%rbx
je     1350 <progress+0x200>
lea    0xcee(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %r12d,%r12d
test   %r15,%r15
je     1369 <progress+0x219>
lea    0xcdc(%rip),%rdi
xor    %r14d,%r14d
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12,%r12
je     137f <progress+0x22f>
lea    0xcce(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14,%r14
je     1395 <progress+0x245>
lea    0xcc5(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x29,%edi
call   1030 <putchar@plt>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fflush@plt>

LLVM IR (-O0):
@progress.started = internal global i64 0
@progress.last = internal global i64 0
@.str = [23 x i8] c"Progress: %.2f%% (ETA:\00"
@.str.1 = [11 x i8] c" %lu weeks\00"
@.str.2 = [10 x i8] c" %lu days\00"
@.str.3 = [11 x i8] c" %lu hours\00"
@.str.4 = [13 x i8] c" %lu minutes\00"
@.str.5 = [13 x i8] c" %lu seconds\00"
@.str.6 = [2 x i8] c")\00"
@stdout = global i32 0
define void @progress(float %0) {
%2 = alloca float
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store float %0, float* %2
%9 = load i64, i64* @progress.started
%10 = icmp ne i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = call i64 @time(i32* null)
store i64 %12, i64* @progress.started
br label %84
13: ; preds = %1
%14 = call i64 @time(i32* null)
store i64 %14, i64* %3
%15 = load i64, i64* @progress.last
%16 = load i64, i64* %3
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
br label %84
19: ; preds = %13
%20 = load i64, i64* %3
store i64 %20, i64* @progress.last
%21 = load i64, i64* %3
%22 = load i64, i64* @progress.started
%23 = sub nsw i64 %21, %22
%24 = sitofp i64 %23 to float
%25 = load float, float* %2
%26 = fdiv float 1.000000e+00, %25
%27 = fsub float %26, 1.000000e+00
%28 = fmul float %24, %27
%29 = fptosi float %28 to i64
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = sdiv i64 %30, 60
store i64 %31, i64* %5
%32 = load i64, i64* %4
%33 = srem i64 %32, 60
store i64 %33, i64* %4
%34 = load i64, i64* %5
%35 = sdiv i64 %34, 60
store i64 %35, i64* %6
%36 = load i64, i64* %5
%37 = srem i64 %36, 60
store i64 %37, i64* %5
%38 = load i64, i64* %6
%39 = sdiv i64 %38, 24
store i64 %39, i64* %7
%40 = load i64, i64* %6
%41 = srem i64 %40, 24
store i64 %41, i64* %6
%42 = load i64, i64* %7
%43 = sdiv i64 %42, 7
store i64 %43, i64* %8
%44 = load i64, i64* %7
%45 = srem i64 %44, 7
store i64 %45, i64* %7
%46 = call i32 (...) @rewriteLine()
%47 = load float, float* %2
%48 = fmul float 1.000000e+02, %47
%49 = fpext float %48 to double
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %49)
%51 = load i64, i64* %8
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %19
%54 = load i64, i64* %8
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %54)
store i64 0, i64* %6
store i64 0, i64* %5
store i64 0, i64* %4
br label %56
56: ; preds = %53, %19
%57 = load i64, i64* %7
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i64, i64* %7
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %60)
store i64 0, i64* %5
store i64 0, i64* %4
br label %62
62: ; preds = %59, %56
%63 = load i64, i64* %6
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = load i64, i64* %6
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %66)
store i64 0, i64* %4
br label %68
68: ; preds = %65, %62
%69 = load i64, i64* %5
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i64, i64* %5
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %72)
br label %74
74: ; preds = %71, %68
%75 = load i64, i64* %4
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i64, i64* %4
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %78)
br label %80
80: ; preds = %77, %74
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%82 = load i32, i32* @stdout
%83 = call i32 @fflush(i32 %82)
br label %84
84: ; preds = %80, %18, %11
ret void
}

LLVM IR (-O2):
@progress.started = internal unnamed_addr global i64 0
@progress.last = internal unnamed_addr global i64 0
@.str = [23 x i8] c"Progress: %.2f%% (ETA:\00"
@.str.1 = [11 x i8] c" %lu weeks\00"
@.str.2 = [10 x i8] c" %lu days\00"
@.str.3 = [11 x i8] c" %lu hours\00"
@.str.4 = [13 x i8] c" %lu minutes\00"
@.str.5 = [13 x i8] c" %lu seconds\00"
@stdout = global i32 0
define void @progress(float %0) {
%2 = load i64, i64* @progress.started
%3 = icmp eq i64 %2, 0
%4 = tail call i64 @time(i32* null)
br i1 %3, label %5, label %6
5: ; preds = %1
store i64 %4, i64* @progress.started
br label %59
6: ; preds = %1
%7 = load i64, i64* @progress.last
%8 = icmp eq i64 %7, %4
br i1 %8, label %59, label %9
9: ; preds = %6
store i64 %4, i64* @progress.last
%10 = load i64, i64* @progress.started
%11 = sub nsw i64 %4, %10
%12 = sitofp i64 %11 to float
%13 = fdiv float 1.000000e+00, %0
%14 = fadd float %13, -1.000000e+00
%15 = fmul float %14, %12
%16 = fptosi float %15 to i64
%17 = sdiv i64 %16, 60
%18 = srem i64 %16, 60
%19 = sdiv i64 %16, 3600
%20 = srem i64 %17, 60
%21 = sdiv i64 %16, 86400
%22 = srem i64 %19, 24
%23 = srem i64 %21, 7
%24 = tail call i32 (...) @rewriteLine()
%25 = fmul float %0, 1.000000e+02
%26 = fpext float %25 to double
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), double %26)
%28 = add i64 %16, 604799
%29 = icmp ult i64 %28, 1209599
br i1 %29, label %33, label %30
30: ; preds = %9
%31 = sdiv i64 %16, 604800
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %31)
br label %33
33: ; preds = %30, %9
%34 = phi i64 [ 0, %30 ], [ %18, %9 ]
%35 = phi i64 [ 0, %30 ], [ %20, %9 ]
%36 = phi i64 [ 0, %30 ], [ %22, %9 ]
%37 = icmp eq i64 %23, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %23)
br label %40
40: ; preds = %38, %33
%41 = phi i64 [ 0, %38 ], [ %34, %33 ]
%42 = phi i64 [ 0, %38 ], [ %35, %33 ]
%43 = icmp eq i64 %36, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %36)
br label %46
46: ; preds = %44, %40
%47 = phi i64 [ 0, %44 ], [ %41, %40 ]
%48 = icmp eq i64 %42, 0
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %42)
br label %51
51: ; preds = %49, %46
%52 = icmp eq i64 %47, 0
br i1 %52, label %55, label %53
53: ; preds = %51
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %47)
br label %55
55: ; preds = %53, %51
%56 = tail call i32 @putchar(i32 41)
%57 = load i32, i32* @stdout
%58 = tail call i32 @fflush(i32 %57)
br label %59
59: ; preds = %55, %6, %5
ret void
}