#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*/ CleanDataCache();
void CreatePageTable(unsigned int nMemSize) {
  unsigned int *pPageTable =
      (unsigned int *)(((((0x8000 + (2 * 1024 * 1024)) + 0x20000) + 0x8000) +
                        0x8000) +
                       0x8000);
  for (unsigned int nEntry = 0; nEntry < 4096; nEntry++) {
    unsigned int nBaseAddress = 1024 * 1024 * nEntry;
    unsigned int nAttributes = 0x0000;
    extern unsigned char _etext;
    if (nBaseAddress < (unsigned int)&_etext) {
      nAttributes = 0x1040E;
    } else if (nBaseAddress ==
               ((((((((0x8000 + (2 * 1024 * 1024)) + 0x20000) + 0x8000) +
                    0x8000) +
                   0x8000) +
                  0x4000) +
                 2 * 1024 * 1024) &
                ~(1024 * 1024 - 1))) {
      nAttributes = 0x10412;
    } else if (nBaseAddress < nMemSize) {
      nAttributes = 0x1041E;
    } else {
      nAttributes = 0x10416;
    }
    pPageTable[nEntry] = nBaseAddress | nAttributes;
  }
  CleanDataCache();
}


x86 assembly (clang, -O0):
<CreatePageTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x240000,%eax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
jae    11c4 <CreatePageTable+0xb4>
mov    -0x14(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    0x2e91(%rip),%rax
cmp    %eax,-0x18(%rbp)
jae    1164 <CreatePageTable+0x54>
movl   $0x1040e,-0x1c(%rbp)
jmp    11a6 <CreatePageTable+0x96>
cmpl   $0x400000,-0x18(%rbp)
jne    117d <CreatePageTable+0x6d>
movl   $0x10412,-0x1c(%rbp)
jmp    11a1 <CreatePageTable+0x91>
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    1195 <CreatePageTable+0x85>
movl   $0x1041e,-0x1c(%rbp)
jmp    119c <CreatePageTable+0x8c>
movl   $0x10416,-0x1c(%rbp)
jmp    11a1 <CreatePageTable+0x91>
jmp    11a6 <CreatePageTable+0x96>
mov    -0x18(%rbp),%edx
or     -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112b <CreatePageTable+0x1b>
mov    $0x0,%al
call   1030 <CleanDataCache@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreatePageTable>:
mov    $0x240000,%r8d
xor    %eax,%eax
test   %edi,%edi
setne  %al
lea    0x10416(,%rax,8),%eax
mov    0x2eb5(%rip),%r10d
test   %r10d,%r10d
mov    $0x1040e,%r9d
cmovne %r9d,%eax
xor    %edx,%edx
cmp    $0x100001,%edi
setae  %dl
lea    0x110416(,%rdx,8),%esi
cmp    $0x100001,%r10d
mov    $0x11040e,%edx
cmovb  %esi,%edx
mov    %edi,%r11d
mov    %eax,0x240000
mov    %edx,0x240004
xor    %eax,%eax
cmp    $0x200001,%edi
setae  %al
lea    0x210416(,%rax,8),%eax
cmp    $0x200001,%r10d
mov    $0x21040e,%edx
cmovb  %eax,%edx
mov    %edx,0x240008
xor    %eax,%eax
cmp    $0x300001,%edi
setae  %al
lea    0x310416(,%rax,8),%eax
cmp    $0x300001,%r10d
mov    $0x31040e,%edx
cmovb  %eax,%edx
mov    %edx,0x24000c
xor    %eax,%eax
cmp    $0x400001,%r10d
setb   %al
lea    0x41040e(,%rax,4),%eax
mov    %eax,0x240010
mov    $0x6,%edi
mov    $0x500000,%eax
mov    $0x600000,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ecx,%ecx
cmp    %r11,%rax
setb   %cl
cmp    %r10,%rax
lea    0x10416(,%rcx,8),%ecx
cmovb  %r9d,%ecx
mov    %eax,%esi
or     %ecx,%esi
mov    %esi,-0x4(%r8,%rdi,4)
cmp    $0x1000,%rdi
je     1249 <CreatePageTable+0x139>
xor    %ecx,%ecx
cmp    %r11,%rdx
setb   %cl
cmp    %r10,%rdx
lea    0x10416(,%rcx,8),%ecx
cmovb  %r9d,%ecx
mov    %edx,%esi
or     %ecx,%esi
mov    %esi,(%r8,%rdi,4)
add    $0x2,%rdi
add    $0x200000,%rax
add    $0x200000,%rdx
jmp    11f0 <CreatePageTable+0xe0>
xor    %eax,%eax
jmp    1030 <CleanDataCache@plt>

LLVM IR (-O0):
@_etext = external global i8
define void @CreatePageTable(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32* inttoptr (i64 2359296 to i32*), i32** %3
store i32 0, i32* %4
br label %7
7: ; preds = %36, %1
%8 = load i32, i32* %4
%9 = icmp ult i32 %8, 4096
br i1 %9, label %10, label %39
10: ; preds = %7
%11 = load i32, i32* %4
%12 = mul i32 1048576, %11
store i32 %12, i32* %5
store i32 0, i32* %6
%13 = load i32, i32* %5
%14 = icmp ult i32 %13, ptrtoint (i8* @_etext to i32)
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 66574, i32* %6
br label %28
16: ; preds = %10
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 4194304
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 66578, i32* %6
br label %27
20: ; preds = %16
%21 = load i32, i32* %5
%22 = load i32, i32* %2
%23 = icmp ult i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 66590, i32* %6
br label %26
25: ; preds = %20
store i32 66582, i32* %6
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26, %19
br label %28
28: ; preds = %27, %15
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = or i32 %29, %30
%32 = load i32*, i32** %3
%33 = load i32, i32* %4
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 %31, i32* %35
br label %36
36: ; preds = %28
%37 = load i32, i32* %4
%38 = add i32 %37, 1
store i32 %38, i32* %4
br label %7
39: ; preds = %7
%40 = call i32 (...) @CleanDataCache()
ret void
}

LLVM IR (-O2):
@_etext = external global i8
define void @CreatePageTable(i32 %0) {
%2 = zext i32 %0 to i64
%3 = icmp eq i32 %0, 0
%4 = select i1 %3, i32 66582, i32 66590
%5 = select i1 icmp ugt (i32 ptrtoint (i8* @_etext to i32), i32 0), i32 66574, i32 %4
store i32 %5, i32* inttoptr (i64 2359296 to i32*)
%6 = icmp ugt i32 %0, 1048576
%7 = select i1 %6, i32 1115166, i32 1115158
%8 = select i1 icmp ugt (i32 ptrtoint (i8* @_etext to i32), i32 1048576), i32 1115150, i32 %7
store i32 %8, i32* inttoptr (i64 2359300 to i32*)
%9 = icmp ugt i32 %0, 2097152
%10 = select i1 %9, i32 2163742, i32 2163734
%11 = select i1 icmp ugt (i32 ptrtoint (i8* @_etext to i32), i32 2097152), i32 2163726, i32 %10
store i32 %11, i32* inttoptr (i64 2359304 to i32*)
%12 = icmp ugt i32 %0, 3145728
%13 = select i1 %12, i32 3212318, i32 3212310
%14 = select i1 icmp ugt (i32 ptrtoint (i8* @_etext to i32), i32 3145728), i32 3212302, i32 %13
store i32 %14, i32* inttoptr (i64 2359308 to i32*)
store i32 select (i1 icmp ugt (i32 ptrtoint (i8* @_etext to i32), i32 4194304), i32 4260878, i32 4260882), i32* inttoptr (i64 2359312 to i32*)
br label %17
15: ; preds = %17
%16 = tail call i32 (...) @CleanDataCache()
ret void
17: ; preds = %29, %1
%18 = phi i64 [ 5, %1 ], [ %38, %29 ]
%19 = shl nuw i64 %18, 20
%20 = icmp ult i64 %19, zext (i32 ptrtoint (i8* @_etext to i32) to i64)
%21 = icmp ult i64 %19, %2
%22 = select i1 %21, i32 66590, i32 66582
%23 = select i1 %20, i32 66574, i32 %22
%24 = trunc i64 %19 to i32
%25 = or i32 %23, %24
%26 = getelementptr inbounds i32, i32* inttoptr (i64 2359296 to i32*), i64 %18
store i32 %25, i32* %26
%27 = add nuw nsw i64 %18, 1
%28 = icmp eq i64 %27, 4096
br i1 %28, label %15, label %29
29: ; preds = %17
%30 = shl nuw i64 %27, 20
%31 = icmp ult i64 %30, zext (i32 ptrtoint (i8* @_etext to i32) to i64)
%32 = icmp ult i64 %30, %2
%33 = select i1 %32, i32 66590, i32 66582
%34 = select i1 %31, i32 66574, i32 %33
%35 = trunc i64 %30 to i32
%36 = or i32 %34, %35
%37 = getelementptr inbounds i32, i32* inttoptr (i64 2359296 to i32*), i64 %27
store i32 %36, i32* %37
%38 = add nuw nsw i64 %18, 2
br label %17
}