// File: /workspace/github_c_makefile_star2_O1/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 $0xc08, %rsp            # imm = 0xC08
leaq 0x2b415(%rip), %rdi     # 0x56595
leaq 0x2966e(%rip), %rsi     # 0x547f5
callq 0x12500
movq %rax, %rbx
leaq 0x800(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rax, %rdx
callq 0x12470
testq %rax, %rax
je 0x2b2bf
leaq 0x800(%rsp), %r14
leaq 0x2b3e9(%rip), %r15     # 0x565a5
xorl %r12d, %r12d
movq %r14, %rdi
movl $0x2d, %esi
callq 0x122b0
testq %rax, %rax
je 0x2b22d
movq %rax, %rbp
incq %rbp
movb $0x0, (%rax)
movq %rbp, %rdi
movl $0x20, %esi
callq 0x122b0
testq %rax, %rax
je 0x2b22d
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
movq %r13, %rdi
movq %r15, %rsi
callq 0x12950
testq %rax, %rax
jne 0x2b22d
movq %r13, %rdi
leaq 0x2b39c(%rip), %rsi     # 0x565ab
callq 0x12950
testq %rax, %rax
jne 0x2b22d
movq %r13, %rdi
leaq 0x2b38d(%rip), %rsi     # 0x565b0
callq 0x12950
testq %rax, %rax
je 0x2b248
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x12470
testq %rax, %rax
jne 0x2b1bf
jmp 0x2b2c2
movq %r13, %rdi
leaq 0x2b367(%rip), %rsi     # 0x565b9
callq 0x12950
testq %rax, %rax
je 0x2b22d
movq %r13, %rdi
leaq 0x2b359(%rip), %rsi     # 0x565bf
callq 0x12950
testq %rax, %rax
je 0x2b22d
movq %r14, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x12800
movq %rax, %r13
movq %rbp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x12800
subq %r13, %rax
movslq %r12d, %r12
movq %r13, 0x400(%rsp,%r12,8)
movq %rax, (%rsp,%r12,8)
leaq 0x2b318(%rip), %rdi     # 0x565c2
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x122c0
incl %r12d
jmp 0x2b22d
xorl %r12d, %r12d
movl %r12d, %r13d
testl %r12d, %r12d
jle 0x2b2f1
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x400(%rsp,%r15,8), %rsi
movq (%rsp,%r15,8), %rdx
movq %r14, %rdi
callq 0x2fdb0
movq %rax, %r14
incq %r15
cmpq %r15, %r13
jne 0x2b2d0
jmp 0x2b2f4
xorl %r14d, %r14d
testl %r12d, %r12d
jle 0x2b315
xorl %r15d, %r15d
movq 0x400(%rsp,%r15,8), %rdi
movq (%rsp,%r15,8), %rsi
callq 0x2fcfd
incq %r15
cmpq %r15, %r13
jne 0x2b2fc
testl %r12d, %r12d
jle 0x2b336
xorl %r15d, %r15d
movq 0x400(%rsp,%r15,8), %rdi
movq (%rsp,%r15,8), %rsi
callq 0x2fd16
incq %r15
cmpq %r15, %r13
jne 0x2b31d
testl %r12d, %r12d
jle 0x2b357
xorl %r15d, %r15d
movq 0x400(%rsp,%r15,8), %rdi
movq (%rsp,%r15,8), %rsi
callq 0x2fd16
incq %r15
cmpq %r15, %r13
jne 0x2b33e
testl %r12d, %r12d
jle 0x2b378
xorl %r15d, %r15d
movq 0x400(%rsp,%r15,8), %rdi
movq (%rsp,%r15,8), %rsi
callq 0x2fcfd
incq %r15
cmpq %r15, %r13
jne 0x2b35f
testl %r12d, %r12d
jle 0x2b3a3
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x400(%rsp,%rbp,8), %rsi
movq (%rsp,%rbp,8), %rdx
movq %r15, %rdi
callq 0x2fdb0
movq %rax, %r15
incq %rbp
cmpq %rbp, %r13
jne 0x2b382
jmp 0x2b3a6
xorl %r15d, %r15d
testl %r12d, %r12d
jle 0x2b3c6
xorl %ebp, %ebp
movq 0x400(%rsp,%rbp,8), %rdi
movq (%rsp,%rbp,8), %rsi
callq 0x2fd16
incq %rbp
cmpq %rbp, %r13
jne 0x2b3ad
testl %r12d, %r12d
jle 0x2b3e6
xorl %ebp, %ebp
movq 0x400(%rsp,%rbp,8), %rdi
movq (%rsp,%rbp,8), %rsi
callq 0x2fd16
incq %rbp
cmpq %rbp, %r13
jne 0x2b3cd
testl %r12d, %r12d
jle 0x2b411
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x400(%rsp,%rbp,8), %rsi
movq (%rsp,%rbp,8), %rdx
movq %r12, %rdi
callq 0x2fdb0
movq %rax, %r12
incq %rbp
cmpq %rbp, %r13
jne 0x2b3f0
jmp 0x2b414
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x12220
xorq %r15, %r14
xorq %r15, %r12
xorl %eax, %eax
orq %r14, %r12
setne %al
addq $0xc08, %rsp            # imm = 0xC08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq