#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 */
void initSysClock(uint32_t reload, uint32_t clk_src) {
  uint32_t reg;
  uint32_t *pRCC_CR, *pLOAD, *pVAL, *pCTRL;
  pRCC_CR = (uint32_t *)(0x40023800 + 0x00);
  *pRCC_CR &= ~0x00050000;
  *pRCC_CR |= 0x00010000;
  while (!(*pRCC_CR & 0x00020000))
    ;
  uint32_t *pRCC_CFGR;
  pRCC_CFGR = (uint32_t *)(0x40023800 + 0x08);
  reg = *pRCC_CFGR;
  reg &= ~0x00000003;
  reg |= 0x00000001;
  *pRCC_CFGR = reg;
  if (reload != 0) {
    pLOAD = (uint32_t *)(0xE000E010U + 0x04);
    *pLOAD = (uint32_t)((25000000 / 8) / 1000 * reload - 1UL);
    pVAL = (uint32_t *)(0xE000E010U + 0x08);
    *pVAL = 0UL;
    pCTRL = (uint32_t *)(0xE000E010U + 0x00);
    *pCTRL |= 0x00000003;
  }
}


x86 assembly (clang, -O0):
<initSysClock>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x40023800,%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
and    $0xfffaffff,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
or     $0x10000,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0x20000,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    114f <initSysClock+0x4f>
jmp    1154 <initSysClock+0x54>
jmp    112f <initSysClock+0x2f>
mov    $0x40023808,%eax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x4(%rbp)
je     11d0 <initSysClock+0xd0>
mov    $0xe000e014,%eax
mov    %rax,-0x20(%rbp)
imul   $0xc35,-0x4(%rbp),%eax
cltq
sub    $0x1,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    $0xe000e018,%eax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    $0xe000e010,%eax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
or     $0x3,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<initSysClock>:
mov    0x40023800,%eax
mov    %eax,%ecx
and    $0xfffaffff,%ecx
or     $0x10000,%ecx
mov    %ecx,0x40023800
test   $0x20000,%eax
jne    1132 <initSysClock+0x32>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
jmp    1130 <initSysClock+0x30>
mov    0x40023808,%eax
and    $0xfffffffc,%eax
or     $0x1,%eax
mov    %eax,0x40023808
test   %edi,%edi
je     1165 <initSysClock+0x65>
imul   $0xc35,%edi,%eax
add    $0xffffffff,%eax
mov    $0xe000e010,%ecx
mov    %eax,0x4(%rcx)
movl   $0x0,0x8(%rcx)
orb    $0x3,(%rcx)
ret

LLVM IR (-O0):
define void @initSysClock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32* inttoptr (i64 1073887232 to i32*), i32** %6
%11 = load i32*, i32** %6
%12 = load i32, i32* %11
%13 = and i32 %12, -327681
store i32 %13, i32* %11
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
%16 = or i32 %15, 65536
store i32 %16, i32* %14
br label %17
17: ; preds = %23, %2
%18 = load i32*, i32** %6
%19 = load i32, i32* %18
%20 = and i32 %19, 131072
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %24
23: ; preds = %17
br label %17
24: ; preds = %17
store i32* inttoptr (i64 1073887240 to i32*), i32** %10
%25 = load i32*, i32** %10
%26 = load i32, i32* %25
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = and i32 %27, -4
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = or i32 %29, 1
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = load i32*, i32** %10
store i32 %31, i32* %32
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %24
store i32* inttoptr (i64 3758153748 to i32*), i32** %7
%36 = load i32, i32* %3
%37 = mul nsw i32 3125, %36
%38 = sext i32 %37 to i64
%39 = sub i64 %38, 1
%40 = trunc i64 %39 to i32
%41 = load i32*, i32** %7
store i32 %40, i32* %41
store i32* inttoptr (i64 3758153752 to i32*), i32** %8
%42 = load i32*, i32** %8
store i32 0, i32* %42
store i32* inttoptr (i64 3758153744 to i32*), i32** %9
%43 = load i32*, i32** %9
%44 = load i32, i32* %43
%45 = or i32 %44, 3
store i32 %45, i32* %43
br label %46
46: ; preds = %35, %24
ret void
}

LLVM IR (-O2):
define void @initSysClock(i32 %0, i32 %1) {
%3 = load i32, i32* inttoptr (i64 1073887232 to i32*)
%4 = and i32 %3, -327681
%5 = or i32 %4, 65536
store i32 %5, i32* inttoptr (i64 1073887232 to i32*)
%6 = and i32 %3, 131072
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2, %8
br label %8
9: ; preds = %2
%10 = load i32, i32* inttoptr (i64 1073887240 to i32*)
%11 = and i32 %10, -4
%12 = or i32 %11, 1
store i32 %12, i32* inttoptr (i64 1073887240 to i32*)
%13 = icmp eq i32 %0, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = mul nsw i32 %0, 3125
%16 = add i32 %15, -1
store i32 %16, i32* inttoptr (i64 3758153748 to i32*)
store i32 0, i32* inttoptr (i64 3758153752 to i32*)
%17 = load i32, i32* inttoptr (i64 3758153744 to i32*)
%18 = or i32 %17, 3
store i32 %18, i32* inttoptr (i64 3758153744 to i32*)
br label %19
19: ; preds = %14, %9
ret void
}