#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*/ enc_write_reg(int, unsigned long);
void vgatv_color(int color) {
  unsigned long clr;
  clr = ((2 * color * 255 / 100) + 1) / 2;
  clr = ((((0)) > ((((clr)) < ((255)) ? ((clr)) : ((255))))
              ? ((0))
              : ((((clr)) < ((255)) ? ((clr)) : ((255))))));
  enc_write_reg(0xA2, clr);
  enc_write_reg(0xA0, clr);
}


x86 assembly (clang, -O0):
<vgatv_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
imul   $0xff,%eax,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0xff,-0x10(%rbp)
jae    115b <vgatv_color+0x4b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1169 <vgatv_color+0x59>
mov    $0xff,%eax
mov    %rax,-0x18(%rbp)
jmp    1169 <vgatv_color+0x59>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jbe    1183 <vgatv_color+0x73>
xor    %eax,%eax
mov    %rax,-0x20(%rbp)
jmp    11b4 <vgatv_color+0xa4>
cmpq   $0xff,-0x10(%rbp)
jae    119e <vgatv_color+0x8e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11ac <vgatv_color+0x9c>
mov    $0xff,%eax
mov    %rax,-0x28(%rbp)
jmp    11ac <vgatv_color+0x9c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0xa2,%edi
call   1030 <enc_write_reg@plt>
mov    -0x10(%rbp),%rsi
mov    $0xa0,%edi
call   1030 <enc_write_reg@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vgatv_color>:
push   %rbx
mov    %edi,%eax
shl    $0x9,%eax
sub    %edi,%eax
sub    %edi,%eax
cltq
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
lea    (%rax,%rcx,1),%edx
add    %ecx,%eax
add    $0x1,%eax
shr    $0x1f,%eax
add    %edx,%eax
add    $0x1,%eax
sar    %eax
cltq
cmp    $0xff,%rax
mov    $0xff,%ebx
cmovb  %rax,%rbx
mov    $0xa2,%edi
mov    %rbx,%rsi
call   1030 <enc_write_reg@plt>
mov    $0xa0,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1030 <enc_write_reg@plt>

LLVM IR (-O0):
define void @vgatv_color(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = mul nsw i32 2, %4
%6 = mul nsw i32 %5, 255
%7 = sdiv i32 %6, 100
%8 = add nsw i32 %7, 1
%9 = sdiv i32 %8, 2
%10 = sext i32 %9 to i64
store i64 %10, i64* %3
%11 = load i64, i64* %3
%12 = icmp ult i64 %11, 255
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load i64, i64* %3
br label %16
15: ; preds = %1
br label %16
16: ; preds = %15, %13
%17 = phi i64 [ %14, %13 ], [ 255, %15 ]
%18 = icmp ugt i64 0, %17
br i1 %18, label %19, label %20
19: ; preds = %16
br label %28
20: ; preds = %16
%21 = load i64, i64* %3
%22 = icmp ult i64 %21, 255
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i64, i64* %3
br label %26
25: ; preds = %20
br label %26
26: ; preds = %25, %23
%27 = phi i64 [ %24, %23 ], [ 255, %25 ]
br label %28
28: ; preds = %26, %19
%29 = phi i64 [ 0, %19 ], [ %27, %26 ]
store i64 %29, i64* %3
%30 = load i64, i64* %3
%31 = call i32 @enc_write_reg(i32 162, i64 %30)
%32 = load i64, i64* %3
%33 = call i32 @enc_write_reg(i32 160, i64 %32)
ret void
}

LLVM IR (-O2):
define void @vgatv_color(i32 %0) {
%2 = mul nsw i32 %0, 510
%3 = sdiv i32 %2, 100
%4 = add nsw i32 %3, 1
%5 = sdiv i32 %4, 2
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, 255
%8 = select i1 %7, i64 %6, i64 255
%9 = tail call i32 @enc_write_reg(i32 162, i64 %8)
%10 = tail call i32 @enc_write_reg(i32 160, i64 %8)
ret void
}