#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, int, int, int);
scalar_t__ strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
void getInfo(const char *virtualAddress) {
  int address = (int)strtol(virtualAddress, NULL, 0);
  int pageNumber = address / 8192;
  int offset = address % 8192;
  int virtual = 8192 * pageNumber + offset;
  printf("Virtual Address: 0x%x\nPage Size: %dKB\nPage Number: 0x%x\nOffset: "
         "0x%x\n",
         virtual, 8192 / 1024, pageNumber, offset);
}


x86 assembly (clang, -O0):
<getInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2000,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2000,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
shl    $0xd,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
lea    0xe89(%rip),%rdi
mov    $0x8,%edx
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getInfo>:
push   %rax
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
lea    0x1fff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %ecx,%edx
and    $0xffffe000,%edx
mov    %eax,%r8d
sub    %edx,%r8d
sar    $0xd,%ecx
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
mov    $0x8,%edx
pop    %rax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [70 x i8] c"Virtual Address: 0x%x\0APage Size: %dKB\0APage Number: 0x%x\0AOffset: 0x%x\0A\00"
define void @getInfo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strtol(i8* %7, i32* null, i32 0)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 8192
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = srem i32 %12, 8192
store i32 %13, i32* %5
%14 = load i32, i32* %4
%15 = mul nsw i32 8192, %14
%16 = load i32, i32* %5
%17 = add nsw i32 %15, %16
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %18, i32 8, i32 %19, i32 %20)
ret void
}

LLVM IR (-O2):
@.str = [70 x i8] c"Virtual Address: 0x%x\0APage Size: %dKB\0APage Number: 0x%x\0AOffset: 0x%x\0A\00"
define void @getInfo(i8* nocapture %0) {
%2 = tail call i64 @strtol(i8* nocapture %0, i32* null, i32 0)
%3 = trunc i64 %2 to i32
%4 = sdiv i32 %3, 8192
%5 = srem i32 %3, 8192
%6 = shl nsw i32 %4, 13
%7 = add nsw i32 %6, %5
%8 = tail call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %7, i32 8, i32 %4, i32 %5)
ret void
}