// File: /workspace/github_cpp_makefile_star2_O3/illmat[P]MemCrawl/maps.cpp
// Function: getRegions(std::vector<scanRegion, std::allocator<scanRegion>>&, int)
int getRegions(std::vector<scanRegion> &regions, pid_t pid)
{
    std::stringstream path;
    path << "/proc/" << pid << "/maps";
    std::cout << "path:" << path.str() << std::endl;
    FILE *fp;
    char *line = NULL;
    size_t len = 0;
    ssize_t read;

    fp = fopen(path.str().c_str(), "r");
    if (fp == NULL)
    {
        std::cout << "unable to open file" << std::endl;
        return 1;
    }

    scanRegion lineBuffer;
    char readable, writeable;

    while ((read = getline(&line, &len, fp)) != -1)
    {
        if (sscanf(line, "%lx-%lx %c%c", &lineBuffer.startRegion, &lineBuffer.endRegion, &readable, &writeable) >= 4)
        {
            if ((readable == 'r') && (writeable == 'w'))
            {
                regions.push_back(lineBuffer);
            }
        }

    }
    fclose(fp);
    free(line);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movl %esi, %ebx
movq %rdi, %r15
leaq -0x1f0(%rbp), %rdi
callq 0x20f0
leaq -0x1e0(%rbp), %r14
leaq 0x1b26(%rip), %rsi      # 0x5159
movl $0x6, %edx
movq %r14, %rdi
callq 0x21e0
movq %r14, %rdi
movl %ebx, %esi
callq 0x22e0
leaq 0x1b0f(%rip), %rsi      # 0x5160
movl $0x5, %edx
movq %rax, %rdi
callq 0x21e0
movq 0x396b(%rip), %rdi      # 0x6fd0
leaq 0x1afa(%rip), %rsi      # 0x5166
movl $0x5, %edx
callq 0x21e0
leaq -0x1d8(%rbp), %r14
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x2270
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x3938(%rip), %rdi      # 0x6fd0
callq 0x21e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq -0x48(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0x36e0
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x21c0
xorl %eax, %eax
movq %rax, -0x38(%rbp)
movq %rax, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x2270
movq -0x58(%rbp), %rdi
leaq 0x1a6b(%rip), %rsi      # 0x516c
callq 0x21f0
movq %rax, %r14
movq -0x58(%rbp), %rdi
cmpq %rbx, %rdi
je 0x371e
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x21c0
testq %r14, %r14
je 0x37bb
movq %r15, -0x60(%rbp)
leaq -0x68(%rbp), %r13
leaq -0x58(%rbp), %r15
leaq -0x2a(%rbp), %rbx
leaq -0x29(%rbp), %r12
leaq -0x38(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x2230
cmpq $-0x1, %rax
je 0x37a6
movq -0x38(%rbp), %rdi
leaq 0x1a27(%rip), %rsi      # 0x5182
movq %r15, %rdx
leaq -0x50(%rbp), %rcx
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x2190
cmpl $0x4, %eax
jl 0x373b
cmpb $0x72, -0x2a(%rbp)
jne 0x373b
cmpb $0x77, -0x29(%rbp)
jne 0x373b
movq -0x60(%rbp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x379c
movups -0x58(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0x373b
movq %r15, %rdx
callq 0x388a
jmp 0x373b
movq %r14, %rdi
callq 0x21a0
movq -0x38(%rbp), %rdi
callq 0x2200
xorl %ebx, %ebx
jmp 0x3806
movq 0x380e(%rip), %rbx      # 0x6fd0
leaq 0x19a5(%rip), %rsi      # 0x516e
movl $0x13, %edx
movq %rbx, %rdi
callq 0x21e0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2180
movsbl %al, %esi
movq 0x37dc(%rip), %rdi      # 0x6fd0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x20e0
movq 0x37a3(%rip), %rsi      # 0x6fb0
leaq -0x1f0(%rbp), %rdi
callq 0x2110
leaq -0x170(%rbp), %rdi
callq 0x2060
movl %ebx, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x385f
jmp 0x385f
jmp 0x385f
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3862
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3862
jmp 0x385f
movq %rax, %rbx
movq 0x3747(%rip), %rsi      # 0x6fb0
leaq -0x1f0(%rbp), %rdi
callq 0x2110
leaq -0x170(%rbp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x22f0
nop