#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_flicker(int flicker) {
  unsigned int flk;
  flk = ((2 * flicker * 16 / 1000) + 1) / 2;
  flk = ((((0)) > ((((flk)) < ((16)) ? ((flk)) : ((16))))
              ? ((0))
              : ((((flk)) < ((16)) ? ((flk)) : ((16))))));
  sio_write_reg(0x22, flk);
}


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

x86 assembly (clang, -O2):
<vgatv_flicker>:
shl    $0x5,%edi
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
lea    (%rax,%rcx,1),%edx
add    %ecx,%eax
add    $0x1,%eax
shr    $0x1f,%eax
add    %edx,%eax
add    $0x1,%eax
sar    %eax
cmp    $0x10,%eax
mov    $0x10,%esi
cmovb  %eax,%esi
mov    $0x22,%edi
jmp    1030 <sio_write_reg@plt>

LLVM IR (-O0):
define void @vgatv_flicker(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, 16
%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, 16
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 ], [ 16, %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, 16
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 ], [ 16, %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 34, i32 %29)
ret void
}

LLVM IR (-O2):
define void @vgatv_flicker(i32 %0) {
%2 = shl nsw i32 %0, 5
%3 = sdiv i32 %2, 1000
%4 = add nsw i32 %3, 1
%5 = sdiv i32 %4, 2
%6 = icmp ult i32 %5, 16
%7 = select i1 %6, i32 %5, i32 16
%8 = tail call i32 @sio_write_reg(i32 34, i32 %7)
ret void
}