#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 */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
unsigned int pos_ceil(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
void progress_bar(long double complete, long double total) {
  unsigned int i, perc;
  static unsigned int old_perc = 0;
  perc = pos_ceil(100 * (complete / total));
  if (perc == old_perc)
    return;
  old_perc = perc;
  printf("\r%c[2K", 27);
  printf("%u%% ", perc);
  for (i = 0; i < perc / 2; i++)
    printf("#");
  fflush(stdout);
}


x86 assembly (clang, -O0):
<progress_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x10(%rbp)
fldt   -0x20(%rbp)
fdivrp %st,%st(1)
flds   0xeae(%rip)
fmulp  %st,%st(1)
fnstcw -0x2e(%rbp)
movzwl -0x2e(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x30(%rbp)
fldcw  -0x30(%rbp)
fistpl -0x2c(%rbp)
fldcw  -0x2e(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <pos_ceil@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    0x2ebb(%rip),%eax
jne    118c <progress_bar+0x5c>
jmp    11fb <progress_bar+0xcb>
mov    -0x28(%rbp),%eax
mov    %eax,0x2ea7(%rip)
lea    0xe68(%rip),%rdi
mov    $0x1b,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
jae    11ed <progress_bar+0xbd>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c0 <progress_bar+0x90>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress_bar>:
push   %rbx
sub    $0x10,%rsp
fldt   0x30(%rsp)
fldt   0x20(%rsp)
fdivp  %st,%st(1)
fmuls  0xeab(%rip)
fnstcw 0x8(%rsp)
movzwl 0x8(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0xa(%rsp)
fldcw  0xa(%rsp)
fistpl 0xc(%rsp)
fldcw  0x8(%rsp)
mov    0xc(%rsp),%edi
call   1040 <pos_ceil@plt>
cmp    0x2ec1(%rip),%eax
jne    118b <progress_bar+0x4b>
add    $0x10,%rsp
pop    %rbx
ret
mov    %eax,%ebx
mov    %eax,0x2eb1(%rip)
lea    0xe6a(%rip),%rdi
mov    $0x1b,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x2,%ebx
jb     11cf <progress_bar+0x8f>
shr    %ebx
nopl   (%rax)
mov    $0x23,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11c0 <progress_bar+0x80>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <fflush@plt>

LLVM IR (-O0):
@progress_bar.old_perc = internal global i32 0
@.str = [7 x i8] c"\0D%c[2K\00"
@.str.1 = [6 x i8] c"%u%% \00"
@.str.2 = [2 x i8] c"#\00"
@stdout = global i32 0
define void @progress_bar(x86_fp80 %0, x86_fp80 %1) {
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca i32
%6 = alloca i32
store x86_fp80 %0, x86_fp80* %3
store x86_fp80 %1, x86_fp80* %4
%7 = load x86_fp80, x86_fp80* %3
%8 = load x86_fp80, x86_fp80* %4
%9 = fdiv x86_fp80 %7, %8
%10 = fmul x86_fp80 0xK4005C800000000000000, %9
%11 = fptosi x86_fp80 %10 to i32
%12 = call i32 @pos_ceil(i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i32, i32* @progress_bar.old_perc
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %2
br label %35
17: ; preds = %2
%18 = load i32, i32* %6
store i32 %18, i32* @progress_bar.old_perc
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 27)
%20 = load i32, i32* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
store i32 0, i32* %5
br label %22
22: ; preds = %29, %17
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = udiv i32 %24, 2
%26 = icmp ult i32 %23, %25
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27
%30 = load i32, i32* %5
%31 = add i32 %30, 1
store i32 %31, i32* %5
br label %22
32: ; preds = %22
%33 = load i32, i32* @stdout
%34 = call i32 @fflush(i32 %33)
br label %35
35: ; preds = %32, %16
ret void
}

LLVM IR (-O2):
@progress_bar.old_perc = internal unnamed_addr global i32 0
@.str = [7 x i8] c"\0D%c[2K\00"
@.str.1 = [6 x i8] c"%u%% \00"
@stdout = global i32 0
define void @progress_bar(x86_fp80 %0, x86_fp80 %1) {
%3 = fdiv x86_fp80 %0, %1
%4 = fmul x86_fp80 %3, 0xK4005C800000000000000
%5 = fptosi x86_fp80 %4 to i32
%6 = tail call i32 @pos_ceil(i32 %5)
%7 = load i32, i32* @progress_bar.old_perc
%8 = icmp eq i32 %6, %7
br i1 %8, label %23, label %9
9: ; preds = %2
store i32 %6, i32* @progress_bar.old_perc
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 27)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%12 = icmp ult i32 %6, 2
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = lshr i32 %6, 1
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ %18, %15 ], [ 0, %13 ]
%17 = tail call i32 @putchar(i32 35)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, %14
br i1 %19, label %20, label %15
20: ; preds = %15, %9
%21 = load i32, i32* @stdout
%22 = tail call i32 @fflush(i32 %21)
br label %23
23: ; preds = %2, %20
ret void
}