#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*/ pid_t;

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


x86 assembly (clang, -O0):
<dump_process_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xeaf(%rip),%rdi
call   1030 <procmsg@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11a7 <dump_process_memory+0x77>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
and    $0xff,%edx
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <dump_process_memory+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_process_memory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
lea    0xeba(%rip),%rdi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <procmsg@plt>
cmp    %ebx,%ebp
ja     1194 <dump_process_memory+0x64>
mov    0x2e83(%rip),%r12
lea    0xec3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%edi
mov    %r14d,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1050 <ptrace@plt>
movzbl %al,%edx
mov    %r15,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
jbe    1170 <dump_process_memory+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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