#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 */
scalar_t__ floor(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char const);
void PrintProgressBar(double percentage, int lineabove) {
  static int prevbarpos = -1;
  const char symbols[] = "\x2D\x2D\x2D\x2D\x61\x2D";
  const int barsize = 50;
  const int numchars = 5;
  const int leftspaces = 2;
  int barpos, charpos, i;
  if (percentage < 0.0)
    percentage = 0.0;
  if (percentage > 100.0)
    percentage = 100.0;
  if (percentage == 0.0 && prevbarpos == -1) {
    for (i = 0; i < (leftspaces - 1); i++)
      putchar(' ');
    printf("[");
    for (i = 0; i < barsize; i++)
      putchar(symbols[5]);
    printf("]\n");
    prevbarpos = 0;
    return;
  }
  barpos = (int)floor(percentage * ((double)barsize) / 100.0);
  charpos = (int)floor(percentage * (double)(barsize * numchars) / 100.0) -
            (barpos * numchars);
  if (barpos == barsize) {
    barpos = (barsize - 1);
    charpos = (numchars - 1);
  }
  printf("\x1B(0");
  if (lineabove)
    printf("\x1B[99D\x1B[K");
  if (lineabove)
    printf("\x1B[1F");
  i = prevbarpos;
  printf("\x1B[%dC", (leftspaces + i));
  while ((i++) < barpos)
    putchar(symbols[4]);
  putchar(symbols[charpos]);
  printf("\x1B[%dD", (leftspaces + i));
  printf("\x1B(B");
  prevbarpos = barpos;
}


x86 assembly (clang, -O0):
<PrintProgressBar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    0xed2(%rip),%eax
mov    %eax,-0x13(%rbp)
mov    0xecc(%rip),%ax
mov    %ax,-0xf(%rbp)
mov    0xec4(%rip),%al
mov    %al,-0xd(%rbp)
movl   $0x32,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
movl   $0x2,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1188 <PrintProgressBar+0x58>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe6b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ac <PrintProgressBar+0x7c>
movsd  0xe59(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    124d <PrintProgressBar+0x11d>
jp     124d <PrintProgressBar+0x11d>
cmpl   $0xffffffff,0x2e6d(%rip)
jne    124d <PrintProgressBar+0x11d>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jge    11fa <PrintProgressBar+0xca>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d8 <PrintProgressBar+0xa8>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x32,-0x2c(%rbp)
jge    1230 <PrintProgressBar+0x100>
movsbl -0xe(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120f <PrintProgressBar+0xdf>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,0x2df0(%rip)
jmp    1363 <PrintProgressBar+0x233>
movsd  0xdbb(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xd9e(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
mov    %eax,-0x24(%rbp)
movsd  0xd92(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xd7d(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1050 <floor@plt>
imul   $0x5,-0x24(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x32,-0x24(%rbp)
jne    12ad <PrintProgressBar+0x17d>
movl   $0x31,-0x24(%rbp)
movl   $0x4,-0x28(%rbp)
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
je     12d3 <PrintProgressBar+0x1a3>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
je     12eb <PrintProgressBar+0x1bb>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d47(%rip),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
add    $0x2,%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    -0x24(%rbp),%eax
jge    132a <PrintProgressBar+0x1fa>
movsbl -0xf(%rbp),%edi
call   1030 <putchar@plt>
jmp    1308 <PrintProgressBar+0x1d8>
movslq -0x28(%rbp),%rax
movsbl -0x13(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%esi
add    $0x2,%esi
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,0x2cd5(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintProgressBar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebp
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
maxsd  %xmm0,%xmm2
movsd  0xe9f(%rip),%xmm4
movapd %xmm4,%xmm3
minsd  %xmm2,%xmm3
ucomisd %xmm1,%xmm3
jne    11c3 <PrintProgressBar+0x83>
jp     11c3 <PrintProgressBar+0x83>
cmpl   $0xffffffff,0x2ec8(%rip)
jne    11c3 <PrintProgressBar+0x83>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x5b,%edi
call   1030 <putchar@plt>
mov    $0x32,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x2d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11a0 <PrintProgressBar+0x60>
lea    0xe8b(%rip),%rdi
call   1040 <puts@plt>
xor    %r13d,%r13d
jmp    12c3 <PrintProgressBar+0x183>
movsd  0xe3d(%rip),%xmm0
mulsd  %xmm3,%xmm0
divsd  %xmm4,%xmm0
movsd  %xmm3,(%rsp)
call   1060 <floor@plt>
mov    %rax,%r15
movsd  (%rsp),%xmm0
mulsd  0xe23(%rip),%xmm0
divsd  0xe0b(%rip),%xmm0
call   1060 <floor@plt>
mov    %rax,%r14
lea    (%r15,%r15,4),%r12
cmp    $0x32,%r15d
mov    $0x31,%r13d
cmovne %r15d,%r13d
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
je     123d <PrintProgressBar+0xfd>
lea    0xdfb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdf6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
sub    %r12,%r14
mov    0x2dfa(%rip),%ebp
lea    0x2(%rbp),%esi
lea    0xde1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %r13d,%ebp
jge    1282 <PrintProgressBar+0x142>
mov    %r13d,%ebx
sub    %ebp,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x61,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    1270 <PrintProgressBar+0x130>
mov    %r13d,%ebp
cmp    $0x32,%r15d
movslq %r14d,%rax
mov    $0x4,%ecx
cmovne %rax,%rcx
lea    0xd7f(%rip),%rax
movsbl (%rcx,%rax,1),%edi
call   1030 <putchar@plt>
add    $0x3,%ebp
lea    0xd8b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,0x2d76(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PrintProgressBar.prevbarpos = internal global i32 -1
@__const.PrintProgressBar.symbols = [7 x i8] c"----a-\00"
@.str = [2 x i8] c"[\00"
@.str.1 = [3 x i8] c"]\0A\00"
@.str.2 = [4 x i8] c"\1B(0\00"
@.str.3 = [9 x i8] c"\1B[99D\1B[K\00"
@.str.4 = [5 x i8] c"\1B[1F\00"
@.str.5 = [6 x i8] c"\1B[%dC\00"
@.str.6 = [6 x i8] c"\1B[%dD\00"
@.str.7 = [4 x i8] c"\1B(B\00"
define void @PrintProgressBar(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca [7 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%12 = bitcast [7 x i8]* %5 to i8*
store i32 50, i32* %6
store i32 5, i32* %7
store i32 2, i32* %8
%13 = load double, double* %3
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %2
store double 0.000000e+00, double* %3
br label %16
16: ; preds = %15, %2
%17 = load double, double* %3
%18 = fcmp ogt double %17, 1.000000e+02
br i1 %18, label %19, label %20
19: ; preds = %16
store double 1.000000e+02, double* %3
br label %20
20: ; preds = %19, %16
%21 = load double, double* %3
%22 = fcmp oeq double %21, 0.000000e+00
br i1 %22, label %23, label %49
23: ; preds = %20
%24 = load i32, i32* @PrintProgressBar.prevbarpos
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %49
26: ; preds = %23
store i32 0, i32* %11
br label %27
27: ; preds = %32, %26
%28 = load i32, i32* %11
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = call i32 @putchar(i8 signext 32)
br label %32
32: ; preds = %30
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 1
store i32 %34, i32* %11
br label %27
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %37
37: ; preds = %44, %35
%38 = load i32, i32* %11
%39 = icmp slt i32 %38, 50
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 5
%42 = load i8, i8* %41
%43 = call i32 @putchar(i8 signext %42)
br label %44
44: ; preds = %40
%45 = load i32, i32* %11
%46 = add nsw i32 %45, 1
store i32 %46, i32* %11
br label %37
47: ; preds = %37
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* @PrintProgressBar.prevbarpos
br label %102
49: ; preds = %23, %20
%50 = load double, double* %3
%51 = fmul double %50, 5.000000e+01
%52 = fdiv double %51, 1.000000e+02
%53 = call i64 @floor(double %52)
%54 = trunc i64 %53 to i32
store i32 %54, i32* %9
%55 = load double, double* %3
%56 = fmul double %55, 2.500000e+02
%57 = fdiv double %56, 1.000000e+02
%58 = call i64 @floor(double %57)
%59 = trunc i64 %58 to i32
%60 = load i32, i32* %9
%61 = mul nsw i32 %60, 5
%62 = sub nsw i32 %59, %61
store i32 %62, i32* %10
%63 = load i32, i32* %9
%64 = icmp eq i32 %63, 50
br i1 %64, label %65, label %66
65: ; preds = %49
store i32 49, i32* %9
store i32 4, i32* %10
br label %66
66: ; preds = %65, %49
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%68 = load i32, i32* %4
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
%73 = load i32, i32* %4
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %77
77: ; preds = %75, %72
%78 = load i32, i32* @PrintProgressBar.prevbarpos
store i32 %78, i32* %11
%79 = load i32, i32* %11
%80 = add nsw i32 2, %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %87, %77
%83 = load i32, i32* %11
%84 = add nsw i32 %83, 1
store i32 %84, i32* %11
%85 = load i32, i32* %9
%86 = icmp slt i32 %83, %85
br i1 %86, label %87, label %91
87: ; preds = %82
%88 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 4
%89 = load i8, i8* %88
%90 = call i32 @putchar(i8 signext %89)
br label %82
91: ; preds = %82
%92 = load i32, i32* %10
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = call i32 @putchar(i8 signext %95)
%97 = load i32, i32* %11
%98 = add nsw i32 2, %97
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %98)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%101 = load i32, i32* %9
store i32 %101, i32* @PrintProgressBar.prevbarpos
br label %102
102: ; preds = %91, %47
ret void
}

LLVM IR (-O2):
@PrintProgressBar.prevbarpos = internal unnamed_addr global i32 -1
@__const.PrintProgressBar.symbols = [7 x i8] c"----a-\00"
@.str.2 = [4 x i8] c"\1B(0\00"
@.str.3 = [9 x i8] c"\1B[99D\1B[K\00"
@.str.4 = [5 x i8] c"\1B[1F\00"
@.str.5 = [6 x i8] c"\1B[%dC\00"
@.str.6 = [6 x i8] c"\1B[%dD\00"
@.str.7 = [4 x i8] c"\1B(B\00"
@str = [2 x i8] c"]\00"
define void @PrintProgressBar(double %0, i32 %1) {
%3 = fcmp olt double %0, 0.000000e+00
%4 = select i1 %3, double 0.000000e+00, double %0
%5 = fcmp ogt double %4, 1.000000e+02
%6 = select i1 %5, double 1.000000e+02, double %4
%7 = fcmp oeq double %6, 0.000000e+00
%8 = load i32, i32* @PrintProgressBar.prevbarpos
%9 = icmp eq i32 %8, -1
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = tail call i32 @putchar(i8 signext 32)
%13 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 91)
br label %14
14: ; preds = %11, %14
%15 = phi i32 [ 0, %11 ], [ %17, %14 ]
%16 = tail call i32 @putchar(i8 signext 45)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, 50
br i1 %18, label %19, label %14
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %59
21: ; preds = %2
%22 = fmul double %6, 5.000000e+01
%23 = fdiv double %22, 1.000000e+02
%24 = tail call i64 @floor(double %23)
%25 = trunc i64 %24 to i32
%26 = fmul double %6, 2.500000e+02
%27 = fdiv double %26, 1.000000e+02
%28 = tail call i64 @floor(double %27)
%29 = mul i64 %24, -5
%30 = add i64 %29, %28
%31 = icmp eq i32 %25, 50
%32 = select i1 %31, i32 49, i32 %25
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp eq i32 %1, 0
br i1 %34, label %38, label %35
35: ; preds = %21
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %21, %35
%39 = load i32, i32* @PrintProgressBar.prevbarpos
%40 = add nsw i32 %39, 2
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = icmp slt i32 %39, %32
br i1 %42, label %43, label %48
43: ; preds = %38, %43
%44 = phi i32 [ %45, %43 ], [ %39, %38 ]
%45 = add i32 %44, 1
%46 = tail call i32 @putchar(i8 signext 97)
%47 = icmp eq i32 %45, %32
br i1 %47, label %48, label %43
48: ; preds = %43, %38
%49 = phi i32 [ %39, %38 ], [ %32, %43 ]
%50 = shl i64 %30, 32
%51 = ashr exact i64 %50, 32
%52 = select i1 %31, i64 4, i64 %51
%53 = getelementptr inbounds [7 x i8], [7 x i8]* @__const.PrintProgressBar.symbols, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = tail call i32 @putchar(i8 signext %54)
%56 = add nsw i32 %49, 3
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %56)
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
br label %59
59: ; preds = %48, %19
%60 = phi i32 [ %32, %48 ], [ 0, %19 ]
store i32 %60, i32* @PrintProgressBar.prevbarpos
ret void
}