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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, int, int, int, int, int, int, int);
scalar_t__ time(int /*<<< orphan*/);
void progress(uint64_t fs_complete, uint64_t fs_total) {
  int days = 0, hours = 0, minutes = 0;
  uint64_t t, pct, speed, seconds = 0;
  static time_t start = 0;
  if (start == 0) {
    start = time(0);
    return;
  }
  pct = (100 * fs_complete) / fs_total;
  t = (time(0) - start);
  if (t != 0) {
    seconds = (fs_total - fs_complete) / (fs_complete / t);
    speed = (fs_complete / t);
    days = 0;
    hours = 0;
    minutes = 0;
    if (seconds >= 60) {
      minutes = (seconds / 60);
      seconds %= 60;
      if (minutes >= 60) {
        hours = minutes / 60;
        minutes %= 60;
        if (hours >= 24) {
          days = hours / 24;
          hours %= 24;
        }
      }
    }
    printf("\rProcessed %llu MB out of %llu MB at %llu MB/s : %llu%% complete. "
           "ETA: %03d:%02d:%02d:%02d",
           fs_complete / 1000 / 1000, fs_total / 1000 / 1000,
           speed / 1000 / 1000, pct, days, hours, minutes, (int)seconds);
  }
}


x86 assembly (clang, -O0):
<progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,0x2ee6(%rip)
jne    116b <progress+0x4b>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x2ed2(%rip)
jmp    12b6 <progress+0x196>
imul   $0x64,-0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1040 <time@plt>
sub    0x2eb4(%rip),%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     12b6 <progress+0x196>
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3c,-0x24(%rbp)
jl     1247 <progress+0x127>
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x3c,-0x14(%rbp)
jl     1242 <progress+0x122>
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x18,-0x10(%rbp)
jl     123d <progress+0x11d>
mov    -0x10(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
jmp    1242 <progress+0x122>
jmp    1247 <progress+0x127>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
mov    -0xc(%rbp),%r9d
mov    -0x10(%rbp),%r11d
mov    -0x14(%rbp),%r10d
mov    -0x24(%rbp),%eax
lea    0xd5c(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmpq   $0x0,0x2f08(%rip)
je     11e7 <progress+0xc7>
mov    %esi,%ebp
mov    %edi,%ebx
imul   $0x64,%edi,%eax
cltd
idiv   %esi
mov    %eax,%r14d
xor    %r15d,%r15d
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%rcx
sub    0x2ee2(%rip),%ecx
je     126a <progress+0x14a>
mov    %ebp,%esi
sub    %ebx,%esi
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    %esi,%eax
cltd
idiv   %ecx
cmp    $0x3c,%eax
jl     11f7 <progress+0xd7>
mov    %eax,%edx
mov    $0x88888889,%esi
mov    %rdx,%r10
imul   %rsi,%r10
shr    $0x25,%r10
imul   $0x3c,%r10d,%edi
mov    %eax,%r11d
sub    %edi,%r11d
cmp    $0xe10,%eax
jb     1202 <progress+0xe2>
mov    $0x91a2b3c5,%r12d
imul   %rdx,%r12
shr    $0x2b,%r12
mov    %r10d,%edi
imul   %rsi,%rdi
shr    $0x25,%rdi
imul   $0x3c,%edi,%esi
sub    %esi,%r10d
cmp    $0x15180,%eax
jb     1205 <progress+0xe5>
mov    $0xc22e4507,%r15d
imul   %rdx,%r15
shr    $0x30,%r15
mov    %r12d,%eax
mov    $0xaaaaaaab,%edx
imul   %rax,%rdx
shr    $0x24,%rdx
shl    $0x3,%edx
lea    (%rdx,%rdx,2),%eax
sub    %eax,%r12d
jmp    1205 <progress+0xe5>
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,0x2e43(%rip)
jmp    126a <progress+0x14a>
xor    %r10d,%r10d
xor    %r12d,%r12d
mov    %eax,%r11d
jmp    1205 <progress+0xe5>
xor    %r12d,%r12d
movslq %ebx,%rax
imul   $0x431bde83,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x32,%rsi
add    %eax,%esi
movslq %ebp,%rax
imul   $0x431bde83,%rax,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x32,%rdx
add    %eax,%edx
movslq %ecx,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x32,%rcx
add    %eax,%ecx
sub    $0x8,%rsp
lea    0xdab(%rip),%rdi
mov    %r14d,%r8d
mov    %r15d,%r9d
push   %r11
push   %r10
push   %r12
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@progress.start = internal global i64 0
@.str = [91 x i8] c"\0DProcessed %llu MB out of %llu MB at %llu MB/s : %llu%% complete. ETA: %03d:%02d:%02d:%02d\00"
define void @progress(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %11
%12 = load i64, i64* @progress.start
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i64 @time(i32 0)
store i64 %15, i64* @progress.start
br label %77
16: ; preds = %2
%17 = load i32, i32* %3
%18 = mul nsw i32 100, %17
%19 = load i32, i32* %4
%20 = sdiv i32 %18, %19
store i32 %20, i32* %9
%21 = call i64 @time(i32 0)
%22 = load i64, i64* @progress.start
%23 = sub nsw i64 %21, %22
%24 = trunc i64 %23 to i32
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %77
27: ; preds = %16
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = sub nsw i32 %28, %29
%31 = load i32, i32* %3
%32 = load i32, i32* %8
%33 = sdiv i32 %31, %32
%34 = sdiv i32 %30, %33
store i32 %34, i32* %11
%35 = load i32, i32* %3
%36 = load i32, i32* %8
%37 = sdiv i32 %35, %36
store i32 %37, i32* %10
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%38 = load i32, i32* %11
%39 = icmp sge i32 %38, 60
br i1 %39, label %40, label %61
40: ; preds = %27
%41 = load i32, i32* %11
%42 = sdiv i32 %41, 60
store i32 %42, i32* %7
%43 = load i32, i32* %11
%44 = srem i32 %43, 60
store i32 %44, i32* %11
%45 = load i32, i32* %7
%46 = icmp sge i32 %45, 60
br i1 %46, label %47, label %60
47: ; preds = %40
%48 = load i32, i32* %7
%49 = sdiv i32 %48, 60
store i32 %49, i32* %6
%50 = load i32, i32* %7
%51 = srem i32 %50, 60
store i32 %51, i32* %7
%52 = load i32, i32* %6
%53 = icmp sge i32 %52, 24
br i1 %53, label %54, label %59
54: ; preds = %47
%55 = load i32, i32* %6
%56 = sdiv i32 %55, 24
store i32 %56, i32* %5
%57 = load i32, i32* %6
%58 = srem i32 %57, 24
store i32 %58, i32* %6
br label %59
59: ; preds = %54, %47
br label %60
60: ; preds = %59, %40
br label %61
61: ; preds = %60, %27
%62 = load i32, i32* %3
%63 = sdiv i32 %62, 1000
%64 = sdiv i32 %63, 1000
%65 = load i32, i32* %4
%66 = sdiv i32 %65, 1000
%67 = sdiv i32 %66, 1000
%68 = load i32, i32* %10
%69 = sdiv i32 %68, 1000
%70 = sdiv i32 %69, 1000
%71 = load i32, i32* %9
%72 = load i32, i32* %5
%73 = load i32, i32* %6
%74 = load i32, i32* %7
%75 = load i32, i32* %11
%76 = call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %64, i32 %67, i32 %70, i32 %71, i32 %72, i32 %73, i32 %74, i32 %75)
br label %77
77: ; preds = %14, %61, %16
ret void
}

LLVM IR (-O2):
@progress.start = internal unnamed_addr global i64 0
@.str = [91 x i8] c"\0DProcessed %llu MB out of %llu MB at %llu MB/s : %llu%% complete. ETA: %03d:%02d:%02d:%02d\00"
define void @progress(i32 %0, i32 %1) {
%3 = load i64, i64* @progress.start
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i64 @time(i32 0)
store i64 %6, i64* @progress.start
br label %40
7: ; preds = %2
%8 = mul nsw i32 %0, 100
%9 = sdiv i32 %8, %1
%10 = tail call i64 @time(i32 0)
%11 = load i64, i64* @progress.start
%12 = sub nsw i64 %10, %11
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %40, label %15
15: ; preds = %7
%16 = sub nsw i32 %1, %0
%17 = sdiv i32 %0, %13
%18 = sdiv i32 %16, %17
%19 = icmp sgt i32 %18, 59
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = udiv i32 %18, 60
%22 = urem i32 %18, 60
%23 = icmp ugt i32 %18, 3599
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = udiv i32 %18, 3600
%26 = urem i32 %21, 60
%27 = icmp ugt i32 %18, 86399
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = udiv i32 %18, 86400
%30 = urem i32 %25, 24
br label %31
31: ; preds = %20, %28, %24, %15
%32 = phi i32 [ %26, %28 ], [ %26, %24 ], [ %21, %20 ], [ 0, %15 ]
%33 = phi i32 [ %30, %28 ], [ %25, %24 ], [ 0, %20 ], [ 0, %15 ]
%34 = phi i32 [ %29, %28 ], [ 0, %24 ], [ 0, %20 ], [ 0, %15 ]
%35 = phi i32 [ %22, %28 ], [ %22, %24 ], [ %22, %20 ], [ %18, %15 ]
%36 = sdiv i32 %0, 1000000
%37 = sdiv i32 %1, 1000000
%38 = sdiv i32 %17, 1000000
%39 = tail call i32 @printf(i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %37, i32 %38, i32 %9, i32 %34, i32 %33, i32 %32, i32 %35)
br label %40
40: ; preds = %7, %31, %5
ret void
}