void __BSP_L1DSetProtection(unsigned int aid, unsigned int page_num,
                            unsigned int perm) {
  unsigned int tmp = 0;
  if (page_num > 15)
    return;
  if (aid > 5)
    tmp = (0x3 << 8) | (perm << 0);
  else
    tmp = (0x1 << (aid + 10)) | (0x1 << 8) | ((perm & 0x3f) << 0);
  ({
    unsigned long __v = tmp;
    (*(volatile unsigned long *)((0x0184ae40 + (page_num)*0x4)) = (__v));
    __v;
  });
}


x86 assembly (clang, -O0):
<__BSP_L1DSetProtection>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xf,-0x8(%rbp)
jbe    1123 <__BSP_L1DSetProtection+0x23>
jmp    1183 <__BSP_L1DSetProtection+0x83>
cmpl   $0x5,-0x4(%rbp)
jbe    1140 <__BSP_L1DSetProtection+0x40>
mov    -0xc(%rbp),%eax
shl    $0x0,%eax
or     $0x300,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <__BSP_L1DSetProtection+0x60>
mov    -0x4(%rbp),%ecx
add    $0xa,%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     $0x100,%eax
mov    -0xc(%rbp),%ecx
and    $0x3f,%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%eax
shl    $0x2,%eax
add    $0x184ae40,%eax
mov    %eax,%eax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<__BSP_L1DSetProtection>:
cmp    $0xf,%esi
ja     112e <__BSP_L1DSetProtection+0x2e>
cmp    $0x6,%edi
jb     1112 <__BSP_L1DSetProtection+0x12>
or     $0x300,%edx
jmp    1122 <__BSP_L1DSetProtection+0x22>
add    $0xa,%dil
and    $0x3f,%edx
bts    %edi,%edx
or     $0x100,%edx
mov    %edx,%eax
mov    %esi,%ecx
mov    %rax,0x184ae40(,%rcx,4)
01
ret

LLVM IR (-O0):
define void @__BSP_L1DSetProtection(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %5
%11 = icmp ugt i32 %10, 15
br i1 %11, label %12, label %13
12: ; preds = %3
br label %40
13: ; preds = %3
%14 = load i32, i32* %4
%15 = icmp ugt i32 %14, 5
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %6
%18 = shl i32 %17, 0
%19 = or i32 768, %18
store i32 %19, i32* %7
br label %29
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add i32 %21, 10
%23 = shl i32 1, %22
%24 = or i32 %23, 256
%25 = load i32, i32* %6
%26 = and i32 %25, 63
%27 = shl i32 %26, 0
%28 = or i32 %24, %27
store i32 %28, i32* %7
br label %29
29: ; preds = %20, %16
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
store i64 %31, i64* %8
%32 = load i64, i64* %8
%33 = load i32, i32* %5
%34 = mul i32 %33, 4
%35 = add i32 25472576, %34
%36 = zext i32 %35 to i64
%37 = inttoptr i64 %36 to i64*
store volatile i64 %32, i64* %37
%38 = load i64, i64* %8
store i64 %38, i64* %9
%39 = load i64, i64* %9
br label %40
40: ; preds = %29, %12
ret void
}

LLVM IR (-O2):
define void @__BSP_L1DSetProtection(i32 %0, i32 %1, i32 %2) {
%4 = icmp ugt i32 %1, 15
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = icmp ugt i32 %0, 5
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = or i32 %2, 768
br label %15
9: ; preds = %5
%10 = add nuw nsw i32 %0, 10
%11 = shl nuw nsw i32 1, %10
%12 = and i32 %2, 63
%13 = or i32 %11, %12
%14 = or i32 %13, 256
br label %15
15: ; preds = %9, %7
%16 = phi i32 [ %8, %7 ], [ %14, %9 ]
%17 = zext i32 %16 to i64
%18 = shl nuw nsw i32 %1, 2
%19 = add nuw nsw i32 %18, 25472576
%20 = zext i32 %19 to i64
%21 = inttoptr i64 %20 to i64*
store volatile i64 %17, i64* %21
br label %22
22: ; preds = %3, %15
ret void
}