#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*/ fprintf(int /*<<< orphan*/, char *, char *, int, char);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ stdout;
void progress(int percent, int finished) {
  char bar[] = "                    ";
  if (percent < 0)
    percent = 0;
  if (percent > 100)
    percent = 100;
  memset(bar, '#', percent / 5);
  fprintf(stdout, "\033[K[%s] %3d%%%c", bar, percent, finished ? '\n' : '\r');
  fflush(stdout);
}


x86 assembly (clang, -O0):
<progress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeb6(%rip),%eax
mov    %eax,-0x10(%rbp)
mov    0xeb1(%rip),%al
mov    %al,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1177 <progress+0x47>
movl   $0x0,-0x4(%rbp)
cmpl   $0x64,-0x4(%rbp)
jle    1188 <progress+0x58>
movl   $0x64,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
mov    $0x23,%esi
call   1030 <memset@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    -0x8(%rbp),%r8d
mov    $0xd,%eax
mov    $0xa,%esi
cmp    $0x0,%r8d
cmovne %esi,%eax
lea    0xe46(%rip),%rsi
movsbl %al,%r8d
call   1040 <fprintf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<progress>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
test   %edi,%edi
cmovns %edi,%eax
cmp    $0x64,%eax
mov    $0x64,%ebp
cmovb  %eax,%ebp
movabs $0x20202020202020,%rax
mov    %rax,0xd(%rsp)
movzbl %bpl,%eax
imul   $0xcd,%eax,%edx
shr    $0xa,%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x23,%esi
call   1030 <memset@plt>
mov    0x2e54(%rip),%r15
mov    (%r15),%edi
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
lea    (%rax,%rax,2),%r8d
add    $0xa,%r8d
lea    0xe70(%rip),%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1040 <fprintf@plt>
mov    (%r15),%edi
call   1050 <fflush@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.progress.bar = [21 x i8] c" \00"
@stdout = global i32 0
@.str = [16 x i8] c"\1B[K[%s] %3d%%%c\00"
define void @progress(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [21 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = bitcast [21 x i8]* %5 to i8*
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %10
10: ; preds = %9, %2
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 100
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 100, i32* %3
br label %14
14: ; preds = %13, %10
%15 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 5
%18 = call i32 @memset(i8* %15, i8 signext 35, i32 %17)
%19 = load i32, i32* @stdout
%20 = getelementptr inbounds [21 x i8], [21 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 10, i32 13
%26 = trunc i32 %25 to i8
%27 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %21, i8 signext %26)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
ret void
}

LLVM IR (-O2):
@__const.progress.bar = [21 x i8] c" \00"
@stdout = global i32 0
@.str = [16 x i8] c"\1B[K[%s] %3d%%%c\00"
define void @progress(i32 %0, i32 %1) {
%3 = alloca [21 x i8]
%4 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 0
%6 = select i1 %5, i32 %0, i32 0
%7 = icmp ult i32 %6, 100
%8 = select i1 %7, i32 %6, i32 100
%9 = trunc i32 %8 to i8
%10 = udiv i8 %9, 5
%11 = zext i8 %10 to i32
%12 = call i32 @memset(i8* %4, i8 signext 35, i32 %11)
%13 = load i32, i32* @stdout
%14 = icmp eq i32 %1, 0
%15 = select i1 %14, i8 13, i8 10
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %8, i8 signext %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
ret void
}