#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*/);
int /*<<< orphan*/ printf(char *, char, short, char *, char const *);
int /*<<< orphan*/ stdout;
void progressbar(unsigned long min, unsigned long max, unsigned long val,
                 const char *comment) {
  static unsigned short counter = 0;
  short percent =
      100 * (((float)val + 0.5 - (float)min) / (float)max - (float)min);
  int i;
  char pgbar[12];
  char *anim = "-\\|/";
  for (i = 0; i < percent / 10 && i < 11; i++)
    pgbar[i] = '=';
  pgbar[i] = '>';
  pgbar[i + 1] = '\0';
  printf("\r%c %3d%% [%-10.10s] %-60.60s", anim[counter % 4], percent, pgbar,
         comment);
  fflush(stdout);
  counter++;
}


x86 assembly (clang, -O0):
<progressbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x48(%rbp)
test   %rax,%rax
movss  %xmm0,-0x44(%rbp)
js     1178 <progressbar+0x58>
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe77(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x50(%rbp)
test   %rax,%rax
movss  %xmm0,-0x4c(%rbp)
js     11cf <progressbar+0xaf>
movss  -0x50(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
movsd  -0x58(%rbp),%xmm0
movss  -0x4c(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  %xmm1,-0x70(%rbp)
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x60(%rbp)
test   %rax,%rax
movss  %xmm0,-0x5c(%rbp)
js     1228 <progressbar+0x108>
movss  -0x60(%rbp),%xmm0
movss  %xmm0,-0x5c(%rbp)
movsd  -0x70(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm0
movss  -0x5c(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
movsd  0xdbd(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %ax,-0x22(%rbp)
lea    0xdb2(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
movswl -0x22(%rbp),%eax
mov    $0xa,%esi
cltd
idiv   %esi
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x71(%rbp)
jge    1291 <progressbar+0x171>
cmpl   $0xb,-0x28(%rbp)
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    12a1 <progressbar+0x181>
jmp    12b8 <progressbar+0x198>
movslq -0x28(%rbp),%rax
movb   $0x3d,-0x34(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1269 <progressbar+0x149>
movslq -0x28(%rbp),%rax
movb   $0x3e,-0x34(%rbp,%rax,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x34(%rbp,%rax,1)
mov    -0x40(%rbp),%rax
mov    %rax,-0x80(%rbp)
movzwl 0x2d57(%rip),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x80(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x22(%rbp),%ax
lea    -0x34(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xd13(%rip),%rdi
movsbl %dl,%esi
movswl %ax,%edx
call   1030 <printf@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    0x2d12(%rip),%ax
add    $0x1,%ax
mov    %ax,0x2d07(%rip)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progressbar>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
test   %rdx,%rdx
js     1147 <progressbar+0x17>
cvtsi2ss %rdx,%xmm0
jmp    115c <progressbar+0x2c>
mov    %rdx,%rax
shr    %rax
and    $0x1,%edx
or     %rax,%rdx
cvtsi2ss %rdx,%xmm0
addss  %xmm0,%xmm0
cvtss2sd %xmm0,%xmm0
addsd  0xe98(%rip),%xmm0
test   %rdi,%rdi
js     1174 <progressbar+0x44>
cvtsi2ss %rdi,%xmm1
jmp    1189 <progressbar+0x59>
mov    %rdi,%rax
shr    %rax
and    $0x1,%edi
or     %rax,%rdi
cvtsi2ss %rdi,%xmm1
addss  %xmm1,%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
test   %rsi,%rsi
js     119d <progressbar+0x6d>
cvtsi2ss %rsi,%xmm2
jmp    11b2 <progressbar+0x82>
mov    %rsi,%rax
shr    %rax
and    $0x1,%esi
or     %rax,%rsi
cvtsi2ss %rsi,%xmm2
addss  %xmm2,%xmm2
cvtss2sd %xmm2,%xmm2
divsd  %xmm2,%xmm0
subsd  %xmm1,%xmm0
mulsd  0xe42(%rip),%xmm0
cvttsd2si %xmm0,%ebp
xor    %eax,%eax
cmp    $0xa,%bp
jl     1205 <progressbar+0xd5>
movzwl %bp,%eax
imul   $0xcccd,%eax,%eax
shr    $0x13,%eax
add    $0xffffffff,%eax
cmp    $0xa,%ax
mov    $0xa,%ebx
cmovb  %eax,%ebx
add    $0x1,%ebx
movzwl %bx,%edx
lea    0x4(%rsp),%rdi
mov    $0x3d,%esi
call   1040 <memset@plt>
movzwl %bx,%eax
mov    %eax,%eax
movw   $0x3e,0x4(%rsp,%rax,1)
movzwl 0x2e27(%rip),%eax
and    $0x3,%eax
lea    0xdf1(%rip),%rcx
movsbl (%rax,%rcx,1),%esi
movswl %bp,%edx
lea    0xde8(%rip),%rdi
lea    0x4(%rsp),%rcx
mov    %r14,%r8
call   1030 <printf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
addw   $0x1,0x2dec(%rip)
01
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@progressbar.counter = internal global i16 0
@.str = [5 x i8] c"-\\|/\00"
@.str.1 = [30 x i8] c"\0D%c %3d%% [%-10.10s] %-60.60s\00"
@stdout = global i32 0
define void @progressbar(i64 %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i16
%10 = alloca i32
%11 = alloca [12 x i8]
%12 = alloca i8*
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%13 = load i64, i64* %7
%14 = uitofp i64 %13 to float
%15 = fpext float %14 to double
%16 = fadd double %15, 5.000000e-01
%17 = load i64, i64* %5
%18 = uitofp i64 %17 to float
%19 = fpext float %18 to double
%20 = fsub double %16, %19
%21 = load i64, i64* %6
%22 = uitofp i64 %21 to float
%23 = fpext float %22 to double
%24 = fdiv double %20, %23
%25 = load i64, i64* %5
%26 = uitofp i64 %25 to float
%27 = fpext float %26 to double
%28 = fsub double %24, %27
%29 = fmul double 1.000000e+02, %28
%30 = fptosi double %29 to i16
store i16 %30, i16* %9
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %10
br label %31
31: ; preds = %46, %4
%32 = load i32, i32* %10
%33 = load i16, i16* %9
%34 = sext i16 %33 to i32
%35 = sdiv i32 %34, 10
%36 = icmp slt i32 %32, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* %10
%39 = icmp slt i32 %38, 11
br label %40
40: ; preds = %37, %31
%41 = phi i1 [ false, %31 ], [ %39, %37 ]
br i1 %41, label %42, label %49
42: ; preds = %40
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 %44
store i8 61, i8* %45
br label %46
46: ; preds = %42
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 1
store i32 %48, i32* %10
br label %31
49: ; preds = %40
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 %51
store i8 62, i8* %52
%53 = load i32, i32* %10
%54 = add nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 %55
store i8 0, i8* %56
%57 = load i8*, i8** %12
%58 = load i16, i16* @progressbar.counter
%59 = zext i16 %58 to i32
%60 = srem i32 %59, 4
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
%63 = load i8, i8* %62
%64 = load i16, i16* %9
%65 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%66 = load i8*, i8** %8
%67 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8 signext %63, i16 signext %64, i8* %65, i8* %66)
%68 = load i32, i32* @stdout
%69 = call i32 @fflush(i32 %68)
%70 = load i16, i16* @progressbar.counter
%71 = add i16 %70, 1
store i16 %71, i16* @progressbar.counter
ret void
}

LLVM IR (-O2):
@progressbar.counter = internal unnamed_addr global i16 0
@.str = [5 x i8] c"-\\|/\00"
@.str.1 = [30 x i8] c"\0D%c %3d%% [%-10.10s] %-60.60s\00"
@stdout = global i32 0
define void @progressbar(i64 %0, i64 %1, i64 %2, i8* %3) {
%5 = alloca [12 x i8]
%6 = uitofp i64 %2 to float
%7 = fpext float %6 to double
%8 = fadd double %7, 5.000000e-01
%9 = uitofp i64 %0 to float
%10 = fpext float %9 to double
%11 = fsub double %8, %10
%12 = uitofp i64 %1 to float
%13 = fpext float %12 to double
%14 = fdiv double %11, %13
%15 = fsub double %14, %10
%16 = fmul double %15, 1.000000e+02
%17 = fptosi double %16 to i16
%18 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%19 = icmp sgt i16 %17, 9
br i1 %19, label %20, label %28
20: ; preds = %4
%21 = udiv i16 %17, 10
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%23 = add nsw i16 %21, -1
%24 = call i16 @llvm.umin.i16(i16 %23, i16 10)
%25 = add nuw nsw i16 %24, 1
%26 = zext i16 %25 to i64
%27 = zext i16 %25 to i32
br label %28
28: ; preds = %20, %4
%29 = phi i32 [ 0, %4 ], [ %27, %20 ]
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 %30
store i8 62, i8* %31
%32 = add nuw nsw i32 %29, 1
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i16, i16* @progressbar.counter
%36 = and i16 %35, 3
%37 = zext i16 %36 to i64
%38 = getelementptr inbounds [5 x i8], [5 x i8]* @.str, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8 signext %39, i16 signext %17, i8* %18, i8* %3)
%41 = load i32, i32* @stdout
%42 = call i32 @fflush(i32 %41)
%43 = load i16, i16* @progressbar.counter
%44 = add i16 %43, 1
store i16 %44, i16* @progressbar.counter
ret void
}