#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 */
unsigned long clk_get_pll_rate();
unsigned int reg_read_32(unsigned int volatile *);
unsigned long clk_get_cpu_rate(void) {
  unsigned long pll_rate, cpu_rate;
  unsigned int ctrl;
  pll_rate = clk_get_pll_rate();
  ctrl = reg_read_32((volatile unsigned int *)(0xbfe78034));
  if ((0x1 << 0) & ctrl) {
    if ((0x1 << 15) & ctrl) {
      cpu_rate = pll_rate / ((ctrl & (0x7f << 8)) >> (8));
    } else {
      cpu_rate = pll_rate / 2;
    }
  } else {
    cpu_rate = ((24000000));
  }
  return cpu_rate;
}


x86 assembly (clang, -O0):
<clk_get_cpu_rate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <clk_get_pll_rate@plt>
mov    %rax,-0x8(%rbp)
mov    $0xbfe78034,%edi
call   1030 <reg_read_32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1191 <clk_get_cpu_rate+0x71>
mov    -0x14(%rbp),%eax
and    $0x8000,%eax
cmp    $0x0,%eax
je     1180 <clk_get_cpu_rate+0x60>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
and    $0x7f00,%ecx
shr    $0x8,%ecx
mov    %ecx,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    118c <clk_get_cpu_rate+0x6c>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1199 <clk_get_cpu_rate+0x79>
movq   $0x16e3600,-0x10(%rbp)
01
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clk_get_cpu_rate>:
push   %rbx
xor    %eax,%eax
call   1040 <clk_get_pll_rate@plt>
mov    %rax,%rbx
mov    $0xbfe78034,%edi
call   1030 <reg_read_32@plt>
mov    %eax,%ecx
mov    $0x16e3600,%eax
test   $0x1,%cl
je     114f <clk_get_cpu_rate+0x2f>
test   $0x8000,%ecx
jne    1151 <clk_get_cpu_rate+0x31>
shr    %rbx
mov    %rbx,%rax
pop    %rbx
ret
shr    $0x8,%ecx
and    $0x7f,%ecx
mov    %rbx,%rax
shr    $0x20,%rax
je     116a <clk_get_cpu_rate+0x4a>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
pop    %rbx
ret
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
pop    %rbx
ret

LLVM IR (-O0):
define i64 @clk_get_cpu_rate() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i32
%4 = call i64 (...) @clk_get_pll_rate()
store i64 %4, i64* %1
%5 = call i32 @reg_read_32(i32* inttoptr (i64 3219619892 to i32*))
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = and i32 1, %6
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %0
%10 = load i32, i32* %3
%11 = and i32 32768, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i64, i64* %1
%15 = load i32, i32* %3
%16 = and i32 %15, 32512
%17 = lshr i32 %16, 8
%18 = zext i32 %17 to i64
%19 = udiv i64 %14, %18
store i64 %19, i64* %2
br label %23
20: ; preds = %9
%21 = load i64, i64* %1
%22 = udiv i64 %21, 2
store i64 %22, i64* %2
br label %23
23: ; preds = %20, %13
br label %25
24: ; preds = %0
store i64 24000000, i64* %2
br label %25
25: ; preds = %24, %23
%26 = load i64, i64* %2
ret i64 %26
}

LLVM IR (-O2):
define i64 @clk_get_cpu_rate() {
%1 = tail call i64 (...) @clk_get_pll_rate()
%2 = tail call i32 @reg_read_32(i32* inttoptr (i64 3219619892 to i32*))
%3 = and i32 %2, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = and i32 %2, 32768
%7 = icmp eq i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = lshr i32 %2, 8
%10 = and i32 %9, 127
%11 = zext i32 %10 to i64
%12 = udiv i64 %1, %11
br label %15
13: ; preds = %5
%14 = lshr i64 %1, 1
br label %15
15: ; preds = %0, %8, %13
%16 = phi i64 [ %12, %8 ], [ %14, %13 ], [ 24000000, %0 ]
ret i64 %16
}