#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ hex_to_ascii(int /*<<< orphan*/, char *);
int /*<<< orphan*/ kmalloc(int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ kprint(char *);
void cmd_page() {
  uint32_t phys_addr;
  uint32_t page = kmalloc(1000, 1, &phys_addr);
  char page_str[16] = "";
  hex_to_ascii(page, page_str);
  char phys_str[16] = "";
  hex_to_ascii(phys_addr, phys_str);
  kprint("Page: ");
  kprint(page_str);
  kprint(", physical address: ");
  kprint(phys_str);
  kprint("\n");
}


x86 assembly (clang, -O0):
<cmd_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x3e8,%edi
mov    $0x1,%esi
lea    -0x4(%rbp),%rdx
call   1060 <kmalloc@plt>
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <hex_to_ascii@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <hex_to_ascii@plt>
lea    0xe63(%rip),%rdi
call   1040 <kprint@plt>
lea    -0x20(%rbp),%rdi
call   1040 <kprint@plt>
lea    0xe55(%rip),%rdi
call   1040 <kprint@plt>
lea    -0x30(%rbp),%rdi
call   1040 <kprint@plt>
lea    0xe55(%rip),%rdi
call   1040 <kprint@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_page>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xc(%rsp),%rdx
mov    $0x3e8,%edi
mov    $0x1,%esi
call   1050 <kmalloc@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <hex_to_ascii@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1040 <hex_to_ascii@plt>
lea    0xe8e(%rip),%rdi
call   1030 <kprint@plt>
mov    %rbx,%rdi
call   1030 <kprint@plt>
lea    0xe81(%rip),%rdi
call   1030 <kprint@plt>
mov    %r14,%rdi
call   1030 <kprint@plt>
lea    0xe82(%rip),%rdi
call   1030 <kprint@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Page: \00"
@.str.1 = [21 x i8] c", physical address: \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @cmd_page() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [16 x i8]
%4 = alloca [16 x i8]
%5 = call i32 @kmalloc(i32 1000, i32 1, i32* %1)
store i32 %5, i32* %2
%6 = bitcast [16 x i8]* %3 to i8*
%7 = load i32, i32* %2
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%9 = call i32 @hex_to_ascii(i32 %7, i8* %8)
%10 = bitcast [16 x i8]* %4 to i8*
%11 = load i32, i32* %1
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%13 = call i32 @hex_to_ascii(i32 %11, i8* %12)
%14 = call i32 @kprint(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%16 = call i32 @kprint(i8* %15)
%17 = call i32 @kprint(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%19 = call i32 @kprint(i8* %18)
%20 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"Page: \00"
@.str.1 = [21 x i8] c", physical address: \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @cmd_page() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = bitcast i32* %1 to i8*
%5 = call i32 @kmalloc(i32 1000, i32 1, i32* %1)
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%7 = call i32 @hex_to_ascii(i32 %5, i8* %6)
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* %1
%10 = call i32 @hex_to_ascii(i32 %9, i8* %8)
%11 = call i32 @kprint(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @kprint(i8* %6)
%13 = call i32 @kprint(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @kprint(i8* %8)
%15 = call i32 @kprint(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}