// File: /workspace/github_c_makefile_star2_O2/erikdubbelboer[P]discnt/src/debug.c
// Function: memtest_test_linux_anonymous_maps
int memtest_test_linux_anonymous_maps(void) {
    FILE *fp = fopen("/proc/self/maps","r");
    char line[1024];
    size_t start_addr, end_addr, size;
    size_t start_vect[MEMTEST_MAX_REGIONS];
    size_t size_vect[MEMTEST_MAX_REGIONS];
    int regions = 0, j;
    uint64_t crc1 = 0, crc2 = 0, crc3 = 0;

    while(fgets(line,sizeof(line),fp) != NULL) {
        char *start, *end, *p = line;

        start = p;
        p = strchr(p,'-');
        if (!p) continue;
        *p++ = '\0';
        end = p;
        p = strchr(p,' ');
        if (!p) continue;
        *p++ = '\0';
        if (strstr(p,"stack") ||
            strstr(p,"vdso") ||
            strstr(p,"vsyscall")) continue;
        if (!strstr(p,"00:00")) continue;
        if (!strstr(p,"rw")) continue;

        start_addr = strtoul(start,NULL,16);
        end_addr = strtoul(end,NULL,16);
        size = end_addr-start_addr;

        start_vect[regions] = start_addr;
        size_vect[regions] = size;
        printf("Testing %lx %lu\n", (unsigned long) start_vect[regions],
                                    (unsigned long) size_vect[regions]);
        regions++;
    }

    /* Test all the regions as an unique sequential region.
     * 1) Take the CRC64 of the memory region. */
    for (j = 0; j < regions; j++) {
        crc1 = crc64(crc1,(void*)start_vect[j],size_vect[j]);
    }

    /* 2) Invert bits, swap adjacent words, swap again, invert bits.
     * This is the error amplification step. */
    for (j = 0; j < regions; j++)
        memtest_non_destructive_invert((void*)start_vect[j],size_vect[j]);
    for (j = 0; j < regions; j++)
        memtest_non_destructive_swap((void*)start_vect[j],size_vect[j]);
    for (j = 0; j < regions; j++)
        memtest_non_destructive_swap((void*)start_vect[j],size_vect[j]);
    for (j = 0; j < regions; j++)
        memtest_non_destructive_invert((void*)start_vect[j],size_vect[j]);

    /* 3) Take the CRC64 sum again. */
    for (j = 0; j < regions; j++)
        crc2 = crc64(crc2,(void*)start_vect[j],size_vect[j]);

    /* 4) Swap + Swap again */
    for (j = 0; j < regions; j++)
        memtest_non_destructive_swap((void*)start_vect[j],size_vect[j]);
    for (j = 0; j < regions; j++)
        memtest_non_destructive_swap((void*)start_vect[j],size_vect[j]);

    /* 5) Take the CRC64 sum again. */
    for (j = 0; j < regions; j++)
        crc3 = crc64(crc3,(void*)start_vect[j],size_vect[j]);

    /* NOTE: It is very important to close the file descriptor only now
     * because closing it before may result into unmapping of some memory
     * region that we are testing. */
    fclose(fp);

    /* If the two CRC are not the same, we trapped a memory error. */
    return crc1 != crc2 || crc2 != crc3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc18, %rsp            # imm = 0xC18
leaq 0x2b707(%rip), %rdi     # 0x4fd95
leaq 0x29e0c(%rip), %rsi     # 0x4e4a1
callq 0x124f0
movq %rax, 0x8(%rsp)
leaq 0x810(%rsp), %r14
pushq $0x2d
popq %rbp
pushq $0x20
popq %r15
xorl %ebx, %ebx
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x8(%rsp), %rdx
callq 0x12460
testq %rax, %rax
je 0x247b7
movq %r14, %rdi
movl %ebp, %esi
callq 0x122b0
testq %rax, %rax
je 0x246b0
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
movq %r13, %rdi
movl %r15d, %esi
callq 0x122b0
testq %rax, %rax
je 0x246b0
movq %rax, %r12
incq %r12
movb $0x0, (%rax)
movq %r12, %rdi
leaq 0x2b69f(%rip), %rsi     # 0x4fda5
callq 0x12940
testq %rax, %rax
jne 0x246b0
movq %r12, %rdi
leaq 0x2b691(%rip), %rsi     # 0x4fdab
callq 0x12940
testq %rax, %rax
jne 0x246b0
movq %r12, %rdi
leaq 0x2b682(%rip), %rsi     # 0x4fdb0
callq 0x12940
testq %rax, %rax
jne 0x246b0
movq %r12, %rdi
leaq 0x2b673(%rip), %rsi     # 0x4fdb9
callq 0x12940
testq %rax, %rax
je 0x246b0
movq %r12, %rdi
leaq 0x2b661(%rip), %rsi     # 0x4fdbf
callq 0x12940
testq %rax, %rax
je 0x246b0
movq %r14, %rdi
xorl %esi, %esi
pushq $0x10
popq %rdx
callq 0x127f0
movq %rax, %r12
movq %r13, %rdi
xorl %esi, %esi
pushq $0x10
popq %rdx
callq 0x127f0
subq %r12, %rax
movslq %ebx, %rbx
movq %r12, 0x410(%rsp,%rbx,8)
movq %rax, 0x10(%rsp,%rbx,8)
leaq 0x2b61f(%rip), %rdi     # 0x4fdc2
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x122c0
incl %ebx
jmp 0x246b0
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
xorl %r14d, %r14d
cmpq %r15, %rbx
je 0x247e5
movq 0x410(%rsp,%r15,8), %rsi
movq 0x10(%rsp,%r15,8), %rdx
movq %r14, %rdi
callq 0x289bc
movq %rax, %r14
incq %r15
jmp 0x247c3
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x24804
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x28913
incq %r15
jmp 0x247e8
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x24823
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x28928
incq %r15
jmp 0x24807
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x24842
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x28928
incq %r15
jmp 0x24826
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x24861
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x28913
incq %r15
jmp 0x24845
xorl %r12d, %r12d
xorl %r15d, %r15d
cmpq %r12, %rbx
je 0x24889
movq 0x410(%rsp,%r12,8), %rsi
movq 0x10(%rsp,%r12,8), %rdx
movq %r15, %rdi
callq 0x289bc
movq %rax, %r15
incq %r12
jmp 0x24867
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x248a8
movq 0x410(%rsp,%r12,8), %rdi
movq 0x10(%rsp,%r12,8), %rsi
callq 0x28928
incq %r12
jmp 0x2488c
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x248c7
movq 0x410(%rsp,%r12,8), %rdi
movq 0x10(%rsp,%r12,8), %rsi
callq 0x28928
incq %r12
jmp 0x248ab
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpq %r13, %rbx
je 0x248ef
movq 0x410(%rsp,%r13,8), %rsi
movq 0x10(%rsp,%r13,8), %rdx
movq %r12, %rdi
callq 0x289bc
movq %rax, %r12
incq %r13
jmp 0x248cd
movq 0x8(%rsp), %rdi
callq 0x12220
xorq %r15, %r14
xorq %r15, %r12
xorl %eax, %eax
orq %r14, %r12
setne %al
addq $0xc18, %rsp            # imm = 0xC18
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq