#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;
typedef int /*<<< orphan*/ pages_to_protect;

/* Variables and functions */
int /*<<< orphan*/ cpu_write_dtlb(int const, int);
int /*<<< orphan*/ cpu_write_itlb(int const, int);
void cpu_configure_region_protection(void) {
  const uint32_t pages_to_protect[] = {0x00000000, 0x80000000, 0xa0000000,
                                       0xc0000000, 0xe0000000};
  for (int i = 0; i < sizeof(pages_to_protect) / sizeof(pages_to_protect[0]);
       ++i) {
    cpu_write_dtlb(pages_to_protect[i], 0xf);
    cpu_write_itlb(pages_to_protect[i], 0xf);
  }
  cpu_write_dtlb(0x20000000, 0);
  cpu_write_itlb(0x20000000, 0);
}


x86 assembly (clang, -O0):
<cpu_configure_region_protection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xed1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xecc(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x5,%rax
jae    118e <cpu_configure_region_protection+0x6e>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114e <cpu_configure_region_protection+0x2e>
mov    $0x20000000,%edi
xor    %esi,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0x20000000,%edi
xor    %esi,%esi
call   1040 <cpu_write_itlb@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_configure_region_protection>:
push   %rax
xor    %edi,%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
xor    %edi,%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    $0x80000000,%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0x80000000,%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    $0xa0000000,%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0xa0000000,%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    $0xc0000000,%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0xc0000000,%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    $0xe0000000,%edi
mov    $0xf,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0xe0000000,%edi
mov    $0xf,%esi
call   1040 <cpu_write_itlb@plt>
mov    $0x20000000,%edi
xor    %esi,%esi
call   1030 <cpu_write_dtlb@plt>
mov    $0x20000000,%edi
xor    %esi,%esi
pop    %rax
jmp    1040 <cpu_write_itlb@plt>

LLVM IR (-O0):
@__const.cpu_configure_region_protection.pages_to_protect = [5 x i32] [i32 0, i32 -2147483648, i32 -1610612736, i32 -1073741824, i32 -536870912]
define void @cpu_configure_region_protection() {
%1 = alloca [5 x i32]
%2 = alloca i32
%3 = bitcast [5 x i32]* %1 to i8*
store i32 0, i32* %2
br label %4
4: ; preds = %19, %0
%5 = load i32, i32* %2
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, 5
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @cpu_write_dtlb(i32 %12, i32 15)
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @cpu_write_itlb(i32 %17, i32 15)
br label %19
19: ; preds = %8
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %4
22: ; preds = %4
%23 = call i32 @cpu_write_dtlb(i32 536870912, i32 0)
%24 = call i32 @cpu_write_itlb(i32 536870912, i32 0)
ret void
}

LLVM IR (-O2):
define void @cpu_configure_region_protection() {
%1 = tail call i32 @cpu_write_dtlb(i32 0, i32 15)
%2 = tail call i32 @cpu_write_itlb(i32 0, i32 15)
%3 = tail call i32 @cpu_write_dtlb(i32 -2147483648, i32 15)
%4 = tail call i32 @cpu_write_itlb(i32 -2147483648, i32 15)
%5 = tail call i32 @cpu_write_dtlb(i32 -1610612736, i32 15)
%6 = tail call i32 @cpu_write_itlb(i32 -1610612736, i32 15)
%7 = tail call i32 @cpu_write_dtlb(i32 -1073741824, i32 15)
%8 = tail call i32 @cpu_write_itlb(i32 -1073741824, i32 15)
%9 = tail call i32 @cpu_write_dtlb(i32 -536870912, i32 15)
%10 = tail call i32 @cpu_write_itlb(i32 -536870912, i32 15)
%11 = tail call i32 @cpu_write_dtlb(i32 536870912, i32 0)
%12 = tail call i32 @cpu_write_itlb(i32 536870912, i32 0)
ret void
}