#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*/ stdin;
void load_bar(int step, int total_steps, int resolution, int width) {
  if (total_steps / resolution == 0)
    return;
  if (step % (total_steps / resolution) != 0)
    return;
  float ratio = step / (float)total_steps;
  int count = ratio * width;
  printf("%3d%% [", (int)(ratio * 100));
  for (int x = 0; x < count; x++)
    printf("=");
  for (int x = count; x < width; ++x)
    printf(" ");
  printf("]\r");
  fflush(stdin);
}


x86 assembly (clang, -O0):
<load_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
cmp    $0x0,%eax
jne    1149 <load_bar+0x29>
jmp    122c <load_bar+0x10c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
cmp    $0x0,%edx
je     116c <load_bar+0x4c>
jmp    122c <load_bar+0x10c>
cvtsi2ssl -0x4(%rbp),%xmm0
cvtsi2ssl -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtsi2ssl -0x10(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x18(%rbp)
movss  0xe64(%rip),%xmm0
mulss  -0x14(%rbp),%xmm0
cvttss2si %xmm0,%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11e2 <load_bar+0xc2>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <load_bar+0x9a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1210 <load_bar+0xf0>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e8 <load_bar+0xc8>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_bar>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %edx,%ecx
mov    %esi,%eax
cltd
idiv   %ecx
test   %eax,%eax
je     114c <load_bar+0x1c>
mov    %eax,%ecx
mov    %edi,%eax
cltd
idiv   %ecx
test   %edx,%edx
je     1151 <load_bar+0x21>
pop    %rbx
pop    %r14
pop    %rbp
ret
cvtsi2ss %edi,%xmm0
cvtsi2ss %esi,%xmm1
cvtsi2ss %ebx,%xmm2
divss  %xmm1,%xmm0
mulss  %xmm0,%xmm2
cvttss2si %xmm2,%r14d
mulss  0xe8e(%rip),%xmm0
cvttss2si %xmm0,%esi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    119f <load_bar+0x6f>
mov    %r14d,%ebp
nopl   0x0(%rax)
mov    $0x3d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    1190 <load_bar+0x60>
cmp    %ebx,%r14d
jge    11bf <load_bar+0x8f>
sub    %r14d,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11b0 <load_bar+0x80>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fflush@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%3d%% [\00"
@.str.1 = [2 x i8] c"=\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"]\0D\00"
@stdin = global i32 0
define void @load_bar(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %6
%14 = load i32, i32* %7
%15 = sdiv i32 %13, %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
br label %65
18: ; preds = %4
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = load i32, i32* %7
%22 = sdiv i32 %20, %21
%23 = srem i32 %19, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br label %65
26: ; preds = %18
%27 = load i32, i32* %5
%28 = sitofp i32 %27 to float
%29 = load i32, i32* %6
%30 = sitofp i32 %29 to float
%31 = fdiv float %28, %30
store float %31, float* %9
%32 = load float, float* %9
%33 = load i32, i32* %8
%34 = sitofp i32 %33 to float
%35 = fmul float %32, %34
%36 = fptosi float %35 to i32
store i32 %36, i32* %10
%37 = load float, float* %9
%38 = fmul float %37, 1.000000e+02
%39 = fptosi float %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %39)
store i32 0, i32* %11
br label %41
41: ; preds = %47, %26
%42 = load i32, i32* %11
%43 = load i32, i32* %10
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %50
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %41
50: ; preds = %41
%51 = load i32, i32* %10
store i32 %51, i32* %12
br label %52
52: ; preds = %58, %50
%53 = load i32, i32* %12
%54 = load i32, i32* %8
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56
%59 = load i32, i32* %12
%60 = add nsw i32 %59, 1
store i32 %60, i32* %12
br label %52
61: ; preds = %52
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @stdin
%64 = call i32 @fflush(i32 %63)
br label %65
65: ; preds = %61, %25, %17
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%3d%% [\00"
@.str.3 = [3 x i8] c"]\0D\00"
@stdin = global i32 0
define void @load_bar(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sdiv i32 %1, %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %37, label %7
7: ; preds = %4
%8 = srem i32 %0, %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %37
10: ; preds = %7
%11 = sitofp i32 %0 to float
%12 = sitofp i32 %1 to float
%13 = fdiv float %11, %12
%14 = sitofp i32 %3 to float
%15 = fmul float %13, %14
%16 = fptosi float %15 to i32
%17 = fmul float %13, 1.000000e+02
%18 = fptosi float %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp sgt i32 %16, 0
br i1 %20, label %23, label %21
21: ; preds = %23, %10
%22 = icmp slt i32 %16, %3
br i1 %22, label %32, label %28
23: ; preds = %10, %23
%24 = phi i32 [ %26, %23 ], [ 0, %10 ]
%25 = tail call i32 @putchar(i32 61)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, %16
br i1 %27, label %21, label %23
28: ; preds = %32, %21
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = tail call i32 @fflush(i32 %30)
br label %37
32: ; preds = %21, %32
%33 = phi i32 [ %35, %32 ], [ %16, %21 ]
%34 = tail call i32 @putchar(i32 32)
%35 = add i32 %33, 1
%36 = icmp eq i32 %35, %3
br i1 %36, label %28, label %32
37: ; preds = %7, %4, %28
ret void
}