#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*/ printf(char *, ...);
void mem_print_page_va_info(unsigned int *pt, unsigned int va) {
  printf("Info for Virtual Address: 0x%h\n", va);
  printf("Translation table base: 0x%h\n", pt);
  unsigned int first_level_table_index = (va >> 20) & 0xFFF;
  unsigned int second_level_table_index = (va >> 12) & 0x7F;
  unsigned int page_index = (va & 0xFFF);
  printf("First level table index: 0x%h\n", first_level_table_index);
  printf("Second level table index: 0x%h\n", second_level_table_index);
  printf("Page index: 0x%h\n", page_index);
  unsigned int *first_level_descriptor =
      (unsigned int *)(((unsigned int)pt) + (first_level_table_index << 2));
  printf("First level descriptor address: 0x%h\n", first_level_descriptor);
  printf("First level descriptor: 0x%h\n", *first_level_descriptor);
  unsigned int coarse_table_base_addr =
      ((*first_level_descriptor >> 10) & 0x3FFFFF);
  printf("Coarse table base address: 0x%h ( 0x%h )\n", coarse_table_base_addr,
         (coarse_table_base_addr << 10));
  unsigned int *second_level_descriptor =
      (unsigned int *)((coarse_table_base_addr << 10) |
                       (second_level_table_index << 2));
  printf("Second level descriptor address: 0x%h\n", second_level_descriptor);
  printf("Second level descriptor: 0x%h\n", *second_level_descriptor);
  unsigned int physical_address =
      ((*second_level_descriptor & 0xFFFFF000) | page_index);
  printf("Physical address: 0x%h, Value: 0x%h\n", physical_address,
         *((unsigned int *)(0x80000000 + physical_address)));
}


x86 assembly (clang, -O0):
<mem_print_page_va_info>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xee5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
shr    $0x14,%eax
and    $0xfff,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
shr    $0xc,%eax
and    $0x7f,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xfff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%esi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xed8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
shr    $0xa,%eax
and    $0x3fffff,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
shl    $0xa,%edx
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
shl    $0xa,%eax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
or     %ecx,%eax
mov    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xee4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%esi
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
and    $0xfffff000,%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x34(%rbp),%eax
add    $0x80000000,%eax
mov    %eax,%eax
mov    (%rax),%edx
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_print_page_va_info>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeec(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%r12d
shr    $0x14,%r12d
mov    %r14d,%r13d
shr    $0xc,%r13d
and    $0x7f,%r13d
and    $0xfff,%r14d
lea    0xee0(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeee(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xefd(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%r15,%r12,4),%ebx
lea    0xefa(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%esi
lea    0xf0d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx),%ebx
mov    %ebx,%esi
shr    $0xa,%esi
and    $0xfffffc00,%ebx
lea    0xf10(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%rbx,%r13,4),%rsi
lea    0xf26(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx,%r13,4),%esi
lea    0xf3b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rbx,%r13,4),%esi
and    $0xfffff000,%esi
or     %r14,%rsi
mov    $0x80000000,%eax
xor    %rsi,%rax
mov    (%rax),%edx
lea    0xf35(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Info for Virtual Address: 0x%h\0A\00"
@.str.1 = [30 x i8] c"Translation table base: 0x%h\0A\00"
@.str.2 = [31 x i8] c"First level table index: 0x%h\0A\00"
@.str.3 = [32 x i8] c"Second level table index: 0x%h\0A\00"
@.str.4 = [18 x i8] c"Page index: 0x%h\0A\00"
@.str.5 = [38 x i8] c"First level descriptor address: 0x%h\0A\00"
@.str.6 = [30 x i8] c"First level descriptor: 0x%h\0A\00"
@.str.7 = [42 x i8] c"Coarse table base address: 0x%h ( 0x%h )\0A\00"
@.str.8 = [39 x i8] c"Second level descriptor address: 0x%h\0A\00"
@.str.9 = [31 x i8] c"Second level descriptor: 0x%h\0A\00"
@.str.10 = [37 x i8] c"Physical address: 0x%h, Value: 0x%h\0A\00"
define void @mem_print_page_va_info(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
store i32* %0, i32** %3
store i32 %1, i32* %4
%12 = load i32, i32* %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32*, i32** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = load i32, i32* %4
%17 = lshr i32 %16, 20
%18 = and i32 %17, 4095
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = lshr i32 %19, 12
%21 = and i32 %20, 127
store i32 %21, i32* %6
%22 = load i32, i32* %4
%23 = and i32 %22, 4095
store i32 %23, i32* %7
%24 = load i32, i32* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %3
%31 = ptrtoint i32* %30 to i32
%32 = load i32, i32* %5
%33 = shl i32 %32, 2
%34 = add i32 %31, %33
%35 = zext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %8
%37 = load i32*, i32** %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32* %37)
%39 = load i32*, i32** %8
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %40)
%42 = load i32*, i32** %8
%43 = load i32, i32* %42
%44 = lshr i32 %43, 10
%45 = and i32 %44, 4194303
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = load i32, i32* %9
%48 = shl i32 %47, 10
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %46, i32 %48)
%50 = load i32, i32* %9
%51 = shl i32 %50, 10
%52 = load i32, i32* %6
%53 = shl i32 %52, 2
%54 = or i32 %51, %53
%55 = zext i32 %54 to i64
%56 = inttoptr i64 %55 to i32*
store i32* %56, i32** %10
%57 = load i32*, i32** %10
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32* %57)
%59 = load i32*, i32** %10
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %60)
%62 = load i32*, i32** %10
%63 = load i32, i32* %62
%64 = and i32 %63, -4096
%65 = load i32, i32* %7
%66 = or i32 %64, %65
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = load i32, i32* %11
%69 = add i32 -2147483648, %68
%70 = zext i32 %69 to i64
%71 = inttoptr i64 %70 to i32*
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %67, i32 %72)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Info for Virtual Address: 0x%h\0A\00"
@.str.1 = [30 x i8] c"Translation table base: 0x%h\0A\00"
@.str.2 = [31 x i8] c"First level table index: 0x%h\0A\00"
@.str.3 = [32 x i8] c"Second level table index: 0x%h\0A\00"
@.str.4 = [18 x i8] c"Page index: 0x%h\0A\00"
@.str.5 = [38 x i8] c"First level descriptor address: 0x%h\0A\00"
@.str.6 = [30 x i8] c"First level descriptor: 0x%h\0A\00"
@.str.7 = [42 x i8] c"Coarse table base address: 0x%h ( 0x%h )\0A\00"
@.str.8 = [39 x i8] c"Second level descriptor address: 0x%h\0A\00"
@.str.9 = [31 x i8] c"Second level descriptor: 0x%h\0A\00"
@.str.10 = [37 x i8] c"Physical address: 0x%h, Value: 0x%h\0A\00"
define void @mem_print_page_va_info(i32* %0, i32 %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32* %0)
%5 = lshr i32 %1, 20
%6 = lshr i32 %1, 12
%7 = and i32 %6, 127
%8 = and i32 %1, 4095
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %8)
%12 = ptrtoint i32* %0 to i64
%13 = trunc i64 %12 to i32
%14 = shl nuw nsw i32 %5, 2
%15 = add i32 %14, %13
%16 = zext i32 %15 to i64
%17 = inttoptr i64 %16 to i32*
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32* %17)
%19 = load i32, i32* %17
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %17
%22 = lshr i32 %21, 10
%23 = and i32 %21, -1024
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i32 %22, i32 %23)
%25 = shl nuw nsw i32 %7, 2
%26 = or i32 %23, %25
%27 = zext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0), i32* %28)
%30 = load i32, i32* %28
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %28
%33 = and i32 %32, -4096
%34 = or i32 %33, %8
%35 = xor i32 %34, -2147483648
%36 = zext i32 %35 to i64
%37 = inttoptr i64 %36 to i32*
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.10, i64 0, i64 0), i32 %34, i32 %38)
ret void
}