#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ ROM_IntMasterEnable();
int /*<<< orphan*/ ROM_IntPriorityGet(int);
int ROM_SysCtlClockGet();
int /*<<< orphan*/ ROM_SysTickEnable();
int /*<<< orphan*/ ROM_SysTickIntEnable();
int /*<<< orphan*/ ROM_SysTickPeriodSet(int);
void setup_systick(int frequency) {
  *(((volatile unsigned long *)0xe000ed20)) |= (((unsigned long)32 - 1) << 16);
  *(((volatile unsigned long *)0xe000ed20)) |= (((unsigned long)32 - 1) << 24);
  uint32_t prio = ROM_IntPriorityGet(14);
  prio = ROM_IntPriorityGet(15);
  ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / frequency - 1);
  ROM_IntMasterEnable();
  ROM_SysTickIntEnable();
  ROM_SysTickEnable();
}


x86 assembly (clang, -O0):
<setup_systick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xe000ed20,%eax
mov    (%rax),%rcx
or     $0x1f0000,%rcx
mov    $0xe000ed20,%eax
mov    %rcx,(%rax)
mov    $0xe000ed20,%eax
mov    (%rax),%rcx
or     $0x1f000000,%rcx
mov    $0xe000ed20,%eax
mov    %rcx,(%rax)
mov    $0xe,%edi
call   1080 <ROM_IntPriorityGet@plt>
mov    %eax,-0x8(%rbp)
mov    $0xf,%edi
call   1080 <ROM_IntPriorityGet@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <ROM_SysCtlClockGet@plt>
cltd
idivl  -0x4(%rbp)
mov    %eax,%edi
sub    $0x1,%edi
call   1060 <ROM_SysTickPeriodSet@plt>
mov    $0x0,%al
call   1040 <ROM_IntMasterEnable@plt>
mov    $0x0,%al
call   1050 <ROM_SysTickIntEnable@plt>
mov    $0x0,%al
call   1070 <ROM_SysTickEnable@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_systick>:
push   %rbx
mov    $0xe000ed20,%eax
orq    $0x1f0000,(%rax)
mov    %edi,%ebx
orq    $0x1f000000,(%rax)
mov    $0xe,%edi
call   1080 <ROM_IntPriorityGet@plt>
mov    $0xf,%edi
call   1080 <ROM_IntPriorityGet@plt>
xor    %eax,%eax
call   1030 <ROM_SysCtlClockGet@plt>
cltd
idiv   %ebx
lea    -0x1(%rax),%edi
call   1060 <ROM_SysTickPeriodSet@plt>
xor    %eax,%eax
call   1040 <ROM_IntMasterEnable@plt>
xor    %eax,%eax
call   1050 <ROM_SysTickIntEnable@plt>
xor    %eax,%eax
pop    %rbx
jmp    1070 <ROM_SysTickEnable@plt>

LLVM IR (-O0):
define void @setup_systick(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load volatile i64, i64* inttoptr (i64 3758157088 to i64*)
%5 = or i64 %4, 2031616
store volatile i64 %5, i64* inttoptr (i64 3758157088 to i64*)
%6 = load volatile i64, i64* inttoptr (i64 3758157088 to i64*)
%7 = or i64 %6, 520093696
store volatile i64 %7, i64* inttoptr (i64 3758157088 to i64*)
%8 = call i32 @ROM_IntPriorityGet(i32 14)
store i32 %8, i32* %3
%9 = call i32 @ROM_IntPriorityGet(i32 15)
store i32 %9, i32* %3
%10 = call i32 (...) @ROM_SysCtlClockGet()
%11 = load i32, i32* %2
%12 = sdiv i32 %10, %11
%13 = sub nsw i32 %12, 1
%14 = call i32 @ROM_SysTickPeriodSet(i32 %13)
%15 = call i32 (...) @ROM_IntMasterEnable()
%16 = call i32 (...) @ROM_SysTickIntEnable()
%17 = call i32 (...) @ROM_SysTickEnable()
ret void
}

LLVM IR (-O2):
define void @setup_systick(i32 %0) {
%2 = load volatile i64, i64* inttoptr (i64 3758157088 to i64*)
%3 = or i64 %2, 2031616
store volatile i64 %3, i64* inttoptr (i64 3758157088 to i64*)
%4 = load volatile i64, i64* inttoptr (i64 3758157088 to i64*)
%5 = or i64 %4, 520093696
store volatile i64 %5, i64* inttoptr (i64 3758157088 to i64*)
%6 = tail call i32 @ROM_IntPriorityGet(i32 14)
%7 = tail call i32 @ROM_IntPriorityGet(i32 15)
%8 = tail call i32 (...) @ROM_SysCtlClockGet()
%9 = sdiv i32 %8, %0
%10 = add nsw i32 %9, -1
%11 = tail call i32 @ROM_SysTickPeriodSet(i32 %10)
%12 = tail call i32 (...) @ROM_IntMasterEnable()
%13 = tail call i32 (...) @ROM_SysTickIntEnable()
%14 = tail call i32 (...) @ROM_SysTickEnable()
ret void
}