#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 scalar_t__ uint64_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ PTRACE_PEEKTEXT;
int /*<<< orphan*/ printf(char *, void *, long);
int /*<<< orphan*/ procmsg(char *, int /*<<< orphan*/, scalar_t__, scalar_t__);
long ptrace(int /*<<< orphan*/, int /*<<< orphan*/, void *, int /*<<< orphan*/);
void dump_process_memory(pid_t pid, uint64_t from_addr, uint64_t to_addr) {
  procmsg("Dump of %d's memory [%p : %p]\n", pid, from_addr, to_addr);
  for (uint64_t addr = from_addr; addr <= to_addr; ++addr) {
    long word = ptrace(PTRACE_PEEKTEXT, pid, (void *)addr, 0);
    printf("  %p:  %02lx\n", (void *)addr, word & 0xFF);
  }
}


x86 assembly (clang, -O0):
<dump_process_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xeab(%rip),%rdi
call   1030 <procmsg@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jg     11b7 <dump_process_memory+0x87>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x20(%rbp),%rdx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
and    $0xff,%rdx
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <dump_process_memory+0x32>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_process_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeb9(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1030 <procmsg@plt>
cmp    %r14,%rbx
jg     1197 <dump_process_memory+0x67>
add    $0x1,%r14
mov    0x2e7c(%rip),%r12
lea    0xeb4(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
movzbl %al,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <dump_process_memory+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Dump of %d's memory [%p : %p]\0A\00"
@PTRACE_PEEKTEXT = global i32 0
@.str.1 = [14 x i8] c" %p: %02lx\0A\00"
define void @dump_process_memory(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i32, i32* %4
%10 = load i64, i64* %5
%11 = load i64, i64* %6
%12 = call i32 @procmsg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %9, i64 %10, i64 %11)
%13 = load i64, i64* %5
store i64 %13, i64* %7
br label %14
14: ; preds = %29, %3
%15 = load i64, i64* %7
%16 = load i64, i64* %6
%17 = icmp sle i64 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i32, i32* @PTRACE_PEEKTEXT
%20 = load i32, i32* %4
%21 = load i64, i64* %7
%22 = inttoptr i64 %21 to i8*
%23 = call i64 @ptrace(i32 %19, i32 %20, i8* %22, i32 0)
store i64 %23, i64* %8
%24 = load i64, i64* %7
%25 = inttoptr i64 %24 to i8*
%26 = load i64, i64* %8
%27 = and i64 %26, 255
%28 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %25, i64 %27)
br label %29
29: ; preds = %18
%30 = load i64, i64* %7
%31 = add nsw i64 %30, 1
store i64 %31, i64* %7
br label %14
32: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"Dump of %d's memory [%p : %p]\0A\00"
@PTRACE_PEEKTEXT = global i32 0
@.str.1 = [14 x i8] c" %p: %02lx\0A\00"
define void @dump_process_memory(i32 %0, i64 %1, i64 %2) {
%4 = tail call i32 @procmsg(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0, i64 %1, i64 %2)
%5 = icmp sgt i64 %1, %2
br i1 %5, label %6, label %7
6: ; preds = %7, %3
ret void
7: ; preds = %3, %7
%8 = phi i64 [ %14, %7 ], [ %1, %3 ]
%9 = load i32, i32* @PTRACE_PEEKTEXT
%10 = inttoptr i64 %8 to i8*
%11 = tail call i64 @ptrace(i32 %9, i32 %0, i8* %10, i32 0)
%12 = and i64 %11, 255
%13 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %10, i64 %12)
%14 = add i64 %8, 1
%15 = icmp eq i64 %8, %2
br i1 %15, label %6, label %7
}