#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 */
typedef int n_val;
typedef scalar_t__ k_val;

/* Variables and functions */
int /*<<< orphan*/ fc8080_write(void *, int, int);
int fc8080_set_freq(void *handle, unsigned int band, unsigned int freq) {
  unsigned int f_diff, f_diff_shifted, n_val, k_val;
  unsigned int f_vco, f_comp;
  unsigned char div_ratio, lo_mode, r_val, data_0x55;
  unsigned char pre_shift_bits = 4;
  div_ratio = 16;
  lo_mode = 0;
  f_vco = freq * div_ratio;
  if (2800000 < f_vco) {
    div_ratio = 12;
    lo_mode = 1;
    f_vco = freq * div_ratio;
  }
  if (f_vco < 19200 * 35)
    r_val = 2;
  else
    r_val = 1;
  f_comp = 19200 / r_val;
  n_val = f_vco / f_comp;
  f_diff = f_vco - f_comp * n_val;
  f_diff_shifted = f_diff << (20 - pre_shift_bits);
  k_val = f_diff_shifted / (f_comp >> pre_shift_bits);
  k_val = k_val | 1;
  data_0x55 = ((r_val == 1) ? 0x00 : 0x10) + (unsigned char)(k_val >> 16);
  fc8080_write(handle, 0x51, 7 + 8 * lo_mode);
  fc8080_write(handle, 0x55, data_0x55);
  fc8080_write(handle, 0x56, (unsigned char)((k_val >> 8) & 0xff));
  fc8080_write(handle, 0x57, (unsigned char)(((k_val)&0xff)));
  fc8080_write(handle, 0x58, (n_val)&0xff);
  if (freq < 207000)
    fc8080_write(handle, 0x6a, 0x0b);
  else
    fc8080_write(handle, 0x6a, 0x03);
  fc8080_write(handle, 0x04, 0x04);
  fc8080_write(handle, 0x50, 0xf3);
  fc8080_write(handle, 0x50, 0xff);
  fc8080_write(handle, 0x04, 0x00);
  return 0;
}


x86 assembly (clang, -O0):
<fc8080_set_freq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movb   $0x4,-0x2d(%rbp)
movb   $0x10,-0x29(%rbp)
movb   $0x0,-0x2a(%rbp)
mov    -0x10(%rbp),%eax
movzbl -0x29(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    $0x2ab980,%eax
cmp    -0x24(%rbp),%eax
jae    115e <fc8080_set_freq+0x4e>
movb   $0xc,-0x29(%rbp)
movb   $0x1,-0x2a(%rbp)
mov    -0x10(%rbp),%eax
movzbl -0x29(%rbp),%ecx
imul   %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xa4100,-0x24(%rbp)
jae    1174 <fc8080_set_freq+0x64>
movb   $0x2,-0x2b(%rbp)
jmp    1178 <fc8080_set_freq+0x68>
movb   $0x1,-0x2b(%rbp)
movzbl -0x2b(%rbp),%ecx
mov    $0x4b00,%eax
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
xor    %edx,%edx
divl   -0x28(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x28(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x2d(%rbp),%edx
mov    $0x14,%ecx
sub    %edx,%ecx
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x28(%rbp),%edx
movzbl -0x2d(%rbp),%ecx
shr    %cl,%edx
mov    %edx,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x20(%rbp)
movzbl -0x2b(%rbp),%edx
mov    $0x10,%eax
xor    %ecx,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    -0x20(%rbp),%ecx
shr    $0x10,%ecx
movzbl %cl,%ecx
add    %ecx,%eax
mov    %al,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
movzbl -0x2a(%rbp),%edx
shl    $0x3,%edx
add    $0x7,%edx
mov    $0x51,%esi
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
movzbl -0x2c(%rbp),%edx
mov    $0x55,%esi
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
movzbl %al,%edx
mov    $0x56,%esi
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
and    $0xff,%eax
movzbl %al,%edx
mov    $0x57,%esi
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
and    $0xff,%edx
mov    $0x58,%esi
call   1030 <fc8080_write@plt>
cmpl   $0x32898,-0x10(%rbp)
jae    128c <fc8080_set_freq+0x17c>
mov    -0x8(%rbp),%rdi
mov    $0x6a,%esi
mov    $0xb,%edx
call   1030 <fc8080_write@plt>
jmp    129f <fc8080_set_freq+0x18f>
mov    -0x8(%rbp),%rdi
mov    $0x6a,%esi
mov    $0x3,%edx
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%edx
mov    %edx,%esi
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x50,%esi
mov    $0xf3,%edx
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x50,%esi
mov    $0xff,%edx
call   1030 <fc8080_write@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1030 <fc8080_write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8080_set_freq>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbp
mov    %edx,%ecx
shl    $0x4,%ecx
lea    0x0(,%r14,4),%eax
xor    %esi,%esi
cmp    $0x2ab981,%ecx
setae  %sil
lea    (%rax,%rax,2),%eax
cmovb  %ecx,%eax
xor    %edi,%edi
cmp    $0xa4100,%eax
setb   %dil
mov    $0x2580,%ecx
mov    $0x4b00,%ebx
cmovb  %ecx,%ebx
xor    %edx,%edx
div    %ebx
mov    %eax,%r15d
mov    %edx,%eax
lea    0x7(,%rsi,8),%ecx
shl    $0x4,%edi
shl    $0x10,%eax
shr    $0x4,%ebx
xor    %edx,%edx
div    %ebx
mov    %eax,%ebx
mov    %eax,%r12d
shr    $0x10,%ebx
add    %edi,%ebx
mov    %rbp,%rdi
mov    $0x51,%esi
mov    %ecx,%edx
call   1030 <fc8080_write@plt>
mov    %rbp,%rdi
mov    $0x55,%esi
mov    %ebx,%edx
call   1030 <fc8080_write@plt>
mov    %r12d,%ebx
movzbl %bh,%edx
mov    %rbp,%rdi
mov    $0x56,%esi
call   1030 <fc8080_write@plt>
mov    %r12d,%eax
or     $0x1,%eax
movzbl %al,%edx
mov    %rbp,%rdi
mov    $0x57,%esi
call   1030 <fc8080_write@plt>
movzbl %r15b,%edx
mov    %rbp,%rdi
mov    $0x58,%esi
call   1030 <fc8080_write@plt>
xor    %eax,%eax
cmp    $0x32898,%r14d
setb   %al
lea    0x3(,%rax,8),%edx
mov    %rbp,%rdi
mov    $0x6a,%esi
call   1030 <fc8080_write@plt>
mov    %rbp,%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1030 <fc8080_write@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    $0xf3,%edx
call   1030 <fc8080_write@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    $0xff,%edx
call   1030 <fc8080_write@plt>
mov    %rbp,%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1030 <fc8080_write@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fc8080_set_freq(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8 4, i8* %17
store i8 16, i8* %13
store i8 0, i8* %14
%18 = load i32, i32* %6
%19 = load i8, i8* %13
%20 = zext i8 %19 to i32
%21 = mul i32 %18, %20
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = icmp ult i32 2800000, %22
br i1 %23, label %24, label %29
24: ; preds = %3
store i8 12, i8* %13
store i8 1, i8* %14
%25 = load i32, i32* %6
%26 = load i8, i8* %13
%27 = zext i8 %26 to i32
%28 = mul i32 %25, %27
store i32 %28, i32* %11
br label %29
29: ; preds = %24, %3
%30 = load i32, i32* %11
%31 = icmp ult i32 %30, 672000
br i1 %31, label %32, label %33
32: ; preds = %29
store i8 2, i8* %15
br label %34
33: ; preds = %29
store i8 1, i8* %15
br label %34
34: ; preds = %33, %32
%35 = load i8, i8* %15
%36 = zext i8 %35 to i32
%37 = sdiv i32 19200, %36
store i32 %37, i32* %12
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = udiv i32 %38, %39
store i32 %40, i32* %9
%41 = load i32, i32* %11
%42 = load i32, i32* %12
%43 = load i32, i32* %9
%44 = mul i32 %42, %43
%45 = sub i32 %41, %44
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = load i8, i8* %17
%48 = zext i8 %47 to i32
%49 = sub nsw i32 20, %48
%50 = shl i32 %46, %49
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = load i32, i32* %12
%53 = load i8, i8* %17
%54 = zext i8 %53 to i32
%55 = lshr i32 %52, %54
%56 = udiv i32 %51, %55
store i32 %56, i32* %10
%57 = load i32, i32* %10
%58 = or i32 %57, 1
store i32 %58, i32* %10
%59 = load i8, i8* %15
%60 = zext i8 %59 to i32
%61 = icmp eq i32 %60, 1
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 0, i32 16
%64 = load i32, i32* %10
%65 = lshr i32 %64, 16
%66 = trunc i32 %65 to i8
%67 = zext i8 %66 to i32
%68 = add nsw i32 %63, %67
%69 = trunc i32 %68 to i8
store i8 %69, i8* %16
%70 = load i8*, i8** %4
%71 = load i8, i8* %14
%72 = zext i8 %71 to i32
%73 = mul nsw i32 8, %72
%74 = add nsw i32 7, %73
%75 = call i32 @fc8080_write(i8* %70, i32 81, i32 %74)
%76 = load i8*, i8** %4
%77 = load i8, i8* %16
%78 = zext i8 %77 to i32
%79 = call i32 @fc8080_write(i8* %76, i32 85, i32 %78)
%80 = load i8*, i8** %4
%81 = load i32, i32* %10
%82 = lshr i32 %81, 8
%83 = and i32 %82, 255
%84 = trunc i32 %83 to i8
%85 = zext i8 %84 to i32
%86 = call i32 @fc8080_write(i8* %80, i32 86, i32 %85)
%87 = load i8*, i8** %4
%88 = load i32, i32* %10
%89 = and i32 %88, 255
%90 = trunc i32 %89 to i8
%91 = zext i8 %90 to i32
%92 = call i32 @fc8080_write(i8* %87, i32 87, i32 %91)
%93 = load i8*, i8** %4
%94 = load i32, i32* %9
%95 = and i32 %94, 255
%96 = call i32 @fc8080_write(i8* %93, i32 88, i32 %95)
%97 = load i32, i32* %6
%98 = icmp ult i32 %97, 207000
br i1 %98, label %99, label %102
99: ; preds = %34
%100 = load i8*, i8** %4
%101 = call i32 @fc8080_write(i8* %100, i32 106, i32 11)
br label %105
102: ; preds = %34
%103 = load i8*, i8** %4
%104 = call i32 @fc8080_write(i8* %103, i32 106, i32 3)
br label %105
105: ; preds = %102, %99
%106 = load i8*, i8** %4
%107 = call i32 @fc8080_write(i8* %106, i32 4, i32 4)
%108 = load i8*, i8** %4
%109 = call i32 @fc8080_write(i8* %108, i32 80, i32 243)
%110 = load i8*, i8** %4
%111 = call i32 @fc8080_write(i8* %110, i32 80, i32 255)
%112 = load i8*, i8** %4
%113 = call i32 @fc8080_write(i8* %112, i32 4, i32 0)
ret i32 0
}

LLVM IR (-O2):
define i32 @fc8080_set_freq(i8* %0, i32 %1, i32 %2) {
%4 = shl i32 %2, 4
%5 = icmp ugt i32 %4, 2800000
%6 = mul i32 %2, 12
%7 = select i1 %5, i32 15, i32 7
%8 = select i1 %5, i32 %6, i32 %4
%9 = icmp ult i32 %8, 672000
%10 = select i1 %9, i32 16, i32 0
%11 = select i1 %9, i32 9600, i32 19200
%12 = udiv i32 %8, %11
%13 = mul i32 %12, %11
%14 = urem i32 %8, %11
%15 = shl i32 %14, 16
%16 = lshr exact i32 %11, 4
%17 = udiv i32 %15, %16
%18 = lshr i32 %17, 16
%19 = add nuw nsw i32 %18, %10
%20 = tail call i32 @fc8080_write(i8* %0, i32 81, i32 %7)
%21 = tail call i32 @fc8080_write(i8* %0, i32 85, i32 %19)
%22 = lshr i32 %17, 8
%23 = and i32 %22, 255
%24 = tail call i32 @fc8080_write(i8* %0, i32 86, i32 %23)
%25 = and i32 %17, 254
%26 = or i32 %25, 1
%27 = tail call i32 @fc8080_write(i8* %0, i32 87, i32 %26)
%28 = and i32 %12, 255
%29 = tail call i32 @fc8080_write(i8* %0, i32 88, i32 %28)
%30 = icmp ult i32 %2, 207000
%31 = select i1 %30, i32 11, i32 3
%32 = tail call i32 @fc8080_write(i8* %0, i32 106, i32 %31)
%33 = tail call i32 @fc8080_write(i8* %0, i32 4, i32 4)
%34 = tail call i32 @fc8080_write(i8* %0, i32 80, i32 243)
%35 = tail call i32 @fc8080_write(i8* %0, i32 80, i32 255)
%36 = tail call i32 @fc8080_write(i8* %0, i32 4, i32 0)
ret i32 0
}