#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*/ bbm_word_read(void *, unsigned short, int, unsigned short *);
unsigned int fc8300_get_current_clk(void *handle, unsigned short devid) {
  unsigned int pre_sel, post_sel, multi;
  unsigned short pll_set = 0;
  bbm_word_read(handle, devid, 0x0055, &pll_set);
  multi = ((pll_set & 0xff00) >> 8) + 2;
  pre_sel = pll_set & 0x000f;
  post_sel = (pll_set & 0x00f0) >> 4;
  return ((19200 >> pre_sel) * multi) >> post_sel;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movw   $0x0,-0x1a(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x55,%edx
lea    -0x1a(%rbp),%rcx
movzwl -0xa(%rbp),%esi
call   1030 <bbm_word_read@plt>
movzwl -0x1a(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
movzwl -0x1a(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x10(%rbp)
movzwl -0x1a(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
mov    $0x4b00,%eax
sar    %cl,%eax
imul   -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
shr    %cl,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rax
movw   $0x0,0x6(%rsp)
lea    0x6(%rsp),%rcx
mov    $0x55,%edx
call   1030 <bbm_word_read@plt>
movzwl 0x6(%rsp),%edx
mov    %edx,%esi
shr    $0x8,%esi
add    $0x2,%esi
mov    %edx,%ecx
and    $0xf,%cl
mov    $0x4b00,%eax
shr    %cl,%eax
imul   %esi,%eax
shr    $0x4,%dl
mov    %edx,%ecx
shr    %cl,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @fc8300_get_current_clk(i8* %0, i16 zeroext %1) {
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16
store i8* %0, i8** %3
store i16 %1, i16* %4
store i16 0, i16* %8
%9 = load i8*, i8** %3
%10 = load i16, i16* %4
%11 = call i32 @bbm_word_read(i8* %9, i16 zeroext %10, i32 85, i16* %8)
%12 = load i16, i16* %8
%13 = zext i16 %12 to i32
%14 = and i32 %13, 65280
%15 = ashr i32 %14, 8
%16 = add nsw i32 %15, 2
store i32 %16, i32* %7
%17 = load i16, i16* %8
%18 = zext i16 %17 to i32
%19 = and i32 %18, 15
store i32 %19, i32* %5
%20 = load i16, i16* %8
%21 = zext i16 %20 to i32
%22 = and i32 %21, 240
%23 = ashr i32 %22, 4
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = ashr i32 19200, %24
%26 = load i32, i32* %7
%27 = mul i32 %25, %26
%28 = load i32, i32* %6
%29 = lshr i32 %27, %28
ret i32 %29
}

LLVM IR (-O2):
define i32 @fc8300_get_current_clk(i8* %0, i16 zeroext %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%5 = call i32 @bbm_word_read(i8* %0, i16 zeroext %1, i32 85, i16* %3)
%6 = load i16, i16* %3
%7 = zext i16 %6 to i32
%8 = lshr i32 %7, 8
%9 = add nuw nsw i32 %8, 2
%10 = and i32 %7, 15
%11 = lshr i32 %7, 4
%12 = and i32 %11, 15
%13 = lshr i32 19200, %10
%14 = mul nuw nsw i32 %13, %9
%15 = lshr i32 %14, %12
ret i32 %15
}