#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printInfo();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  printInfo();
  unsigned long int addressNum;
  unsigned int pageNum;
  unsigned int offSet;
  if (argc > 1 && argc <= 2) {
    addressNum = strtoul(argv[1], NULL, 10);
    if (addressNum < 4294967296) {
      pageNum = addressNum / 4096;
      offSet = addressNum % 4096;
      fprintf(stdout, "The address %d contains:\n", addressNum);
      fprintf(stdout, "page number = %d\n", pageNum);
      fprintf(stdout, "offset = %d\n", offSet);
    } else {
      fprintf(stderr, "ERROR Invalid Memory Address\n");
      return 1;
    }
  } else {
    fprintf(stderr, "ERROR Please provide %s with an address\n", argv[0]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <printInfo@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1223 <main+0xf3>
cmpl   $0x2,-0x8(%rbp)
jg     1223 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
movabs $0x100000000,%rax
cmp    %rax,-0x18(%rbp)
jae    11fb <main+0xcb>
mov    -0x18(%rbp),%rax
shr    $0xc,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
and    $0xfff,%rax
mov    %eax,-0x20(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    121e <main+0xee>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x124>
jmp    124d <main+0x11d>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0x124>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <printInfo@plt>
cmp    $0x2,%ebp
jne    11b8 <main+0x88>
mov    0x8(%rbx),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
shr    $0x20,%rcx
jne    11d4 <main+0xa4>
mov    %rax,%rbp
shr    $0xc,%rbp
mov    %eax,%r14d
and    $0xfff,%r14d
mov    0x2e5d(%rip),%r15
mov    (%r15),%edi
lea    0xe7b(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xe81(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r15),%edi
lea    0xe80(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f0 <main+0xc0>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe8c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11eb <main+0xbb>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [26 x i8] c"The address %d contains:\0A\00"
@.str.1 = [18 x i8] c"page number = %d\0A\00"
@.str.2 = [13 x i8] c"offset = %d\0A\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"ERROR Invalid Memory Address\0A\00"
@.str.4 = [41 x i8] c"ERROR Please provide %s with an address\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @printInfo()
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %42
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sle i32 %13, 2
br i1 %14, label %15, label %42
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strtoul(i8* %18, i32* null, i32 10)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp ult i64 %20, 4294967296
br i1 %21, label %22, label %38
22: ; preds = %15
%23 = load i64, i64* %6
%24 = udiv i64 %23, 4096
%25 = trunc i64 %24 to i32
store i32 %25, i32* %7
%26 = load i64, i64* %6
%27 = urem i64 %26, 4096
%28 = trunc i64 %27 to i32
store i32 %28, i32* %8
%29 = load i32, i32* @stdout
%30 = load i64, i64* %6
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %30)
%32 = load i32, i32* @stdout
%33 = load i32, i32* %7
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @stdout
%36 = load i32, i32* %8
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %41
38: ; preds = %15
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %49
41: ; preds = %22
br label %48
42: ; preds = %12, %2
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %46)
store i32 1, i32* %3
br label %49
48: ; preds = %41
store i32 0, i32* %3
br label %49
49: ; preds = %48, %42, %38
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [26 x i8] c"The address %d contains:\0A\00"
@.str.1 = [18 x i8] c"page number = %d\0A\00"
@.str.2 = [13 x i8] c"offset = %d\0A\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"ERROR Invalid Memory Address\0A\00"
@.str.4 = [41 x i8] c"ERROR Please provide %s with an address\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @printInfo()
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %24
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strtoul(i8* nocapture %7, i32* null, i32 10)
%9 = icmp ult i64 %8, 4294967296
br i1 %9, label %10, label %21
10: ; preds = %5
%11 = lshr i64 %8, 12
%12 = trunc i64 %11 to i32
%13 = trunc i64 %8 to i32
%14 = and i32 %13, 4095
%15 = load i32, i32* @stdout
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i64 %8)
%17 = load i32, i32* @stdout
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %28
21: ; preds = %5
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %28
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %10, %24, %21
%29 = phi i32 [ 0, %10 ], [ 1, %21 ], [ 1, %24 ]
ret i32 %29
}