// File: /workspace/github_cpp_makefile_star2_O2/illmat[P]MemCrawl/main.cpp
// Function: main
int main(int argc, char* argv[])
{
    pid_t pid;
    int input = 0;
    bool isFirstRun = true;
    std::string commando;
    std::vector<scanRegion> regions;
    std::vector<scanResult> results;

    if(argc < 2)
    {
        printError("usage ./MemCrawl <pid>");
        return 1;
    }

    if ((pid = atol(argv[1])) == 0)
    {
        printError("usage ./MemCrawl <pid>");
        return 1;
    }

    // get read/writeable scan regions
    if (getRegions(regions, pid) != 0)
    {
        printError("could not get regions");
        return 1;
    }

    std::cout << "Enter Command (try: help)" << std::endl;
    std::cout << results.size() << "> ";
    std::getline (std::cin, commando);

    while (commando != "quit" && commando != "q")
    {

        try
        {
            input = string2int(commando);
            if (isFirstRun)
            {
                isFirstRun = false;
                if (scanIntInit(regions, results, pid, input) != 0)
                {
                    printError("could not scan memory");
                    return 1;
                }
            }
            else
            {
                if (scanIntResults(results, pid, input) != 0)
                {
                    std::cout << "could not scan memory" << std::endl;
                    return 1;
                }
            }

        }
        catch (int e)
        {
            if (e == 1)
            {
                if (commando == "help")
                {
                    printHelp();
                }

                if (commando == "list")
                {
                    printResults(results);
                }

                if (commando == "update")
                {
                    if (updateIntResults(results, pid) != 0)
                    {
                        printError("could not scan memory");
                        return 1;
                    }
                }

                if (commando == "ulist")
                {
                    if (updateIntResults(results, pid) != 0)
                    {
                        printError("could not scan memory");
                        return 1;
                    }
                    printResults(results);
                }

                if (commando == "info")
                {
                    std::cout << std::endl << "scan regions: " << std::endl;
                    int adresses = 0;
                    for(std::vector<scanRegion>::iterator it = regions.begin(); it != regions.end(); ++it)
                    {
                        scanRegion sr = (scanRegion) *it;
                        std::cout << std::hex << sr.startRegion << " - " << sr.endRegion << std::dec <<std::endl;
                        adresses += sr.endRegion - sr.startRegion;
                    }
                    std::cout << std::endl << adresses << " adresses" << std::endl;

                }

                if (commando == "reset")
                {
                    regions.clear();
                    results.clear();
                    isFirstRun = true;
                    // get read/writeable scan regions
                    if (getRegions(regions, pid) != 0)
                    {
                        printError("could not get regions");
                        return 1;
                    }

                }

                if (commando.substr(0, 3) == "pid")
                {
                    if (commando.length() < 5)
                    {
                        std::cout << "correct usage: pid <pid>" << std::endl;
                    }
                    else
                    {
                        int val = 0;
                        std::stringstream ss(commando.substr(4, commando.length()));
                        if ((ss >> val).fail())
                        {
                            printError("wrong parameter for pid command");
                        }
                        else
                        {
                            pid = val;
                            // reset
                            regions.clear();
                            results.clear();
                            isFirstRun = true;
                            // get read/writeable scan regions
                            if (getRegions(regions, pid) != 0)
                            {
                                printError("could not get regions");
                                return 1;
                            }
                        }
                    }
                }

                if (commando.substr(0, 3) == "set")
                {
                    if (commando.length() < 5)
                    {
                        std::cout << "correct usage: set 5" << std::endl;
                    }
                    else
                    {
                        int val = 0;
                        std::stringstream ss(commando.substr(4, commando.length()));
                        if ((ss >> val).fail())
                        {
                            printError("wrong parameter for set command");
                        }
                        else
                        {
                            if (setInt(results, pid, val) != 0)
                            {
                                std::cout << "could not set value" << std::endl;
                                return 1;
                            }
                        }
                    }
                }
            }
            else
            {
                printError("unknown");
            }
        }
        std::cout << results.size() << "> ";
        std::getline (std::cin, commando);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andq $0x0, -0x70(%rbp)
xorps %xmm0, %xmm0
andq $0x0, -0x40(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x50(%rbp)
pushq $0x1
popq %r15
cmpl $0x1, %edi
jg 0x25a0
leaq 0x1a8c(%rip), %rsi      # 0x4004
leaq -0x238(%rbp), %rdi
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x238(%rbp), %rdi
callq 0x39c2
leaq -0x238(%rbp), %rdi
jmp 0x261f
movq 0x8(%rsi), %rdi
callq 0x2240
movq %rax, %rbx
testl %ebx, %ebx
je 0x25f2
leaq -0x80(%rbp), %rdi
movl %ebx, %esi
callq 0x3268
testl %eax, %eax
je 0x2657
leaq 0x1a51(%rip), %rsi      # 0x401b
leaq -0x1f8(%rbp), %rdi
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x1f8(%rbp), %rdi
callq 0x39c2
leaq -0x1f8(%rbp), %rdi
jmp 0x261f
leaq 0x1a0b(%rip), %rsi      # 0x4004
leaq -0x218(%rbp), %rdi
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x218(%rbp), %rdi
callq 0x39c2
leaq -0x218(%rbp), %rdi
callq 0x20b0
leaq -0x50(%rbp), %rdi
callq 0x30a2
leaq -0x80(%rbp), %rdi
callq 0x3064
leaq -0xc8(%rbp), %rdi
callq 0x20b0
movl %r15d, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4972(%rip), %rdi      # 0x6fd0
leaq 0x19cc(%rip), %rsi      # 0x4031
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x4, %rsi
movq 0x494b(%rip), %rdi      # 0x6fd0
callq 0x2110
leaq 0x19ba(%rip), %rsi      # 0x404b
movq %rax, %rdi
callq 0x21d0
movq 0x4940(%rip), %rdi      # 0x6fe0
leaq -0xc8(%rbp), %rsi
callq 0x2040
movq $0x0, -0x58(%rbp)
movb $0x1, %r14b
leaq -0xc8(%rbp), %r12
leaq -0x3f8(%rbp), %r13
movq %r12, %rdi
leaq 0x197f(%rip), %rsi      # 0x404e
callq 0x2f89
xorl %r15d, %r15d
testb %al, %al
je 0x2624
movq %r12, %rdi
leaq 0x196a(%rip), %rsi      # 0x4053
callq 0x2f89
testb %al, %al
je 0x2624
movq %r12, %rdi
callq 0x3558
movl %eax, %r15d
testb $0x1, %r14b
je 0x2761
xorl %r14d, %r14d
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2f96
movq %r13, %rdi
leaq -0x50(%rbp), %rsi
movl %ebx, %edx
movl %r15d, %ecx
callq 0x3adc
movl %eax, %r15d
movq %r13, %rdi
callq 0x3064
testl %r15d, %r15d
je 0x279c
leaq -0x258(%rbp), %r14
movq %r14, %rdi
leaq 0x190d(%rip), %rsi      # 0x4055
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
movq %r14, %rdi
callq 0x39c2
jmp 0x2e05
xorl %r14d, %r14d
leaq -0x50(%rbp), %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x3ba6
testl %eax, %eax
je 0x279c
xorl %r14d, %r14d
movq 0x4850(%rip), %rdi      # 0x6fd0
leaq 0x18ce(%rip), %rsi      # 0x4055
callq 0x21d0
xorl %r14d, %r14d
movq %rax, %rdi
callq 0x20d0
jmp 0x2e11
xorl %r14d, %r14d
movq -0x48(%rbp), %rsi
subq -0x50(%rbp), %rsi
sarq $0x4, %rsi
movq 0x481e(%rip), %rdi      # 0x6fd0
callq 0x2110
movq %rax, %rdi
leaq 0x188a(%rip), %rsi      # 0x404b
callq 0x21d0
movq 0x4813(%rip), %rdi      # 0x6fe0
movq %r12, %rsi
callq 0x2040
jmp 0x26c5
movq %rdx, %r15
movq %rax, -0x30(%rbp)
jmp 0x2803
movq %rdx, %r15
movq %rax, -0x30(%rbp)
movq %r13, %rdi
callq 0x3064
jmp 0x2803
movq %rdx, %r15
movq %rax, -0x30(%rbp)
movq %r14, %rdi
callq 0x20b0
xorl %r14d, %r14d
jmp 0x280f
movq %rdx, %r15
movq %rax, -0x30(%rbp)
cmpl $0x1, %r15d
jne 0x2f27
movq -0x30(%rbp), %rdi
callq 0x2090
cmpl $0x1, (%rax)
jne 0x28d2
movq %r12, %rdi
leaq 0x1836(%rip), %rsi      # 0x406b
callq 0x2fed
testb %al, %al
je 0x2843
callq 0x39f7
movq %r12, %rdi
leaq 0x182b(%rip), %rsi      # 0x4078
callq 0x2fed
testb %al, %al
je 0x287e
leaq -0xf8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2ffe
leaq -0xf8(%rbp), %rdi
callq 0x38c0
leaq -0xf8(%rbp), %rdi
callq 0x30a2
movq %r12, %rdi
leaq 0x17e8(%rip), %rsi      # 0x4070
callq 0x2fed
testb %al, %al
je 0x290e
leaq -0x50(%rbp), %rdi
movl %ebx, %esi
callq 0x3c8c
testl %eax, %eax
je 0x290e
leaq -0x1d8(%rbp), %rdi
leaq 0x17a7(%rip), %rsi      # 0x4055
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x1d8(%rbp), %rdi
callq 0x39c2
leaq -0x1d8(%rbp), %rdi
jmp 0x295d
leaq -0x118(%rbp), %rdi
leaq 0x1847(%rip), %rsi      # 0x4127
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x118(%rbp), %rdi
callq 0x39c2
leaq -0x118(%rbp), %rdi
callq 0x20b0
movb $0x1, %al
movl %eax, -0x30(%rbp)
jmp 0x2b14
movq %r12, %rdi
leaq 0x175f(%rip), %rsi      # 0x4077
callq 0x2fed
testb %al, %al
je 0x298f
leaq -0x50(%rbp), %rdi
movl %ebx, %esi
callq 0x3c8c
testl %eax, %eax
je 0x2967
leaq -0x1b8(%rbp), %rdi
leaq 0x1717(%rip), %rsi      # 0x4055
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x1b8(%rbp), %rdi
callq 0x39c2
leaq -0x1b8(%rbp), %rdi
callq 0x20b0
jmp 0x2b06
leaq -0xe0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2ffe
leaq -0xe0(%rbp), %rdi
callq 0x38c0
leaq -0xe0(%rbp), %rdi
callq 0x30a2
movq %r12, %rdi
leaq 0x16e4(%rip), %rsi      # 0x407d
callq 0x2fed
testb %al, %al
je 0x2a8f
movq 0x4623(%rip), %rdi      # 0x6fd0
callq 0x20d0
movq %rax, %rdi
leaq 0x16c6(%rip), %rsi      # 0x4082
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
movl $0x0, -0x5c(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x78(%rbp), %rax
je 0x2a61
movq -0x30(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %r15
movq 0x45dc(%rip), %rdi      # 0x6fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl 0x18(%rdi,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rdi,%rax)
movq %rsi, -0xa8(%rbp)
callq 0x2110
movq %rax, %rdi
leaq 0x1672(%rip), %rsi      # 0x4091
callq 0x21d0
movq %rax, %rdi
movq %r15, %rsi
callq 0x2110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
callq 0x20d0
subl -0xa8(%rbp), %r15d
addl %r15d, -0x5c(%rbp)
addq $0x10, -0x30(%rbp)
jmp 0x29d8
movq 0x4568(%rip), %rdi      # 0x6fd0
callq 0x20d0
movq %rax, %rdi
movl -0x5c(%rbp), %esi
callq 0x22f0
movq %rax, %rdi
leaq 0x1613(%rip), %rsi      # 0x4095
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
movq %r12, %rdi
leaq 0x1606(%rip), %rsi      # 0x409f
callq 0x2fed
testb %al, %al
je 0x2b32
movq -0x80(%rbp), %rax
cmpq %rax, -0x78(%rbp)
je 0x2ab4
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x2ac2
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
movl %ebx, %esi
callq 0x3268
testl %eax, %eax
je 0x2b2f
leaq -0x198(%rbp), %rdi
leaq 0x153c(%rip), %rsi      # 0x401b
leaq -0x3e0(%rbp), %rdx
callq 0x2f4e
leaq -0x198(%rbp), %rdi
callq 0x39c2
leaq -0x198(%rbp), %rdi
callq 0x20b0
movb $0x1, %r14b
movl $0x0, -0x30(%rbp)
pushq $0x1
popq %rax
movq %rax, -0x58(%rbp)
callq 0x22c0
movq -0x58(%rbp), %rax
movl %eax, %r15d
cmpb $0x0, -0x30(%rbp)
jne 0x279f
jmp 0x2624
movb $0x1, %r14b
leaq -0x3e0(%rbp), %rdi
movq %r12, %rsi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x2210
leaq -0x3e0(%rbp), %rdi
leaq 0x180f(%rip), %rsi      # 0x4363
callq 0x2fed
movl %eax, %r15d
leaq -0x3e0(%rbp), %rdi
callq 0x20b0
testb %r15b, %r15b
je 0x2cad
movq -0xc0(%rbp), %rcx
cmpq $0x4, %rcx
ja 0x2b9e
movq 0x444b(%rip), %rdi      # 0x6fd0
leaq 0x1519(%rip), %rsi      # 0x40a5
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
jmp 0x2cad
andl $0x0, -0x34(%rbp)
leaq -0xa0(%rbp), %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
callq 0x2210
leaq -0x3e0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x22a0
leaq -0xa0(%rbp), %rdi
callq 0x20b0
leaq -0x3e0(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x2c2b
leaq -0x178(%rbp), %rdi
leaq 0x14bc(%rip), %rsi      # 0x40be
leaq -0xa0(%rbp), %rdx
callq 0x2f4e
leaq -0x178(%rbp), %rdi
callq 0x39c2
leaq -0x178(%rbp), %rdi
callq 0x20b0
movb $0x1, %r15b
jmp 0x2c98
movq -0x80(%rbp), %rax
cmpq %rax, -0x78(%rbp)
je 0x2c39
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rax
cmpq %rax, -0x48(%rbp)
je 0x2c47
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %ebx
leaq -0x80(%rbp), %rdi
movl %ebx, %esi
callq 0x3268
movb $0x1, %r14b
testl %eax, %eax
je 0x2c26
leaq -0x158(%rbp), %rdi
leaq 0x13b1(%rip), %rsi      # 0x401b
leaq -0xa0(%rbp), %rdx
callq 0x2f4e
leaq -0x158(%rbp), %rdi
callq 0x39c2
leaq -0x158(%rbp), %rdi
callq 0x20b0
xorl %r15d, %r15d
pushq $0x1
popq %rax
movq %rax, -0x58(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x2140
testb %r15b, %r15b
je 0x2dad
leaq -0x3e0(%rbp), %rdi
movq %r12, %rsi
xorl %edx, %edx
pushq $0x3
popq %rcx
callq 0x2210
leaq -0x3e0(%rbp), %rdi
leaq 0x13d2(%rip), %rsi      # 0x40a1
callq 0x2fed
movl %eax, %r15d
leaq -0x3e0(%rbp), %rdi
callq 0x20b0
movb $0x1, %al
movl %eax, -0x30(%rbp)
testb %r15b, %r15b
je 0x2b14
movq -0xc0(%rbp), %rcx
cmpq $0x4, %rcx
ja 0x2d1e
movq 0x42cb(%rip), %rdi      # 0x6fd0
leaq 0x13d2(%rip), %rsi      # 0x40de
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
jmp 0x2b14
andl $0x0, -0x34(%rbp)
leaq -0xa0(%rbp), %rdi
movq %r12, %rsi
pushq $0x4
popq %rdx
callq 0x2210
leaq -0x3e0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
pushq $0x18
popq %rdx
callq 0x22a0
leaq -0xa0(%rbp), %rdi
callq 0x20b0
leaq -0x3e0(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x2db9
leaq -0x138(%rbp), %rdi
leaq 0x1371(%rip), %rsi      # 0x40f3
leaq -0xa0(%rbp), %rdx
callq 0x2f4e
leaq -0x138(%rbp), %rdi
callq 0x39c2
leaq -0x138(%rbp), %rdi
callq 0x20b0
movb $0x1, %al
movl %eax, -0x30(%rbp)
jmp 0x2df4
movl $0x0, -0x30(%rbp)
jmp 0x2b14
movl -0x34(%rbp), %edx
leaq -0x50(%rbp), %rdi
movl %ebx, %esi
callq 0x3d17
testl %eax, %eax
je 0x2da6
movq 0x41fe(%rip), %rdi      # 0x6fd0
leaq 0x133a(%rip), %rsi      # 0x4113
callq 0x21d0
movq %rax, %rdi
callq 0x20d0
movl $0x0, -0x30(%rbp)
pushq $0x1
popq %rax
movq %rax, -0x58(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x2140
jmp 0x2b14
leaq -0x258(%rbp), %rdi
callq 0x20b0
pushq $0x1
popq %r15
jmp 0x2624
jmp 0x2e5f
movq %rax, -0x30(%rbp)
leaq -0x138(%rbp), %rdi
jmp 0x2e58
jmp 0x2e5f
jmp 0x2e71
jmp 0x2ed2
jmp 0x2ed2
jmp 0x2ed2
movq %rax, -0x30(%rbp)
leaq -0x158(%rbp), %rdi
jmp 0x2e58
jmp 0x2e5f
jmp 0x2e5f
movq %rax, -0x30(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x20b0
jmp 0x2e63
movq %rax, -0x30(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x2140
jmp 0x2ed6
movq %rax, -0x30(%rbp)
leaq -0xa0(%rbp), %rdi
jmp 0x2ecb
jmp 0x2ed2
jmp 0x2ed2
movq %rax, -0x30(%rbp)
leaq -0x198(%rbp), %rdi
jmp 0x2ecb
jmp 0x2ed2
jmp 0x2ed2
jmp 0x2ed2
movq %rax, -0x30(%rbp)
leaq -0xe0(%rbp), %rdi
jmp 0x2ee8
movq %rax, -0x30(%rbp)
leaq -0x1b8(%rbp), %rdi
jmp 0x2ecb
jmp 0x2ed2
movq %rax, -0x30(%rbp)
leaq -0x118(%rbp), %rdi
jmp 0x2ecb
jmp 0x2ed2
movq %rax, -0x30(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x20b0
jmp 0x2ed6
movq %rax, -0x30(%rbp)
callq 0x22c0
jmp 0x2f27
movq %rax, -0x30(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x30a2
jmp 0x2ed6
movq %rax, -0x30(%rbp)
leaq -0x218(%rbp), %rdi
jmp 0x2f18
jmp 0x2f23
movq %rax, -0x30(%rbp)
leaq -0x1f8(%rbp), %rdi
jmp 0x2f18
jmp 0x2f23
movq %rax, -0x30(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x20b0
jmp 0x2f27
jmp 0x2f23
jmp 0x2f23
movq %rax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x30a2
leaq -0x80(%rbp), %rdi
callq 0x3064
leaq -0xc8(%rbp), %rdi
callq 0x20b0
movq -0x30(%rbp), %rdi
callq 0x2300