#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 */
uint32_t get_sclk_apll() {
  uint32_t mdiv, pdiv, sdiv;
  mdiv = ((*((volatile uint32_t *)0xE0100100)) & 0x3ff0000) >> 16;
  pdiv = ((*((volatile uint32_t *)0xE0100100)) & 0x3f00) >> 8;
  sdiv = (*((volatile uint32_t *)0xE0100100)) & 0x03;
  if ((*((volatile uint32_t *)0xE0100200)) & 0x01)
    return mdiv * ((24000000) / (pdiv << (sdiv - 1)));
  else
    return (24000000);
}


x86 assembly (clang, -O0):
<get_sclk_apll>:
push   %rbp
mov    %rsp,%rbp
mov    $0xe0100100,%eax
mov    (%rax),%eax
and    $0x3ff0000,%eax
sar    $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    $0xe0100100,%eax
mov    (%rax),%eax
and    $0x3f00,%eax
sar    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    $0xe0100100,%eax
mov    (%rax),%eax
and    $0x3,%eax
mov    %eax,-0x10(%rbp)
mov    $0xe0100200,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1173 <get_sclk_apll+0x73>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
shl    %cl,%eax
mov    %eax,%ecx
mov    $0x16e3600,%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <get_sclk_apll+0x7a>
movl   $0x16e3600,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sclk_apll>:
mov    $0xe0100100,%edx
mov    (%rdx),%esi
mov    (%rdx),%edi
mov    (%rdx),%ecx
mov    $0x16e3600,%eax
testl  $0x1,0x100(%rdx)
je     113f <get_sclk_apll+0x3f>
shr    $0x8,%edi
and    $0x3f,%edi
shr    $0x10,%esi
and    $0x3ff,%esi
and    $0x3,%cl
add    $0xff,%cl
shl    %cl,%edi
mov    $0x16e3600,%eax
xor    %edx,%edx
idiv   %edi
imul   %esi,%eax
ret

LLVM IR (-O0):
define i32 @get_sclk_apll() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load volatile i32, i32* inttoptr (i64 3759145216 to i32*)
%6 = and i32 %5, 67043328
%7 = ashr i32 %6, 16
store i32 %7, i32* %2
%8 = load volatile i32, i32* inttoptr (i64 3759145216 to i32*)
%9 = and i32 %8, 16128
%10 = ashr i32 %9, 8
store i32 %10, i32* %3
%11 = load volatile i32, i32* inttoptr (i64 3759145216 to i32*)
%12 = and i32 %11, 3
store i32 %12, i32* %4
%13 = load volatile i32, i32* inttoptr (i64 3759145472 to i32*)
%14 = and i32 %13, 1
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %0
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = shl i32 %18, %20
%22 = sdiv i32 24000000, %21
%23 = mul nsw i32 %17, %22
store i32 %23, i32* %1
br label %25
24: ; preds = %0
store i32 24000000, i32* %1
br label %25
25: ; preds = %24, %16
%26 = load i32, i32* %1
ret i32 %26
}

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