#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*/ COLOR_PAIR(int);
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int /*<<< orphan*/ draw_rect(int, int, int, int);
void draw_scrollbar(int x, int y, unsigned content_h, unsigned content_offset,
                    unsigned displayed_h) {
  float bar_ratio_height = displayed_h / (float)content_h;
  float bar_ratio_top = ((int)content_offset - displayed_h) / (float)content_h;
  int bar_height = (int)(displayed_h * bar_ratio_height) + 1;
  int bar_top = displayed_h * bar_ratio_top;
  attron(COLOR_PAIR((3 + 1)));
  draw_rect(x, y + bar_top, 1, bar_height);
  attroff(COLOR_PAIR((3 + 1)));
}


x86 assembly (clang, -O0):
<draw_scrollbar>:
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    %r8d,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2ss %rax,%xmm0
mov    -0xc(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    %ecx,%eax
cvtsi2ss %rax,%xmm0
mov    -0xc(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2ss %rax,%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2ss %rax,%xmm0
mulss  -0x1c(%rbp),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x24(%rbp)
mov    $0x4,%edi
call   1060 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1040 <attron@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x24(%rbp),%esi
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
call   1050 <draw_rect@plt>
mov    $0x4,%edi
call   1060 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw_scrollbar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r14d
mov    %r8d,%eax
cvtsi2ss %rax,%xmm0
mov    %edx,%eax
cvtsi2ss %rax,%xmm1
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
sub    %r8d,%ecx
cvtsi2ss %rcx,%xmm3
divss  %xmm1,%xmm3
mulss  %xmm0,%xmm2
cvttss2si %xmm2,%ebp
add    $0x1,%ebp
mulss  %xmm0,%xmm3
cvttss2si %xmm3,%r15d
mov    $0x4,%edi
call   1060 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1040 <attron@plt>
add    %r15d,%ebx
mov    %r14d,%edi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
call   1050 <draw_rect@plt>
mov    $0x4,%edi
call   1060 <COLOR_PAIR@plt>
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <attroff@plt>

LLVM IR (-O0):
define void @draw_scrollbar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca float
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%15 = load i32, i32* %10
%16 = uitofp i32 %15 to float
%17 = load i32, i32* %8
%18 = uitofp i32 %17 to float
%19 = fdiv float %16, %18
store float %19, float* %11
%20 = load i32, i32* %9
%21 = load i32, i32* %10
%22 = sub i32 %20, %21
%23 = uitofp i32 %22 to float
%24 = load i32, i32* %8
%25 = uitofp i32 %24 to float
%26 = fdiv float %23, %25
store float %26, float* %12
%27 = load i32, i32* %10
%28 = uitofp i32 %27 to float
%29 = load float, float* %11
%30 = fmul float %28, %29
%31 = fptosi float %30 to i32
%32 = add nsw i32 %31, 1
store i32 %32, i32* %13
%33 = load i32, i32* %10
%34 = uitofp i32 %33 to float
%35 = load float, float* %12
%36 = fmul float %34, %35
%37 = fptosi float %36 to i32
store i32 %37, i32* %14
%38 = call i32 @COLOR_PAIR(i32 4)
%39 = call i32 @attron(i32 %38)
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = load i32, i32* %14
%43 = add nsw i32 %41, %42
%44 = load i32, i32* %13
%45 = call i32 @draw_rect(i32 %40, i32 %43, i32 1, i32 %44)
%46 = call i32 @COLOR_PAIR(i32 4)
%47 = call i32 @attroff(i32 %46)
ret void
}

LLVM IR (-O2):
define void @draw_scrollbar(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = uitofp i32 %4 to float
%7 = uitofp i32 %2 to float
%8 = fdiv float %6, %7
%9 = sub i32 %3, %4
%10 = uitofp i32 %9 to float
%11 = fdiv float %10, %7
%12 = fmul float %8, %6
%13 = fptosi float %12 to i32
%14 = add nsw i32 %13, 1
%15 = fmul float %11, %6
%16 = fptosi float %15 to i32
%17 = tail call i32 @COLOR_PAIR(i32 4)
%18 = tail call i32 @attron(i32 %17)
%19 = add nsw i32 %16, %1
%20 = tail call i32 @draw_rect(i32 %0, i32 %19, i32 1, i32 %14)
%21 = tail call i32 @COLOR_PAIR(i32 4)
%22 = tail call i32 @attroff(i32 %21)
ret void
}