#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*/ mmu_get_perms(int, int, int *, int *, int *, int *);
int /*<<< orphan*/ printf(char *, unsigned int, char *, ...);
void mmu_dump_pages(unsigned int vaddr, unsigned int entry) {
  int xn;
  int ng;
  int s;
  int ap2;
  int ap1;
  int pr;
  int pw;
  int ur;
  int uw;
  unsigned int paddr;
  if ((entry & 0x3) == 0x1) {
    xn = entry & 0x8000;
    ng = entry & 0x800;
    s = entry & 0x400;
    ap2 = entry & 0x200;
    ap1 = (entry >> 4) & 3;
    mmu_get_perms(ap2, ap1, &ur, &uw, &pr, &pw);
    paddr = entry & 0xFFFF0000;
    printf("-[0x%08X] %s PA:0x%08X NG:%d SH:%d UR:%d UW:%d PR:%d PW:%d XN:%d\n",
           vaddr, "Lg Page  ", paddr, !!ng, !!s, !!ur, !!uw, !!pr, !!pw, !!xn);
  } else if ((entry & 0x2)) {
    xn = entry & 1;
    ng = entry & 0x800;
    s = entry & 0x400;
    ap2 = entry & 0x200;
    ap1 = (entry >> 4) & 3;
    mmu_get_perms(ap2, ap1, &ur, &uw, &pr, &pw);
    paddr = entry & 0xFFFFF000;
    printf("-[0x%08X] %s PA:0x%08X NG:%d SH:%d UR:%d UW:%d PR:%d PW:%d XN:%d\n",
           vaddr, "Sm Page  ", paddr, !!ng, !!s, !!ur, !!uw, !!pr, !!pw, !!xn);
  } else {
    printf("-[0x%08X] %s\n", vaddr, "Unmapped ");
  }
}


x86 assembly (clang, -O0):
<mmu_dump_pages>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    1249 <mmu_dump_pages+0x129>
mov    -0x18(%rbp),%eax
and    $0x8000,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0x800,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
and    $0x400,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
and    $0x200,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x4,%eax
and    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1040 <mmu_get_perms@plt>
mov    -0x18(%rbp),%eax
and    $0xffff0000,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%ecx
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r8d
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r9d
cmpl   $0x0,-0x38(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r14d
cmpl   $0x0,-0x3c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ebx
cmpl   $0x0,-0x30(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r11d
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r10d
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
lea    0xde0(%rip),%rdi
lea    0xe1b(%rip),%rdx
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    137c <mmu_dump_pages+0x25c>
mov    -0x18(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     135f <mmu_dump_pages+0x23f>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0x800,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
and    $0x400,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
and    $0x200,%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x4,%eax
and    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
lea    -0x38(%rbp),%rdx
lea    -0x3c(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x34(%rbp),%r9
call   1040 <mmu_get_perms@plt>
mov    -0x18(%rbp),%eax
and    $0xfffff000,%eax
mov    %eax,-0x40(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x40(%rbp),%ecx
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r8d
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r9d
cmpl   $0x0,-0x38(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r14d
cmpl   $0x0,-0x3c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%ebx
cmpl   $0x0,-0x30(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r11d
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%r10d
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
lea    0xcca(%rip),%rdi
lea    0xd0f(%rip),%rdx
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1377 <mmu_dump_pages+0x257>
mov    -0x14(%rbp),%esi
lea    0xced(%rip),%rdi
lea    0xcf4(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    137c <mmu_dump_pages+0x25c>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmu_dump_pages>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r15d
mov    %esi,%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    11d8 <mmu_dump_pages+0xb8>
mov    %ebx,%edi
and    $0x200,%edi
mov    %ebx,%esi
shr    $0x4,%esi
and    $0x3,%esi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1040 <mmu_get_perms@plt>
mov    %ebx,%ecx
and    $0xffff0000,%ecx
mov    %ebx,%r8d
shr    $0xb,%r8d
and    $0x1,%r8d
mov    %ebx,%r9d
shr    $0xa,%r9d
and    $0x1,%r9d
xor    %r10d,%r10d
cmpl   $0x0,0x4(%rsp)
setne  %r10b
xor    %r11d,%r11d
cmpl   $0x0,(%rsp)
setne  %r11b
xor    %r14d,%r14d
cmpl   $0x0,0xc(%rsp)
setne  %r14b
xor    %ebp,%ebp
cmpl   $0x0,0x8(%rsp)
setne  %bpl
shr    $0xf,%ebx
and    $0x1,%ebx
sub    $0x8,%rsp
lea    0xe3d(%rip),%rdi
lea    0xe78(%rip),%rdx
mov    %r15d,%esi
xor    %eax,%eax
push   %rbx
push   %rbp
push   %r14
jmp    1295 <mmu_dump_pages+0x175>
test   $0x2,%bl
jne    1201 <mmu_dump_pages+0xe1>
lea    0xe72(%rip),%rdi
lea    0xe79(%rip),%rdx
mov    %r15d,%esi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    %ebx,%r14d
and    $0x1,%r14d
mov    %ebx,%edi
and    $0x200,%edi
mov    %ebx,%esi
shr    $0x4,%esi
and    $0x3,%esi
lea    0x4(%rsp),%rdx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1040 <mmu_get_perms@plt>
mov    %ebx,%ecx
and    $0xfffff000,%ecx
mov    %ebx,%r8d
shr    $0xb,%r8d
and    $0x1,%r8d
shr    $0xa,%ebx
and    $0x1,%ebx
xor    %r10d,%r10d
cmpl   $0x0,0x4(%rsp)
setne  %r10b
xor    %r11d,%r11d
cmpl   $0x0,(%rsp)
setne  %r11b
xor    %r12d,%r12d
cmpl   $0x0,0xc(%rsp)
setne  %r12b
xor    %ebp,%ebp
cmpl   $0x0,0x8(%rsp)
setne  %bpl
sub    $0x8,%rsp
lea    0xd7f(%rip),%rdi
lea    0xdc4(%rip),%rdx
mov    %r15d,%esi
mov    %ebx,%r9d
xor    %eax,%eax
push   %r14
push   %rbp
push   %r12
push   %r11
push   %r10
call   1030 <printf@plt>
add    $0x30,%rsp
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"-[0x%08X] %s PA:0x%08X NG:%d SH:%d UR:%d UW:%d PR:%d PW:%d XN:%d\0A\00"
@.str.1 = [10 x i8] c"Lg Page \00"
@.str.2 = [10 x i8] c"Sm Page \00"
@.str.3 = [14 x i8] c"-[0x%08X] %s\0A\00"
@.str.4 = [10 x i8] c"Unmapped \00"
define void @mmu_dump_pages(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%15 = load i32, i32* %4
%16 = and i32 %15, 3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %73
18: ; preds = %2
%19 = load i32, i32* %4
%20 = and i32 %19, 32768
store i32 %20, i32* %5
%21 = load i32, i32* %4
%22 = and i32 %21, 2048
store i32 %22, i32* %6
%23 = load i32, i32* %4
%24 = and i32 %23, 1024
store i32 %24, i32* %7
%25 = load i32, i32* %4
%26 = and i32 %25, 512
store i32 %26, i32* %8
%27 = load i32, i32* %4
%28 = lshr i32 %27, 4
%29 = and i32 %28, 3
store i32 %29, i32* %9
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = call i32 @mmu_get_perms(i32 %30, i32 %31, i32* %12, i32* %13, i32* %10, i32* %11)
%33 = load i32, i32* %4
%34 = and i32 %33, -65536
store i32 %34, i32* %14
%35 = load i32, i32* %3
%36 = load i32, i32* %14
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = xor i1 %39, true
%41 = zext i1 %40 to i32
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
%44 = xor i1 %43, true
%45 = xor i1 %44, true
%46 = zext i1 %45 to i32
%47 = load i32, i32* %12
%48 = icmp ne i32 %47, 0
%49 = xor i1 %48, true
%50 = xor i1 %49, true
%51 = zext i1 %50 to i32
%52 = load i32, i32* %13
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
%55 = xor i1 %54, true
%56 = zext i1 %55 to i32
%57 = load i32, i32* %10
%58 = icmp ne i32 %57, 0
%59 = xor i1 %58, true
%60 = xor i1 %59, true
%61 = zext i1 %60 to i32
%62 = load i32, i32* %11
%63 = icmp ne i32 %62, 0
%64 = xor i1 %63, true
%65 = xor i1 %64, true
%66 = zext i1 %65 to i32
%67 = load i32, i32* %5
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
%70 = xor i1 %69, true
%71 = zext i1 %70 to i32
%72 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %35, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %41, i32 %46, i32 %51, i32 %56, i32 %61, i32 %66, i32 %71)
br label %136
73: ; preds = %2
%74 = load i32, i32* %4
%75 = and i32 %74, 2
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %132
77: ; preds = %73
%78 = load i32, i32* %4
%79 = and i32 %78, 1
store i32 %79, i32* %5
%80 = load i32, i32* %4
%81 = and i32 %80, 2048
store i32 %81, i32* %6
%82 = load i32, i32* %4
%83 = and i32 %82, 1024
store i32 %83, i32* %7
%84 = load i32, i32* %4
%85 = and i32 %84, 512
store i32 %85, i32* %8
%86 = load i32, i32* %4
%87 = lshr i32 %86, 4
%88 = and i32 %87, 3
store i32 %88, i32* %9
%89 = load i32, i32* %8
%90 = load i32, i32* %9
%91 = call i32 @mmu_get_perms(i32 %89, i32 %90, i32* %12, i32* %13, i32* %10, i32* %11)
%92 = load i32, i32* %4
%93 = and i32 %92, -4096
store i32 %93, i32* %14
%94 = load i32, i32* %3
%95 = load i32, i32* %14
%96 = load i32, i32* %6
%97 = icmp ne i32 %96, 0
%98 = xor i1 %97, true
%99 = xor i1 %98, true
%100 = zext i1 %99 to i32
%101 = load i32, i32* %7
%102 = icmp ne i32 %101, 0
%103 = xor i1 %102, true
%104 = xor i1 %103, true
%105 = zext i1 %104 to i32
%106 = load i32, i32* %12
%107 = icmp ne i32 %106, 0
%108 = xor i1 %107, true
%109 = xor i1 %108, true
%110 = zext i1 %109 to i32
%111 = load i32, i32* %13
%112 = icmp ne i32 %111, 0
%113 = xor i1 %112, true
%114 = xor i1 %113, true
%115 = zext i1 %114 to i32
%116 = load i32, i32* %10
%117 = icmp ne i32 %116, 0
%118 = xor i1 %117, true
%119 = xor i1 %118, true
%120 = zext i1 %119 to i32
%121 = load i32, i32* %11
%122 = icmp ne i32 %121, 0
%123 = xor i1 %122, true
%124 = xor i1 %123, true
%125 = zext i1 %124 to i32
%126 = load i32, i32* %5
%127 = icmp ne i32 %126, 0
%128 = xor i1 %127, true
%129 = xor i1 %128, true
%130 = zext i1 %129 to i32
%131 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %94, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %95, i32 %100, i32 %105, i32 %110, i32 %115, i32 %120, i32 %125, i32 %130)
br label %135
132: ; preds = %73
%133 = load i32, i32* %3
%134 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %133, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %135
135: ; preds = %132, %77
br label %136
136: ; preds = %135, %18
ret void
}

LLVM IR (-O2):
@.str = [66 x i8] c"-[0x%08X] %s PA:0x%08X NG:%d SH:%d UR:%d UW:%d PR:%d PW:%d XN:%d\0A\00"
@.str.1 = [10 x i8] c"Lg Page \00"
@.str.2 = [10 x i8] c"Sm Page \00"
@.str.3 = [14 x i8] c"-[0x%08X] %s\0A\00"
@.str.4 = [10 x i8] c"Unmapped \00"
define void @mmu_dump_pages(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = and i32 %1, 3
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %38
13: ; preds = %2
%14 = and i32 %1, 512
%15 = lshr i32 %1, 4
%16 = and i32 %15, 3
%17 = call i32 @mmu_get_perms(i32 %14, i32 %16, i32* %5, i32* %6, i32* %3, i32* %4)
%18 = and i32 %1, -65536
%19 = lshr i32 %1, 11
%20 = and i32 %19, 1
%21 = lshr i32 %1, 10
%22 = and i32 %21, 1
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i32
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
%34 = zext i1 %33 to i32
%35 = lshr i32 %1, 15
%36 = and i32 %35, 1
%37 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %20, i32 %22, i32 %25, i32 %28, i32 %31, i32 %34, i32 %36)
br label %67
38: ; preds = %2
%39 = and i32 %1, 2
%40 = icmp eq i32 %39, 0
br i1 %40, label %65, label %41
41: ; preds = %38
%42 = and i32 %1, 1
%43 = and i32 %1, 512
%44 = lshr i32 %1, 4
%45 = and i32 %44, 3
%46 = call i32 @mmu_get_perms(i32 %43, i32 %45, i32* %5, i32* %6, i32* %3, i32* %4)
%47 = and i32 %1, -4096
%48 = lshr i32 %1, 11
%49 = and i32 %48, 1
%50 = lshr i32 %1, 10
%51 = and i32 %50, 1
%52 = load i32, i32* %5
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i32
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, 0
%57 = zext i1 %56 to i32
%58 = load i32, i32* %3
%59 = icmp ne i32 %58, 0
%60 = zext i1 %59 to i32
%61 = load i32, i32* %4
%62 = icmp ne i32 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %47, i32 %49, i32 %51, i32 %54, i32 %57, i32 %60, i32 %63, i32 %42)
br label %67
65: ; preds = %38
%66 = tail call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %67
67: ; preds = %41, %65, %13
ret void
}