#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
void cpu_set_interrupt_priority(uint8_t irq, uint8_t priority) {
  const uint32_t prio_shift = irq % 4 * 8 + 5;
  if (priority > 7)
    priority = 7;
  (*(volatile uint32_t *)(0xe000e400 + 4 * (irq / 4))) =
      ((*(volatile uint32_t *)(0xe000e400 + 4 * (irq / 4))) &
       ~(7 << prio_shift)) |
      (priority << prio_shift);
}


x86 assembly (clang, -O0):
<cpu_set_interrupt_priority>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
shl    $0x3,%eax
add    $0x5,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x7,-0x8(%rbp)
jle    1131 <cpu_set_interrupt_priority+0x31>
movl   $0x7,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
shl    $0x2,%eax
add    $0xe000e400,%eax
mov    %eax,%eax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
mov    $0x7,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
mov    -0x10(%rbp),%ecx
or     %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0x4,%esi
cltd
idiv   %esi
shl    $0x2,%eax
add    $0xe000e400,%eax
mov    %eax,%eax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_set_interrupt_priority>:
lea    0x3(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
and    $0xfffffffc,%eax
sub    %eax,%edi
lea    0x0(,%rdi,8),%ecx
cmp    $0x7,%esi
mov    $0x7,%edx
cmovge %edx,%esi
add    $0xe000e400,%eax
or     $0x5,%cl
shl    %cl,%edx
not    %edx
shl    %cl,%esi
and    (%rax),%edx
or     %edx,%esi
mov    %esi,(%rax)
ret

LLVM IR (-O0):
define void @cpu_set_interrupt_priority(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = srem i32 %6, 4
%8 = mul nsw i32 %7, 8
%9 = add nsw i32 %8, 5
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 7
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 7, i32* %4
br label %13
13: ; preds = %12, %2
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 4
%16 = mul nsw i32 4, %15
%17 = add i32 -536812544, %16
%18 = zext i32 %17 to i64
%19 = inttoptr i64 %18 to i32*
%20 = load volatile i32, i32* %19
%21 = load i32, i32* %5
%22 = shl i32 7, %21
%23 = xor i32 %22, -1
%24 = and i32 %20, %23
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = shl i32 %25, %26
%28 = or i32 %24, %27
%29 = load i32, i32* %3
%30 = sdiv i32 %29, 4
%31 = mul nsw i32 4, %30
%32 = add i32 -536812544, %31
%33 = zext i32 %32 to i64
%34 = inttoptr i64 %33 to i32*
store volatile i32 %28, i32* %34
ret void
}

LLVM IR (-O2):
define void @cpu_set_interrupt_priority(i32 %0, i32 %1) {
%3 = srem i32 %0, 4
%4 = shl nsw i32 %3, 3
%5 = or i32 %4, 5
%6 = icmp slt i32 %1, 7
%7 = select i1 %6, i32 %1, i32 7
%8 = sdiv i32 %0, 4
%9 = shl nsw i32 %8, 2
%10 = add i32 %9, -536812544
%11 = zext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = load volatile i32, i32* %12
%14 = shl i32 7, %5
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = shl i32 %7, %5
%18 = or i32 %16, %17
store volatile i32 %18, i32* %12
ret void
}