#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*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void loadbar(int tamanho, long baixado, long total, int reset) {
  int x, c;
  double ratio;
  static double repeat = 0;
  if (reset) {
    repeat = 0;
    return;
  }
  ratio = (double)baixado / total;
  if ((ratio - repeat) < 0.001)
    return;
  repeat = ratio;
  c = ratio * tamanho;
  printf("%3.1f%% [", ratio * 100);
  for (x = 0; x < c; x++)
    putchar('=');
  for (x = c; x < tamanho; x++)
    putchar(' ');
  printf("]\n\033[F\033[J");
}


x86 assembly (clang, -O0):
<loadbar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1150 <loadbar+0x30>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2eed(%rip)
jmp    1229 <loadbar+0x109>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
subsd  0x2ec6(%rip),%xmm1
movsd  0xe86(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1189 <loadbar+0x69>
jmp    1229 <loadbar+0x109>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2ea2(%rip)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
movsd  0xe55(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
lea    0xe51(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11f1 <loadbar+0xd1>
mov    $0x3d,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cd <loadbar+0xad>
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    121b <loadbar+0xfb>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f7 <loadbar+0xd7>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadbar>:
push   %rbp
push   %r14
push   %rbx
test   %ecx,%ecx
je     1135 <loadbar+0x15>
movq   $0x0,0x2f05(%rip)
jmp    115d <loadbar+0x3d>
cvtsi2sd %rsi,%xmm0
cvtsi2sd %rdx,%xmm1
divsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
subsd  0x2ee9(%rip),%xmm1
movsd  0xea9(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1162 <loadbar+0x42>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %edi,%ebx
movsd  %xmm0,0x2ecc(%rip)
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%r14d
mulsd  0xe84(%rip),%xmm0
lea    0xe85(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11af <loadbar+0x8f>
mov    %r14d,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x3d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11a0 <loadbar+0x80>
cmp    %ebx,%r14d
jge    11cf <loadbar+0xaf>
sub    %r14d,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11c0 <loadbar+0xa0>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@loadbar.repeat = internal global double 0.000000e+00
@.str = [10 x i8] c"%3.1f%% [\00"
@.str.1 = [9 x i8] c"]\0A\1B[F\1B[J\00"
define void @loadbar(i32 %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 %0, i32* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %4
store double 0.000000e+00, double* @loadbar.repeat
br label %58
15: ; preds = %4
%16 = load i64, i64* %6
%17 = sitofp i64 %16 to double
%18 = load i64, i64* %7
%19 = sitofp i64 %18 to double
%20 = fdiv double %17, %19
store double %20, double* %11
%21 = load double, double* %11
%22 = load double, double* @loadbar.repeat
%23 = fsub double %21, %22
%24 = fcmp olt double %23, 1.000000e-03
br i1 %24, label %25, label %26
25: ; preds = %15
br label %58
26: ; preds = %15
%27 = load double, double* %11
store double %27, double* @loadbar.repeat
%28 = load double, double* %11
%29 = load i32, i32* %5
%30 = sitofp i32 %29 to double
%31 = fmul double %28, %30
%32 = fptosi double %31 to i32
store i32 %32, i32* %10
%33 = load double, double* %11
%34 = fmul double %33, 1.000000e+02
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %34)
store i32 0, i32* %9
br label %36
36: ; preds = %42, %26
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = call i32 @putchar(i8 signext 61)
br label %42
42: ; preds = %40
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %36
45: ; preds = %36
%46 = load i32, i32* %10
store i32 %46, i32* %9
br label %47
47: ; preds = %53, %45
%48 = load i32, i32* %9
%49 = load i32, i32* %5
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = call i32 @putchar(i8 signext 32)
br label %53
53: ; preds = %51
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %47
56: ; preds = %47
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %25, %14
ret void
}

LLVM IR (-O2):
@loadbar.repeat = internal unnamed_addr global double 0.000000e+00
@.str = [10 x i8] c"%3.1f%% [\00"
@.str.1 = [9 x i8] c"]\0A\1B[F\1B[J\00"
define void @loadbar(i32 %0, i64 %1, i64 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %7, label %6
6: ; preds = %4
store double 0.000000e+00, double* @loadbar.repeat
br label %35
7: ; preds = %4
%8 = sitofp i64 %1 to double
%9 = sitofp i64 %2 to double
%10 = fdiv double %8, %9
%11 = load double, double* @loadbar.repeat
%12 = fsub double %10, %11
%13 = fcmp olt double %12, 1.000000e-03
br i1 %13, label %35, label %14
14: ; preds = %7
store double %10, double* @loadbar.repeat
%15 = sitofp i32 %0 to double
%16 = fmul double %10, %15
%17 = fptosi double %16 to i32
%18 = fmul double %10, 1.000000e+02
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %18)
%20 = icmp sgt i32 %17, 0
br i1 %20, label %23, label %21
21: ; preds = %23, %14
%22 = icmp slt i32 %17, %0
br i1 %22, label %28, label %33
23: ; preds = %14, %23
%24 = phi i32 [ %26, %23 ], [ 0, %14 ]
%25 = tail call i32 @putchar(i8 signext 61)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, %17
br i1 %27, label %21, label %23
28: ; preds = %21, %28
%29 = phi i32 [ %31, %28 ], [ %17, %21 ]
%30 = tail call i32 @putchar(i8 signext 32)
%31 = add i32 %29, 1
%32 = icmp eq i32 %31, %0
br i1 %32, label %33, label %28
33: ; preds = %28, %21
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %7, %33, %6
ret void
}