#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 off_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned int, int, char *);
int /*<<< orphan*/ stdout;
void display_progressbar(off_t offset, unsigned int n) {
  off_t to_display;
  static unsigned int old_n = -1;
  static int gib_mode = 0;
  static off_t old_to_display = 0;
  if (offset < 1024 * 1024 * 1024) {
    to_display = offset / 1024 * 10 / 1024;
  } else {
    gib_mode = 1;
    to_display = offset / (1024 * 1024) * 10 / 1024;
  }
  if (n != old_n || to_display != old_to_display) {
    printf("\rRecovered files: %4u        Analyzed: %4.1f %s  ", n,
           to_display / 10.0, gib_mode ? "GiB" : "MiB");
    fflush(stdout);
    old_n = n;
    old_to_display = to_display;
  }
}


x86 assembly (clang, -O0):
<display_progressbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x40000000,-0x4(%rbp)
jge    1159 <display_progressbar+0x39>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
imul   $0xa,%eax,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    117c <display_progressbar+0x5c>
movl   $0x1,0x2ed5(%rip)
mov    -0x4(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
imul   $0xa,%eax,%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
cmp    0x2eab(%rip),%eax
jne    119a <display_progressbar+0x7a>
mov    -0xc(%rbp),%eax
cmp    0x2ea8(%rip),%eax
je     11f9 <display_progressbar+0xd9>
mov    -0x8(%rbp),%esi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe56(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    0x2e80(%rip),%edi
lea    0xe7f(%rip),%rcx
lea    0xe74(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x8(%rbp),%eax
mov    %eax,0x2e40(%rip)
mov    -0xc(%rbp),%eax
mov    %eax,0x2e43(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_progressbar>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
cmp    $0x3fffffff,%edi
jg     113d <display_progressbar+0x1d>
lea    0x3ff(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
sar    $0xa,%eax
jmp    1149 <display_progressbar+0x29>
movb   $0x1,0x2ef4(%rip)
shr    $0x14,%edi
mov    %edi,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rax,4),%ebp
add    $0x3ff,%ebp
test   %ecx,%ecx
cmovns %ecx,%ebp
sar    $0xa,%ebp
cmp    %ebx,0x2ecb(%rip)
jne    116f <display_progressbar+0x4f>
cmp    0x2ecf(%rip),%ebp
je     11c0 <display_progressbar+0xa0>
cvtsi2sd %ebp,%xmm0
divsd  0xe85(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xeb4(%rip),%rax
lea    0xeb1(%rip),%rcx
cmpb   $0x0,0x2ea4(%rip)
cmovne %rax,%rcx
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    %ebx,0x2e76(%rip)
mov    %ebp,0x2e7c(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@display_progressbar.old_n = internal global i32 -1
@display_progressbar.gib_mode = internal global i32 0
@display_progressbar.old_to_display = internal global i32 0
@.str = [50 x i8] c"\0DRecovered files: %4u Analyzed: %4.1f %s \00"
@.str.1 = [4 x i8] c"GiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@stdout = global i32 0
define void @display_progressbar(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 1073741824
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %3
%10 = sdiv i32 %9, 1024
%11 = mul nsw i32 %10, 10
%12 = sdiv i32 %11, 1024
store i32 %12, i32* %5
br label %18
13: ; preds = %2
store i32 1, i32* @display_progressbar.gib_mode
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 1048576
%16 = mul nsw i32 %15, 10
%17 = sdiv i32 %16, 1024
store i32 %17, i32* %5
br label %18
18: ; preds = %13, %8
%19 = load i32, i32* %4
%20 = load i32, i32* @display_progressbar.old_n
%21 = icmp ne i32 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %5
%24 = load i32, i32* @display_progressbar.old_to_display
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22, %18
%27 = load i32, i32* %4
%28 = load i32, i32* %5
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 1.000000e+01
%31 = fptosi double %30 to i32
%32 = load i32, i32* @display_progressbar.gib_mode
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%36 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %31, i8* %35)
%37 = load i32, i32* @stdout
%38 = call i32 @fflush(i32 %37)
%39 = load i32, i32* %4
store i32 %39, i32* @display_progressbar.old_n
%40 = load i32, i32* %5
store i32 %40, i32* @display_progressbar.old_to_display
br label %41
41: ; preds = %26, %22
ret void
}

LLVM IR (-O2):
@display_progressbar.old_n = internal unnamed_addr global i32 -1
@display_progressbar.gib_mode = internal unnamed_addr global i1 false
@display_progressbar.old_to_display = internal unnamed_addr global i32 0
@.str = [50 x i8] c"\0DRecovered files: %4u Analyzed: %4.1f %s \00"
@.str.1 = [4 x i8] c"GiB\00"
@.str.2 = [4 x i8] c"MiB\00"
@stdout = global i32 0
define void @display_progressbar(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 1073741824
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = sdiv i32 %0, 1024
br label %8
6: ; preds = %2
store i1 true, i1* @display_progressbar.gib_mode
%7 = lshr i32 %0, 20
br label %8
8: ; preds = %6, %4
%9 = phi i32 [ %5, %4 ], [ %7, %6 ]
%10 = mul nsw i32 %9, 10
%11 = sdiv i32 %10, 1024
%12 = load i32, i32* @display_progressbar.old_n
%13 = icmp eq i32 %12, %1
%14 = load i32, i32* @display_progressbar.old_to_display
%15 = icmp eq i32 %11, %14
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %26, label %17
17: ; preds = %8
%18 = sitofp i32 %11 to double
%19 = fdiv double %18, 1.000000e+01
%20 = fptosi double %19 to i32
%21 = load i1, i1* @display_progressbar.gib_mode
%22 = select i1 %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %20, i8* %22)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fflush(i32 %24)
store i32 %1, i32* @display_progressbar.old_n
store i32 %11, i32* @display_progressbar.old_to_display
br label %26
26: ; preds = %8, %17
ret void
}