#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 get_color_by_level(int, int);
int /*<<< orphan*/ goto_xy(int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reset_color();
int /*<<< orphan*/ set_color(int);
int /*<<< orphan*/ stdout;
int trunc(double);
void display_bar(int col, double rms, int lim, int reso) {
  int i, j, color;
  j = trunc(rms / reso + 1);
  if (j > lim)
    j = lim;
  for (i = 0; i < j; i++) {
    color = get_color_by_level(i, lim);
    set_color(color);
    goto_xy(col, lim - i + 2);
    printf("%s", "\u2590");
  }
  reset_color();
  fflush(stdout);
}


x86 assembly (clang, -O0):
<display_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe64(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1080 <trunc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    11ba <display_bar+0x4a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1215 <display_bar+0xa5>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <get_color_by_level@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <set_color@plt>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
sub    -0x1c(%rbp),%esi
add    $0x2,%esi
call   1090 <goto_xy@plt>
lea    0xe0d(%rip),%rdi
lea    0xe09(%rip),%rsi
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c1 <display_bar+0x51>
mov    $0x0,%al
call   1070 <reset_color@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_bar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cvtsi2sd %edx,%xmm1
mov    %esi,%r15d
mov    %edi,%r14d
divsd  %xmm1,%xmm0
addsd  0xe6f(%rip),%xmm0
call   1080 <trunc@plt>
mov    %eax,%r12d
cmp    %r15d,%eax
cmovg  %r15d,%r12d
test   %r12d,%r12d
jle    11f5 <display_bar+0x85>
lea    0x2(%r15),%ebx
xor    %ebp,%ebp
lea    0xe59(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r15d,%esi
call   1030 <get_color_by_level@plt>
mov    %eax,%edi
call   1050 <set_color@plt>
mov    %r14d,%edi
mov    %ebx,%esi
call   1090 <goto_xy@plt>
lea    0xe26(%rip),%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
add    $0x1,%ebp
add    $0xffffffff,%ebx
cmp    %ebp,%r12d
jne    11c0 <display_bar+0x50>
xor    %eax,%eax
call   1070 <reset_color@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fflush@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"\E2\96\90\00"
@stdout = global i32 0
define void @display_bar(i32 %0, double %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load double, double* %6
%13 = load i32, i32* %8
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
%16 = fadd double %15, 1.000000e+00
%17 = call i32 @trunc(double %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = load i32, i32* %7
store i32 %22, i32* %10
br label %23
23: ; preds = %21, %4
store i32 0, i32* %9
br label %24
24: ; preds = %41, %23
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i32, i32* %9
%30 = load i32, i32* %7
%31 = call i32 @get_color_by_level(i32 %29, i32 %30)
store i32 %31, i32* %11
%32 = load i32, i32* %11
%33 = call i32 @set_color(i32 %32)
%34 = load i32, i32* %5
%35 = load i32, i32* %7
%36 = load i32, i32* %9
%37 = sub nsw i32 %35, %36
%38 = add nsw i32 %37, 2
%39 = call i32 @goto_xy(i32 %34, i32 %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %28
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %24
44: ; preds = %24
%45 = call i32 (...) @reset_color()
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"\E2\96\90\00"
@stdout = global i32 0
define void @display_bar(i32 %0, double %1, i32 %2, i32 %3) {
%5 = sitofp i32 %3 to double
%6 = fdiv double %1, %5
%7 = fadd double %6, 1.000000e+00
%8 = tail call i32 @trunc(double %7)
%9 = icmp sgt i32 %8, %2
%10 = select i1 %9, i32 %2, i32 %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %4
%13 = add i32 %2, 2
br label %14
14: ; preds = %12, %14
%15 = phi i32 [ 0, %12 ], [ %21, %14 ]
%16 = tail call i32 @get_color_by_level(i32 %15, i32 %2)
%17 = tail call i32 @set_color(i32 %16)
%18 = sub i32 %13, %15
%19 = tail call i32 @goto_xy(i32 %0, i32 %18)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%21 = add nuw nsw i32 %15, 1
%22 = icmp eq i32 %21, %10
br i1 %22, label %23, label %14
23: ; preds = %14, %4
%24 = tail call i32 (...) @reset_color()
%25 = load i32, i32* @stdout
%26 = tail call i32 @fflush(i32 %25)
ret void
}