#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 */

/* Variables and functions */
int /*<<< orphan*/ cm3_add_mpu_region(unsigned long, unsigned long,
                                      unsigned long const);
void mpu_init(const unsigned long *init_table) {
  unsigned long rbar, region = 0;
  if (init_table == (unsigned long *)0x00000000) {
    cm3_add_mpu_region(0, 0x00000000, (3 << 24) | (31 << 1) | (1 << 0));
  } else {
    while (*init_table != 0xFFFFFFFF) {
      rbar = *init_table;
      rbar |= region | (1 << 4);
      cm3_add_mpu_region(region, rbar, *(init_table + 1));
      init_table += 2;
      region++;
    }
  }
}


x86 assembly (clang, -O0):
<mpu_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1145 <mpu_init+0x35>
xor    %eax,%eax
mov    %eax,%esi
mov    $0x300003f,%edx
mov    %rsi,%rdi
call   1030 <cm3_add_mpu_region@plt>
jmp    11ae <mpu_init+0x9e>
jmp    114a <mpu_init+0x3a>
mov    -0x8(%rbp),%rax
mov    $0xffffffff,%ecx
cmp    %rcx,(%rax)
je     11a9 <mpu_init+0x99>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
or     $0x10,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rdx
call   1030 <cm3_add_mpu_region@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114a <mpu_init+0x3a>
jmp    11ae <mpu_init+0x9e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpu_init>:
test   %rdi,%rdi
je     1169 <mpu_init+0x59>
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rsi
mov    $0xffffffff,%r15d
cmp    %r15,%rsi
je     1163 <mpu_init+0x53>
add    $0x10,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
or     %rbx,%rsi
or     $0x10,%rsi
mov    -0x8(%r14),%rdx
mov    %rbx,%rdi
call   1030 <cm3_add_mpu_region@plt>
add    $0x1,%rbx
mov    (%r14),%rsi
add    $0x10,%r14
cmp    %r15,%rsi
jne    1140 <mpu_init+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x300003f,%edx
xor    %edi,%edi
xor    %esi,%esi
jmp    1030 <cm3_add_mpu_region@plt>

LLVM IR (-O0):
define void @mpu_init(i64* %0) {
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i64
store i64* %0, i64** %2
store i64 0, i64* %4
%5 = load i64*, i64** %2
%6 = icmp eq i64* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @cm3_add_mpu_region(i64 0, i64 0, i64 50331711)
br label %32
9: ; preds = %1
br label %10
10: ; preds = %14, %9
%11 = load i64*, i64** %2
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 4294967295
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i64*, i64** %2
%16 = load i64, i64* %15
store i64 %16, i64* %3
%17 = load i64, i64* %4
%18 = or i64 %17, 16
%19 = load i64, i64* %3
%20 = or i64 %19, %18
store i64 %20, i64* %3
%21 = load i64, i64* %4
%22 = load i64, i64* %3
%23 = load i64*, i64** %2
%24 = getelementptr inbounds i64, i64* %23, i64 1
%25 = load i64, i64* %24
%26 = call i32 @cm3_add_mpu_region(i64 %21, i64 %22, i64 %25)
%27 = load i64*, i64** %2
%28 = getelementptr inbounds i64, i64* %27, i64 2
store i64* %28, i64** %2
%29 = load i64, i64* %4
%30 = add i64 %29, 1
store i64 %30, i64* %4
br label %10
31: ; preds = %10
br label %32
32: ; preds = %31, %7
ret void
}

LLVM IR (-O2):
define void @mpu_init(i64* %0) {
%2 = icmp eq i64* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i64, i64* %0
%5 = icmp eq i64 %4, 4294967295
br i1 %5, label %21, label %8
6: ; preds = %1
%7 = tail call i32 @cm3_add_mpu_region(i64 0, i64 0, i64 50331711)
br label %21
8: ; preds = %3, %8
%9 = phi i64 [ %19, %8 ], [ %4, %3 ]
%10 = phi i64 [ %18, %8 ], [ 0, %3 ]
%11 = phi i64* [ %17, %8 ], [ %0, %3 ]
%12 = or i64 %10, %9
%13 = or i64 %12, 16
%14 = getelementptr inbounds i64, i64* %11, i64 1
%15 = load i64, i64* %14
%16 = tail call i32 @cm3_add_mpu_region(i64 %10, i64 %13, i64 %15)
%17 = getelementptr inbounds i64, i64* %11, i64 2
%18 = add i64 %10, 1
%19 = load i64, i64* %17
%20 = icmp eq i64 %19, 4294967295
br i1 %20, label %21, label %8
21: ; preds = %8, %3, %6
ret void
}