#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*/ outb(int, unsigned short);
void init_time_chip(unsigned int freq) {
  unsigned short reload;
  if (freq <= 18) {
    reload = 0xFFFF;
  } else if (freq >= 596591) {
    reload = 0x0002;
  } else {
    reload = (unsigned short)((1193182 / freq) & 0xFFFF);
  }
  outb(0x43, 0x34);
  outb(0x40, reload & 0xFF);
  outb(0x40, reload >> 8);
}


x86 assembly (clang, -O0):
<init_time_chip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x12,-0x4(%rbp)
ja     1130 <init_time_chip+0x20>
movw   $0xffff,-0x6(%rbp)
jmp    1160 <init_time_chip+0x50>
cmpl   $0x91a6f,-0x4(%rbp)
jb     1148 <init_time_chip+0x38>
movw   $0x2,-0x6(%rbp)
jmp    115b <init_time_chip+0x4b>
mov    $0x1234de,%eax
xor    %edx,%edx
divl   -0x4(%rbp)
and    $0xffff,%eax
mov    %ax,-0x6(%rbp)
jmp    1160 <init_time_chip+0x50>
mov    $0x43,%edi
mov    $0x34,%esi
call   1030 <outb@plt>
movzwl -0x6(%rbp),%eax
and    $0xff,%eax
mov    $0x40,%edi
movzwl %ax,%esi
call   1030 <outb@plt>
movzwl -0x6(%rbp),%eax
sar    $0x8,%eax
mov    $0x40,%edi
movzwl %ax,%esi
call   1030 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_time_chip>:
push   %rbx
mov    $0xffff,%ebx
cmp    $0x13,%edi
jb     1133 <init_time_chip+0x23>
mov    $0x2,%ebx
cmp    $0x91a6e,%edi
ja     1133 <init_time_chip+0x23>
mov    $0x1234de,%eax
xor    %edx,%edx
div    %edi
mov    %eax,%ebx
mov    $0x43,%edi
mov    $0x34,%esi
call   1030 <outb@plt>
movzbl %bl,%esi
mov    $0x40,%edi
call   1030 <outb@plt>
shr    $0x8,%ebx
movzwl %bx,%esi
mov    $0x40,%edi
pop    %rbx
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @init_time_chip(i32 %0) {
%2 = alloca i32
%3 = alloca i16
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ule i32 %4, 18
br i1 %5, label %6, label %7
6: ; preds = %1
store i16 -1, i16* %3
br label %17
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp uge i32 %8, 596591
br i1 %9, label %10, label %11
10: ; preds = %7
store i16 2, i16* %3
br label %16
11: ; preds = %7
%12 = load i32, i32* %2
%13 = udiv i32 1193182, %12
%14 = and i32 %13, 65535
%15 = trunc i32 %14 to i16
store i16 %15, i16* %3
br label %16
16: ; preds = %11, %10
br label %17
17: ; preds = %16, %6
%18 = call i32 @outb(i32 67, i16 zeroext 52)
%19 = load i16, i16* %3
%20 = zext i16 %19 to i32
%21 = and i32 %20, 255
%22 = trunc i32 %21 to i16
%23 = call i32 @outb(i32 64, i16 zeroext %22)
%24 = load i16, i16* %3
%25 = zext i16 %24 to i32
%26 = ashr i32 %25, 8
%27 = trunc i32 %26 to i16
%28 = call i32 @outb(i32 64, i16 zeroext %27)
ret void
}

LLVM IR (-O2):
define void @init_time_chip(i32 %0) {
%2 = icmp ult i32 %0, 19
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = icmp ugt i32 %0, 596590
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = udiv i32 1193182, %0
br label %7
7: ; preds = %3, %1, %5
%8 = phi i32 [ %6, %5 ], [ 65535, %1 ], [ 2, %3 ]
%9 = tail call i32 @outb(i32 67, i16 zeroext 52)
%10 = trunc i32 %8 to i16
%11 = and i16 %10, 255
%12 = tail call i32 @outb(i32 64, i16 zeroext %11)
%13 = lshr i32 %8, 8
%14 = trunc i32 %13 to i16
%15 = tail call i32 @outb(i32 64, i16 zeroext %14)
ret void
}