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

/* Variables and functions */
int ReadProcessMemory(int, unsigned long, unsigned long, unsigned char *);
int /*<<< orphan*/ printf(char *, unsigned char);
int main(int argc, char **argv) {
  pid_t pid = 14413;
  unsigned long address = 210173952;
  unsigned long length = 0x40;
  unsigned char buf[64];
  int result = ReadProcessMemory(pid, address, length, buf);
  for (int i = 0; i < length; i++) {
    printf("%02X", buf[i]);
  }
  return (result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x384d,-0x14(%rbp)
movq   $0xc870000,-0x20(%rbp)
0c
movq   $0x40,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x70(%rbp),%rcx
call   1040 <ReadProcessMemory@plt>
mov    %eax,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
movslq -0x78(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    119f <main+0x7f>
movslq -0x78(%rbp),%rax
lea    0xe79(%rip),%rdi
movzbl -0x70(%rbp,%rax,1),%esi
call   1030 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    116e <main+0x4e>
mov    -0x74(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsp,%rcx
mov    $0xc870000,%esi
mov    $0x40,%edx
mov    $0x384d,%edi
call   1040 <ReadProcessMemory@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
lea    0xeb5(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%rbp,1),%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    $0x40,%rbp
jne    1150 <main+0x30>
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02X\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca [64 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 14413, i32* %6
store i64 210173952, i64* %7
store i64 64, i64* %8
%12 = load i32, i32* %6
%13 = load i64, i64* %7
%14 = load i64, i64* %8
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%16 = call i32 @ReadProcessMemory(i32 %12, i64 %13, i64 %14, i8* %15)
store i32 %16, i32* %10
store i32 0, i32* %11
br label %17
17: ; preds = %28, %2
%18 = load i32, i32* %11
%19 = sext i32 %18 to i64
%20 = load i64, i64* %8
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %11
%30 = add nsw i32 %29, 1
store i32 %30, i32* %11
br label %17
31: ; preds = %17
%32 = load i32, i32* %10
ret i32 %32
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02X\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @ReadProcessMemory(i32 14413, i64 210173952, i64 64, i8* %4)
br label %7
6: ; preds = %7
ret i32 %5
7: ; preds = %2, %7
%8 = phi i64 [ 0, %2 ], [ %12, %7 ]
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 64
br i1 %13, label %6, label %7
}