#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*/ sio_write_reg(int, unsigned int);
void vgatv_sharpness(int sharpness) {
  unsigned int shp;
  shp = ((2 * sharpness * 20 / 1000) + 1) / 2;
  shp = ((((0)) > ((((shp)) < ((20)) ? ((shp)) : ((20))))
              ? ((0))
              : ((((shp)) < ((20)) ? ((shp)) : ((20))))));
  sio_write_reg(0x20, shp);
}


x86 assembly (clang, -O0):
<vgatv_sharpness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
imul   $0x14,%eax,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jae    114f <vgatv_sharpness+0x3f>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    115c <vgatv_sharpness+0x4c>
mov    $0x14,%eax
mov    %eax,-0xc(%rbp)
jmp    115c <vgatv_sharpness+0x4c>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jbe    1173 <vgatv_sharpness+0x63>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <vgatv_sharpness+0x8b>
cmpl   $0x14,-0x8(%rbp)
jae    1188 <vgatv_sharpness+0x78>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <vgatv_sharpness+0x85>
mov    $0x14,%eax
mov    %eax,-0x14(%rbp)
jmp    1195 <vgatv_sharpness+0x85>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
mov    $0x20,%edi
call   1030 <sio_write_reg@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vgatv_sharpness>:
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
lea    (%rax,%rcx,1),%edx
add    %ecx,%eax
add    $0x1,%eax
shr    $0x1f,%eax
add    %edx,%eax
add    $0x1,%eax
sar    %eax
cmp    $0x14,%eax
mov    $0x14,%esi
cmovb  %eax,%esi
mov    $0x20,%edi
jmp    1030 <sio_write_reg@plt>

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

LLVM IR (-O2):
define void @vgatv_sharpness(i32 %0) {
%2 = sdiv i32 %0, 25
%3 = add nsw i32 %2, 1
%4 = sdiv i32 %3, 2
%5 = icmp ult i32 %4, 20
%6 = select i1 %5, i32 %4, i32 20
%7 = tail call i32 @sio_write_reg(i32 32, i32 %6)
ret void
}