#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*/ path;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ PTRACE_ATTACH;
int /*<<< orphan*/ PTRACE_CONT;
int /*<<< orphan*/ PTRACE_DETACH;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fatal(char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getopt(int, char **, char *);
int getpagesize();
int /*<<< orphan*/ lseek(int, unsigned long long, int /*<<< orphan*/);
void *malloc(int);
int open(char *, int, ...);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ ptrace(int /*<<< orphan*/, int, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int read(int, void *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char *, char *, unsigned long long *, unsigned long long *, char *,
           unsigned long long *);
int /*<<< orphan*/ *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ write(int, void *, int);
int main(int argc, char *argv[]) {
  char path[PATH_MAX], line[1024];
  FILE *mfd;
  void *buf;
  int rfd, wfd, pid, c, pgsz;
  while ((c = getopt(argc, argv, "h")) != -1) {
    switch (c) {
    case 'h':
    default:
      usage();
      break;
    }
  }
  argc -= optind;
  argv += optind;
  if (argc < 2)
    usage();
  pid = atoi(argv[0]);
  if (ptrace(PTRACE_ATTACH, pid, 0, 0) < 0)
    fatal("failed to attach to process %d: %s\n", pid, strerror(errno));
  snprintf(path, sizeof(path), "/proc/%d/maps", pid);
  mfd = fopen(path, "rb");
  if (mfd == NULL)
    fatal("%s: %s", path, strerror(errno));
  snprintf(path, sizeof(path), "/proc/%d/mem", pid);
  rfd = open(path, O_RDONLY);
  if (rfd < 0)
    fatal("%s: %s", path, strerror(errno));
  wfd = open(argv[1], O_WRONLY | O_CREAT, 0644);
  if (wfd < 0)
    fatal("%s: %s", argv[1], strerror(errno));
  pgsz = getpagesize();
  buf = malloc(pgsz);
  if (buf == NULL)
    fatal("%s", strerror(errno));
  while (fgets(line, sizeof(line), mfd)) {
    char perm[32];
    unsigned long long addr, start, end, size, off;
    int n;
    pgsz = getpagesize();
    n = sscanf(line, "%llx-%llx %31s %llx", &start, &end, perm, &off);
    if (n != 4)
      continue;
    size = end - start;
    printf("%llx-%llx %llx %s %llx\n", start, end, size, perm, off);
    if (strchr(perm, 'r') == NULL)
      continue;
    lseek(rfd, start, SEEK_SET);
    for (addr = start; addr < end; addr += pgsz) {
      n = read(rfd, buf, pgsz);
      if (n < 0)
        printf("%s\n", strerror(errno));
      write(wfd, buf, pgsz);
    }
  }
  fclose(mfd);
  close(rfd);
  close(wfd);
  ptrace(PTRACE_CONT, pid, 0, 0);
  ptrace(PTRACE_DETACH, pid, 0, 0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x4b0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x4a8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd63(%rip),%rdx
call   1120 <getopt@plt>
mov    %eax,-0x440(%rbp)
cmp    $0xffffffff,%eax
je     12d6 <main+0x96>
mov    -0x440(%rbp),%eax
sub    $0x68,%eax
jne    12ca <main+0x8a>
jmp    12c5 <main+0x85>
jmp    12ca <main+0x8a>
mov    $0x0,%al
call   10f0 <usage@plt>
jmp    128f <main+0x4f>
mov    0x2ceb(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1311 <main+0xd1>
mov    $0x0,%al
call   10f0 <usage@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x43c(%rbp)
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
mov    -0x43c(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   10e0 <ptrace@plt>
cmp    $0x0,%rax
jge    1376 <main+0x136>
mov    -0x43c(%rbp),%eax
mov    %eax,-0x4b4(%rbp)
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x4b4(%rbp),%esi
mov    %rax,%rdx
lea    0xc93(%rip),%rdi
mov    $0x0,%al
call   1160 <fatal@plt>
mov    -0x4a8(%rbp),%rdi
mov    -0x4b0(%rbp),%rax
mov    %eax,%esi
mov    -0x43c(%rbp),%ecx
lea    0xc93(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x4a8(%rbp),%rdi
lea    0xc8e(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    13e6 <main+0x1a6>
mov    0x2be9(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x4a8(%rbp),%rsi
mov    %rax,%rdx
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1160 <fatal@plt>
mov    -0x4a8(%rbp),%rdi
mov    -0x4b0(%rbp),%rax
mov    %eax,%esi
mov    -0x43c(%rbp),%ecx
lea    0xc3b(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x4a8(%rbp),%rdi
mov    0x2bc2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1100 <open@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jge    1458 <main+0x218>
mov    0x2b77(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x4a8(%rbp),%rsi
mov    %rax,%rdx
lea    0xbe6(%rip),%rdi
mov    $0x0,%al
call   1160 <fatal@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2b29(%rip),%rax
mov    (%rax),%esi
mov    0x2b88(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1100 <open@plt>
mov    %eax,-0x438(%rbp)
cmpl   $0x0,-0x438(%rbp)
jge    14c6 <main+0x286>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x4c0(%rbp)
mov    0x2b09(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    -0x4c0(%rbp),%rsi
mov    %rax,%rdx
lea    0xb78(%rip),%rdi
mov    $0x0,%al
call   1160 <fatal@plt>
mov    $0x0,%al
call   1140 <getpagesize@plt>
mov    %eax,-0x444(%rbp)
mov    -0x444(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    1512 <main+0x2d2>
mov    0x2ab6(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    %rax,%rsi
lea    0xb30(%rip),%rdi
mov    $0x0,%al
call   1160 <fatal@plt>
jmp    1517 <main+0x2d7>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   10b0 <fgets@plt>
cmp    $0x0,%rax
je     16b1 <main+0x471>
mov    $0x0,%al
call   1140 <getpagesize@plt>
mov    %eax,-0x444(%rbp)
lea    -0x420(%rbp),%rdi
lea    -0x470(%rbp),%r8
lea    0xaf0(%rip),%rsi
lea    -0x480(%rbp),%rdx
lea    -0x488(%rbp),%rcx
lea    -0x498(%rbp),%r9
call   10d0 <sscanf@plt>
mov    %eax,-0x49c(%rbp)
cmpl   $0x4,-0x49c(%rbp)
je     158d <main+0x34d>
jmp    1517 <main+0x2d7>
mov    -0x488(%rbp),%rax
sub    -0x480(%rbp),%rax
mov    %rax,-0x490(%rbp)
mov    -0x480(%rbp),%rsi
mov    -0x488(%rbp),%rdx
mov    -0x490(%rbp),%rcx
lea    -0x470(%rbp),%r8
mov    -0x498(%rbp),%r9
lea    0xa93(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x470(%rbp),%rdi
mov    $0x72,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    15f3 <main+0x3b3>
jmp    1517 <main+0x2d7>
mov    -0x434(%rbp),%edi
mov    -0x480(%rbp),%rsi
mov    0x29a1(%rip),%rax
mov    (%rax),%edx
call   1080 <lseek@plt>
mov    -0x480(%rbp),%rax
mov    %rax,-0x478(%rbp)
mov    -0x478(%rbp),%rax
cmp    -0x488(%rbp),%rax
jae    16ac <main+0x46c>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   10a0 <read@plt>
mov    %eax,-0x49c(%rbp)
cmpl   $0x0,-0x49c(%rbp)
jge    167a <main+0x43a>
mov    0x294e(%rip),%rax
mov    (%rax),%edi
call   1150 <strerror@plt>
mov    %rax,%rsi
lea    0x9af(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x438(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   1030 <write@plt>
movslq -0x444(%rbp),%rax
add    -0x478(%rbp),%rax
mov    %rax,-0x478(%rbp)
jmp    161c <main+0x3dc>
jmp    1517 <main+0x2d7>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x434(%rbp),%edi
call   1090 <close@plt>
mov    -0x438(%rbp),%edi
call   1090 <close@plt>
mov    0x28c6(%rip),%rax
mov    (%rax),%edi
mov    -0x43c(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   10e0 <ptrace@plt>
mov    0x28de(%rip),%rax
mov    (%rax),%edi
mov    -0x43c(%rbp),%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   10e0 <ptrace@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
mov    %rsi,%r13
mov    %edi,%ebx
mov    0x2d78(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r15
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xd75(%rip),%rdx
call   1130 <getopt@plt>
cmp    $0xffffffff,%eax
je     12b9 <main+0x69>
lea    0xd64(%rip),%r12
nopl   0x0(%rax)
xor    %eax,%eax
call   1100 <usage@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r12,%rdx
call   1130 <getopt@plt>
cmp    $0xffffffff,%eax
jne    12a0 <main+0x50>
mov    0x2d08(%rip),%rax
mov    (%rax),%r12
sub    %r12d,%ebx
cmp    $0x1,%ebx
jg     12d2 <main+0x82>
xor    %eax,%eax
call   1100 <usage@plt>
mov    0x0(%r13,%r12,8),%rdi
call   1140 <atoi@plt>
mov    %eax,%ebx
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10f0 <ptrace@plt>
test   %rax,%rax
jns    1318 <main+0xc8>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xcf6(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1170 <fatal@plt>
lea    0xd07(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%ecx
call   1080 <snprintf@plt>
lea    0xd01(%rip),%rsi
mov    %r15,%rdi
call   1120 <fopen@plt>
mov    %rax,-0x38(%rbp)
test   %rax,%rax
jne    1366 <main+0x116>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xcde(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1170 <fatal@plt>
lea    0xcd1(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,-0x4c(%rbp)
mov    %ebx,%ecx
call   1080 <snprintf@plt>
mov    0x2c54(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
jns    13b9 <main+0x169>
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xc8b(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1170 <fatal@plt>
mov    0x8(%r13,%r12,8),%rdi
mov    0x2bcb(%rip),%rax
mov    0x2c2c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,-0x30(%rbp)
test   %eax,%eax
jns    140a <main+0x1ba>
mov    0x8(%r13,%r12,8),%rbx
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xc3a(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1170 <fatal@plt>
xor    %eax,%eax
call   1150 <getpagesize@plt>
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    143f <main+0x1ef>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
lea    0xc06(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1170 <fatal@plt>
lea    -0x480(%rbp),%rdi
mov    $0x400,%esi
mov    -0x38(%rbp),%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     1574 <main+0x324>
lea    -0x480(%rbp),%rbx
jmp    1491 <main+0x241>
cs nopw 0x0(%rax,%rax,1)
lea    -0x480(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    -0x38(%rbp),%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     1574 <main+0x324>
xor    %eax,%eax
call   1150 <getpagesize@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
lea    0xba6(%rip),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x80(%rbp),%r8
lea    -0x58(%rbp),%r9
call   10e0 <sscanf@plt>
cmp    $0x4,%eax
mov    -0x30(%rbp),%ebx
jne    1470 <main+0x220>
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rsi
mov    %rdx,%rcx
sub    %rsi,%rcx
mov    -0x58(%rbp),%r9
lea    0xb84(%rip),%rdi
lea    -0x80(%rbp),%r15
mov    %r15,%r8
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    $0x72,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1470 <main+0x220>
mov    -0x48(%rbp),%rsi
mov    0x2a9e(%rip),%rax
mov    (%rax),%edx
mov    -0x2c(%rbp),%edi
call   1090 <lseek@plt>
mov    -0x48(%rbp),%r15
cmp    -0x40(%rbp),%r15
jae    1470 <main+0x220>
movslq %r13d,%r12
jmp    154a <main+0x2fa>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
add    %r12,%r15
cmp    -0x40(%rbp),%r15
jae    1470 <main+0x220>
mov    -0x2c(%rbp),%edi
mov    %r14,%rsi
mov    %r13d,%edx
call   10b0 <read@plt>
test   %eax,%eax
jns    1530 <main+0x2e0>
mov    0x2a4d(%rip),%rax
mov    (%rax),%edi
call   1160 <strerror@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    1530 <main+0x2e0>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%edi
call   10a0 <close@plt>
mov    0x2a0c(%rip),%rax
mov    (%rax),%edi
mov    -0x4c(%rbp),%ebx
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10f0 <ptrace@plt>
mov    0x2a25(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   10f0 <ptrace@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"h\00"
@optind = global i64 0
@PTRACE_ATTACH = global i32 0
@.str.1 = [36 x i8] c"failed to attach to process %d: %s\0A\00"
@errno = global i32 0
@.str.2 = [14 x i8] c"/proc/%d/maps\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [7 x i8] c"%s: %s\00"
@.str.5 = [13 x i8] c"/proc/%d/mem\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [20 x i8] c"%llx-%llx %31s %llx\00"
@.str.8 = [24 x i8] c"%llx-%llx %llx %s %llx\0A\00"
@SEEK_SET = global i32 0
@.str.9 = [4 x i8] c"%s\0A\00"
@PTRACE_CONT = global i32 0
@PTRACE_DETACH = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [1024 x i8]
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [32 x i8]
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%23 = load i32, i32* @PATH_MAX
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
store i8* %25, i8** %6
%26 = alloca i8, i64 %24
store i64 %24, i64* %7
br label %27
27: ; preds = %37, %2
%28 = load i32, i32* %4
%29 = load i8**, i8*** %5
%30 = call i32 @getopt(i32 %28, i8** %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %30, i32* %14
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* %14
switch i32 %33, label %35 [
i32 104, label %34
]
34: ; preds = %32
br label %35
35: ; preds = %32, %34
%36 = call i32 (...) @usage()
br label %37
37: ; preds = %35
br label %27
38: ; preds = %27
%39 = load i64, i64* @optind
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = sub nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %4
%44 = load i64, i64* @optind
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 %44
store i8** %46, i8*** %5
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 2
br i1 %48, label %49, label %51
49: ; preds = %38
%50 = call i32 (...) @usage()
br label %51
51: ; preds = %49, %38
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %13
%56 = load i32, i32* @PTRACE_ATTACH
%57 = load i32, i32* %13
%58 = call i64 @ptrace(i32 %56, i32 %57, i32 0, i32 0)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %51
%61 = load i32, i32* %13
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %61, i8* %63)
br label %65
65: ; preds = %60, %51
%66 = trunc i64 %24 to i32
%67 = load i32, i32* %13
%68 = call i32 @snprintf(i8* %26, i32 %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %67)
%69 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %69, i32** %9
%70 = load i32*, i32** %9
%71 = icmp eq i32* %70, null
br i1 %71, label %72, label %76
72: ; preds = %65
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %26, i8* %74)
br label %76
76: ; preds = %72, %65
%77 = trunc i64 %24 to i32
%78 = load i32, i32* %13
%79 = call i32 @snprintf(i8* %26, i32 %77, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %78)
%80 = load i32, i32* @O_RDONLY
%81 = call i32 (i8*, i32, ...) @open(i8* %26, i32 %80)
store i32 %81, i32* %11
%82 = load i32, i32* %11
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %76
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %26, i8* %86)
br label %88
88: ; preds = %84, %76
%89 = load i8**, i8*** %5
%90 = getelementptr inbounds i8*, i8** %89, i64 1
%91 = load i8*, i8** %90
%92 = load i32, i32* @O_WRONLY
%93 = load i32, i32* @O_CREAT
%94 = or i32 %92, %93
%95 = call i32 (i8*, i32, ...) @open(i8* %91, i32 %94, i32 420)
store i32 %95, i32* %12
%96 = load i32, i32* %12
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %105
98: ; preds = %88
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %101, i8* %103)
br label %105
105: ; preds = %98, %88
%106 = call i32 (...) @getpagesize()
store i32 %106, i32* %15
%107 = load i32, i32* %15
%108 = call i8* @malloc(i32 %107)
store i8* %108, i8** %10
%109 = load i8*, i8** %10
%110 = icmp eq i8* %109, null
br i1 %110, label %111, label %115
111: ; preds = %105
%112 = load i32, i32* @errno
%113 = call i8* @strerror(i32 %112)
%114 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %113)
br label %115
115: ; preds = %111, %105
br label %116
116: ; preds = %174, %142, %128, %115
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%118 = load i32*, i32** %9
%119 = call i64 @fgets(i8* %117, i32 1024, i32* %118)
%120 = icmp ne i64 %119, 0
br i1 %120, label %121, label %175
121: ; preds = %116
%122 = call i32 (...) @getpagesize()
store i32 %122, i32* %15
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%124 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%125 = call i32 @sscanf(i8* %123, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64* %18, i64* %19, i8* %124, i64* %21)
store i32 %125, i32* %22
%126 = load i32, i32* %22
%127 = icmp ne i32 %126, 4
br i1 %127, label %128, label %129
128: ; preds = %121
br label %116
129: ; preds = %121
%130 = load i64, i64* %19
%131 = load i64, i64* %18
%132 = sub i64 %130, %131
store i64 %132, i64* %20
%133 = load i64, i64* %18
%134 = load i64, i64* %19
%135 = load i64, i64* %20
%136 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%137 = load i64, i64* %21
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %133, i64 %134, i64 %135, i8* %136, i64 %137)
%139 = getelementptr inbounds [32 x i8], [32 x i8]* %16, i64 0, i64 0
%140 = call i32* @strchr(i8* %139, i8 signext 114)
%141 = icmp eq i32* %140, null
br i1 %141, label %142, label %143
142: ; preds = %129
br label %116
143: ; preds = %129
%144 = load i32, i32* %11
%145 = load i64, i64* %18
%146 = load i32, i32* @SEEK_SET
%147 = call i32 @lseek(i32 %144, i64 %145, i32 %146)
%148 = load i64, i64* %18
store i64 %148, i64* %17
br label %149
149: ; preds = %169, %143
%150 = load i64, i64* %17
%151 = load i64, i64* %19
%152 = icmp ult i64 %150, %151
br i1 %152, label %153, label %174
153: ; preds = %149
%154 = load i32, i32* %11
%155 = load i8*, i8** %10
%156 = load i32, i32* %15
%157 = call i32 @read(i32 %154, i8* %155, i32 %156)
store i32 %157, i32* %22
%158 = load i32, i32* %22
%159 = icmp slt i32 %158, 0
br i1 %159, label %160, label %164
160: ; preds = %153
%161 = load i32, i32* @errno
%162 = call i8* @strerror(i32 %161)
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* %162)
br label %164
164: ; preds = %160, %153
%165 = load i32, i32* %12
%166 = load i8*, i8** %10
%167 = load i32, i32* %15
%168 = call i32 @write(i32 %165, i8* %166, i32 %167)
br label %169
169: ; preds = %164
%170 = load i32, i32* %15
%171 = sext i32 %170 to i64
%172 = load i64, i64* %17
%173 = add i64 %172, %171
store i64 %173, i64* %17
br label %149
174: ; preds = %149
br label %116
175: ; preds = %116
%176 = load i32*, i32** %9
%177 = call i32 @fclose(i32* %176)
%178 = load i32, i32* %11
%179 = call i32 @close(i32 %178)
%180 = load i32, i32* %12
%181 = call i32 @close(i32 %180)
%182 = load i32, i32* @PTRACE_CONT
%183 = load i32, i32* %13
%184 = call i64 @ptrace(i32 %182, i32 %183, i32 0, i32 0)
%185 = load i32, i32* @PTRACE_DETACH
%186 = load i32, i32* %13
%187 = call i64 @ptrace(i32 %185, i32 %186, i32 0, i32 0)
%188 = load i8*, i8** %6
%189 = load i32, i32* %3
ret i32 %189
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [2 x i8] c"h\00"
@optind = global i64 0
@PTRACE_ATTACH = global i32 0
@.str.1 = [36 x i8] c"failed to attach to process %d: %s\0A\00"
@errno = global i32 0
@.str.2 = [14 x i8] c"/proc/%d/maps\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [7 x i8] c"%s: %s\00"
@.str.5 = [13 x i8] c"/proc/%d/mem\00"
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [20 x i8] c"%llx-%llx %31s %llx\00"
@.str.8 = [24 x i8] c"%llx-%llx %llx %s %llx\0A\00"
@SEEK_SET = global i32 0
@PTRACE_CONT = global i32 0
@PTRACE_DETACH = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = alloca [32 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %2, %14
%15 = tail call i32 (...) @usage()
%16 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %14
18: ; preds = %14, %2
%19 = load i64, i64* @optind
%20 = trunc i64 %19 to i32
%21 = sub i32 %0, %20
%22 = getelementptr inbounds i8*, i8** %1, i64 %19
%23 = icmp slt i32 %21, 2
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = tail call i32 (...) @usage()
br label %26
26: ; preds = %24, %18
%27 = load i8*, i8** %22
%28 = tail call i32 @atoi(i8* %27)
%29 = load i32, i32* @PTRACE_ATTACH
%30 = tail call i64 @ptrace(i32 %29, i32 %28, i32 0, i32 0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %26
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %34)
br label %36
36: ; preds = %32, %26
%37 = call i32 @snprintf(i8* %10, i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%38 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %42)
br label %44
44: ; preds = %40, %36
%45 = call i32 @snprintf(i8* %10, i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%46 = load i32, i32* @O_RDONLY
%47 = call i32 (i8*, i32, ...) @open(i8* %10, i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %51)
br label %53
53: ; preds = %49, %44
%54 = getelementptr inbounds i8*, i8** %22, i64 1
%55 = load i8*, i8** %54
%56 = load i32, i32* @O_WRONLY
%57 = load i32, i32* @O_CREAT
%58 = or i32 %57, %56
%59 = call i32 (i8*, i32, ...) @open(i8* %55, i32 %58, i32 420)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %53
%62 = load i8*, i8** %54
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %62, i8* %64)
br label %66
66: ; preds = %61, %53
%67 = call i32 (...) @getpagesize()
%68 = call i8* @malloc(i32 %67)
%69 = icmp eq i8* %68, null
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i8*, ...) @fatal(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %70, %66
%75 = call i64 @fgets(i8* %11, i32 1024, i32* %38)
%76 = icmp eq i64 %75, 0
br i1 %76, label %119, label %77
77: ; preds = %74
%78 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%79 = bitcast i64* %5 to i8*
%80 = bitcast i64* %6 to i8*
%81 = bitcast i64* %7 to i8*
br label %82
82: ; preds = %77, %116
%83 = call i32 (...) @getpagesize()
%84 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64* %5, i64* %6, i8* %78, i64* %7)
%85 = icmp eq i32 %84, 4
br i1 %85, label %86, label %116
86: ; preds = %82
%87 = load i64, i64* %6
%88 = load i64, i64* %5
%89 = sub i64 %87, %88
%90 = load i64, i64* %7
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 %88, i64 %87, i64 %89, i8* %78, i64 %90)
%92 = call i32* @strchr(i8* %78, i8 signext 114)
%93 = icmp eq i32* %92, null
br i1 %93, label %116, label %94
94: ; preds = %86
%95 = load i64, i64* %5
%96 = load i32, i32* @SEEK_SET
%97 = call i32 @lseek(i32 %47, i64 %95, i32 %96)
%98 = load i64, i64* %5
%99 = load i64, i64* %6
%100 = icmp ult i64 %98, %99
br i1 %100, label %101, label %116
101: ; preds = %94
%102 = sext i32 %83 to i64
br label %103
103: ; preds = %101, %111
%104 = phi i64 [ %98, %101 ], [ %113, %111 ]
%105 = call i32 @read(i32 %47, i8* %68, i32 %83)
%106 = icmp slt i32 %105, 0
br i1 %106, label %107, label %111
107: ; preds = %103
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 @puts(i8* dereferenceable(1) %109)
br label %111
111: ; preds = %107, %103
%112 = call i32 @write(i32 %59, i8* %68, i32 %83)
%113 = add i64 %104, %102
%114 = load i64, i64* %6
%115 = icmp ult i64 %113, %114
br i1 %115, label %103, label %116
116: ; preds = %111, %94, %86, %82
%117 = call i64 @fgets(i8* %11, i32 1024, i32* %38)
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %82
119: ; preds = %116, %74
%120 = call i32 @fclose(i32* %38)
%121 = call i32 @close(i32 %47)
%122 = call i32 @close(i32 %59)
%123 = load i32, i32* @PTRACE_CONT
%124 = call i64 @ptrace(i32 %123, i32 %28, i32 0, i32 0)
%125 = load i32, i32* @PTRACE_DETACH
%126 = call i64 @ptrace(i32 %125, i32 %28, i32 0, i32 0)
ret i32 0
}