#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 *, int);
void printAllRealPgd(int pgdcount, int countedpages[pgdcount], int max_idx,
                     int potengtialPdgArray[pgdcount], int pageSize) {
  int i;
  for (i = 0; i < pgdcount; i++) {
    if (countedpages[i] == max_idx || i == max_idx) {
      printf("pgd physical address:0x%x\n", potengtialPdgArray[i] * pageSize);
    }
  }
}


x86 assembly (clang, -O0):
<printAllRealPgd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118b <printAllRealPgd+0x7b>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
je     115d <printAllRealPgd+0x4d>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1178 <printAllRealPgd+0x68>
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
imul   -0x24(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
jmp    117d <printAllRealPgd+0x6d>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1131 <printAllRealPgd+0x21>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAllRealPgd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,0x4(%rsp)
test   %edi,%edi
jle    116b <printAllRealPgd+0x5b>
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edx,%r13d
mov    %edi,%r12d
xor    %r14d,%r14d
jmp    115e <printAllRealPgd+0x4e>
nopw   0x0(%rax,%rax,1)
mov    (%r15,%r14,4),%esi
imul   0x4(%rsp),%esi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r12
je     116b <printAllRealPgd+0x5b>
cmp    %ebp,(%rbx,%r14,4)
je     1140 <printAllRealPgd+0x30>
cmp    %r14,%r13
jne    1155 <printAllRealPgd+0x45>
jmp    1140 <printAllRealPgd+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"pgd physical address:0x%x\0A\00"
define void @printAllRealPgd(i32 %0, i32* %1, i32 %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = load i32, i32* %6
%15 = zext i32 %14 to i64
store i32 0, i32* %11
br label %16
16: ; preds = %42, %5
%17 = load i32, i32* %11
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = load i32, i32* %8
%27 = icmp eq i32 %25, %26
br i1 %27, label %32, label %28
28: ; preds = %20
%29 = load i32, i32* %11
%30 = load i32, i32* %8
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %41
32: ; preds = %28, %20
%33 = load i32*, i32** %9
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %10
%39 = mul nsw i32 %37, %38
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %32, %28
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %16
45: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"pgd physical address:0x%x\0A\00"
define void @printAllRealPgd(i32 %0, i32* nocapture %1, i32 %2, i32* nocapture %3, i32 %4) {
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %25
7: ; preds = %5
%8 = zext i32 %2 to i64
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %7, %22
%11 = phi i64 [ 0, %7 ], [ %23, %22 ]
%12 = getelementptr inbounds i32, i32* %1, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, %2
%15 = icmp eq i64 %11, %8
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = getelementptr inbounds i32, i32* %3, i64 %11
%19 = load i32, i32* %18
%20 = mul nsw i32 %19, %4
%21 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %10, %17
%23 = add nuw nsw i64 %11, 1
%24 = icmp eq i64 %23, %9
br i1 %24, label %25, label %10
25: ; preds = %22, %5
ret void
}