#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 *, ...);
int /*<<< orphan*/ stdout;
void print_progress_bar(unsigned int current, unsigned int total) {
  unsigned int numTicks = current * 40 / total;
  unsigned int i;
  printf("\rLoading [");
  for (i = 0; i < numTicks; i++)
    printf("=");
  for (; i < 40; i++)
    printf(" ");
  printf("] (%d%%)", current * 100 / total);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<print_progress_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
imul   $0x28,-0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0xc(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1177 <print_progress_bar+0x57>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114f <print_progress_bar+0x2f>
jmp    117c <print_progress_bar+0x5c>
cmpl   $0x28,-0x10(%rbp)
jae    11a2 <print_progress_bar+0x82>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117c <print_progress_bar+0x5c>
imul   $0x64,-0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_progress_bar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
lea    0x0(,%r14,8),%eax
lea    (%rax,%rax,4),%ebp
lea    0xeb0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r15d,%ebp
jb     119f <print_progress_bar+0x6f>
mov    %ebp,%eax
xor    %edx,%edx
div    %r15d
cmp    $0x2,%eax
mov    $0x1,%r12d
cmovae %eax,%r12d
mov    $0xffffffff,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ebp
mov    $0x3d,%edi
call   1030 <putchar@plt>
lea    0x1(%rbp),%ebx
add    $0x2,%ebp
cmp    %r12d,%ebp
jne    1180 <print_progress_bar+0x50>
cmp    $0x26,%ebx
ja     11be <print_progress_bar+0x8e>
add    $0x1,%ebx
add    $0xffffffd8,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
inc    %ebx
jne    11b0 <print_progress_bar+0x80>
imul   $0x64,%r14d,%eax
xor    %edx,%edx
div    %r15d
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fflush@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"\0DLoading [\00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [9 x i8] c"] (%d%%)\00"
@stdout = global i32 0
define void @print_progress_bar(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = mul i32 %7, 40
%9 = load i32, i32* %4
%10 = udiv i32 %8, %9
store i32 %10, i32* %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %12
12: ; preds = %18, %2
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16
%19 = load i32, i32* %6
%20 = add i32 %19, 1
store i32 %20, i32* %6
br label %12
21: ; preds = %12
br label %22
22: ; preds = %27, %21
%23 = load i32, i32* %6
%24 = icmp ult i32 %23, 40
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25
%28 = load i32, i32* %6
%29 = add i32 %28, 1
store i32 %29, i32* %6
br label %22
30: ; preds = %22
%31 = load i32, i32* %3
%32 = mul i32 %31, 100
%33 = load i32, i32* %4
%34 = udiv i32 %32, %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"\0DLoading [\00"
@.str.3 = [9 x i8] c"] (%d%%)\00"
@stdout = global i32 0
define void @print_progress_bar(i32 %0, i32 %1) {
%3 = mul i32 %0, 40
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = icmp ult i32 %3, %1
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = udiv i32 %3, %1
%8 = call i32 @llvm.umax.i32(i32 %7, i32 1)
br label %13
9: ; preds = %13
%10 = icmp ult i32 %14, 39
br i1 %10, label %11, label %23
11: ; preds = %2, %9
%12 = phi i32 [ 0, %2 ], [ %16, %9 ]
br label %18
13: ; preds = %6, %13
%14 = phi i32 [ %16, %13 ], [ 0, %6 ]
%15 = tail call i32 @putchar(i32 61)
%16 = add nuw i32 %14, 1
%17 = icmp eq i32 %16, %8
br i1 %17, label %9, label %13
18: ; preds = %11, %18
%19 = phi i32 [ %21, %18 ], [ %12, %11 ]
%20 = tail call i32 @putchar(i32 32)
%21 = add i32 %19, 1
%22 = icmp eq i32 %21, 40
br i1 %22, label %23, label %18
23: ; preds = %18, %9
%24 = mul i32 %0, 100
%25 = udiv i32 %24, %1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stdout
%28 = tail call i32 @fflush(i32 %27)
ret void
}