#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 uint32_t;

/* Variables and functions */
int get_sclk_apll();
int get_sclk_mpll();
uint32_t get_hclk_dsys() {
  uint32_t a2m_ratio, hclk_dsys_ratio;
  a2m_ratio = ((*((volatile uint32_t *)0xE0100300)) & 0x70) >> 4;
  hclk_dsys_ratio = ((*((volatile uint32_t *)0xE0100300)) & 0xf0000) >> 16;
  if ((*((volatile uint32_t *)0xE0100200)) & 0x100000)
    return get_sclk_apll() / (a2m_ratio + 1) / (hclk_dsys_ratio + 1);
  else
    return get_sclk_mpll() / (hclk_dsys_ratio + 1);
}


x86 assembly (clang, -O0):
<get_hclk_dsys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xe0100300,%eax
mov    (%rax),%eax
and    $0x70,%eax
sar    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    $0xe0100300,%eax
mov    (%rax),%eax
and    $0xf0000,%eax
sar    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    $0xe0100200,%eax
mov    (%rax),%eax
and    $0x100000,%eax
cmp    $0x0,%eax
je     1180 <get_hclk_dsys+0x60>
mov    $0x0,%al
call   1040 <get_sclk_apll@plt>
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1193 <get_hclk_dsys+0x73>
mov    $0x0,%al
call   1030 <get_sclk_mpll@plt>
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hclk_dsys>:
push   %rbp
push   %rbx
push   %rax
mov    $0xe0100300,%eax
mov    (%rax),%ebp
mov    (%rax),%ebx
testl  $0x100000,-0x100(%rax)
jne    1141 <get_hclk_dsys+0x21>
xor    %eax,%eax
call   1030 <get_sclk_mpll@plt>
jmp    1154 <get_hclk_dsys+0x34>
shr    $0x4,%ebp
and    $0x7,%ebp
xor    %eax,%eax
call   1040 <get_sclk_apll@plt>
add    $0x1,%ebp
cltd
idiv   %ebp
shr    $0x10,%ebx
and    $0xf,%ebx
add    $0x1,%ebx
cltd
idiv   %ebx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_hclk_dsys() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = load volatile i32, i32* inttoptr (i64 3759145728 to i32*)
%5 = and i32 %4, 112
%6 = ashr i32 %5, 4
store i32 %6, i32* %2
%7 = load volatile i32, i32* inttoptr (i64 3759145728 to i32*)
%8 = and i32 %7, 983040
%9 = ashr i32 %8, 16
store i32 %9, i32* %3
%10 = load volatile i32, i32* inttoptr (i64 3759145472 to i32*)
%11 = and i32 %10, 1048576
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %0
%14 = call i32 (...) @get_sclk_apll()
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = sdiv i32 %14, %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = sdiv i32 %17, %19
store i32 %20, i32* %1
br label %26
21: ; preds = %0
%22 = call i32 (...) @get_sclk_mpll()
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
%25 = sdiv i32 %22, %24
store i32 %25, i32* %1
br label %26
26: ; preds = %21, %13
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
define i32 @get_hclk_dsys() {
%1 = load volatile i32, i32* inttoptr (i64 3759145728 to i32*)
%2 = load volatile i32, i32* inttoptr (i64 3759145728 to i32*)
%3 = load volatile i32, i32* inttoptr (i64 3759145472 to i32*)
%4 = and i32 %3, 1048576
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %0
%7 = lshr i32 %1, 4
%8 = and i32 %7, 7
%9 = tail call i32 (...) @get_sclk_apll()
%10 = add nuw nsw i32 %8, 1
%11 = sdiv i32 %9, %10
br label %14
12: ; preds = %0
%13 = tail call i32 (...) @get_sclk_mpll()
br label %14
14: ; preds = %12, %6
%15 = phi i32 [ %13, %12 ], [ %11, %6 ]
%16 = lshr i32 %2, 16
%17 = and i32 %16, 15
%18 = add nuw nsw i32 %17, 1
%19 = sdiv i32 %15, %18
ret i32 %19
}