// File: /workspace/github_c_makefile_star2_O3/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 0x2b9c4(%rip), %rdi     # 0x5657d
leaq 0x29c7d(%rip), %rsi     # 0x5483d
callq 0x124f0
movq %rax, %rbx
leaq 0x810(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rax, %rdx
callq 0x12460
xorl %r15d, %r15d
testq %rax, %rax
je 0x2ae89
leaq 0x810(%rsp), %r14
leaq 0x2b995(%rip), %r15     # 0x5658d
leaq 0x2b994(%rip), %r12     # 0x56593
movq $0x0, 0x8(%rsp)
movq %r14, %rdi
movl $0x2d, %esi
callq 0x122b0
testq %rax, %rax
je 0x2ac72
movq %rax, %rbp
incq %rbp
movb $0x0, (%rax)
movq %rbp, %rdi
movl $0x20, %esi
callq 0x122b0
testq %rax, %rax
je 0x2ac72
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
movq %r13, %rdi
movq %r15, %rsi
callq 0x12940
testq %rax, %rax
jne 0x2ac72
movq %r13, %rdi
movq %r12, %rsi
callq 0x12940
testq %rax, %rax
jne 0x2ac72
movq %r13, %rdi
leaq 0x2b930(%rip), %rsi     # 0x56598
callq 0x12940
testq %rax, %rax
je 0x2ac8c
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x12460
testq %rax, %rax
jne 0x2ac08
jmp 0x2ad0d
movq %r13, %rdi
leaq 0x2b90b(%rip), %rsi     # 0x565a1
callq 0x12940
testq %rax, %rax
je 0x2ac72
movq %r13, %rdi
leaq 0x2b8fd(%rip), %rsi     # 0x565a7
callq 0x12940
testq %rax, %rax
je 0x2ac72
movq %r14, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x127f0
movq %rax, %r13
movq %rbp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x127f0
subq %r13, %rax
movq 0x8(%rsp), %rbp
movslq %ebp, %rbp
movq %r13, 0x410(%rsp,%rbp,8)
movq %rax, 0x10(%rsp,%rbp,8)
leaq 0x2b8b6(%rip), %rdi     # 0x565aa
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x122c0
incl %ebp
movq %rbp, 0x8(%rsp)
jmp 0x2ac72
movq 0x8(%rsp), %r12
testl %r12d, %r12d
jle 0x2ae86
movl %r12d, %r13d
xorl %r15d, %r15d
xorl %r14d, %r14d
movq 0x410(%rsp,%r15,8), %rsi
movq 0x10(%rsp,%r15,8), %rdx
movq %r14, %rdi
callq 0x2f7e4
movq %rax, %r14
incq %r15
cmpq %r15, %r13
jne 0x2ad24
testl %r12d, %r12d
jle 0x2ae81
xorl %r15d, %r15d
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x2f731
incq %r15
cmpq %r15, %r13
jne 0x2ad50
testl %r12d, %r12d
jle 0x2ae81
xorl %r15d, %r15d
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x2f74a
incq %r15
cmpq %r15, %r13
jne 0x2ad76
testl %r12d, %r12d
jle 0x2ae81
xorl %r15d, %r15d
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x2f74a
incq %r15
cmpq %r15, %r13
jne 0x2ad9c
testl %r12d, %r12d
jle 0x2ae81
xorl %r15d, %r15d
movq 0x410(%rsp,%r15,8), %rdi
movq 0x10(%rsp,%r15,8), %rsi
callq 0x2f731
incq %r15
cmpq %r15, %r13
jne 0x2adc2
testl %r12d, %r12d
jle 0x2ae81
xorl %r12d, %r12d
xorl %r15d, %r15d
movq 0x410(%rsp,%r12,8), %rsi
movq 0x10(%rsp,%r12,8), %rdx
movq %r15, %rdi
callq 0x2f7e4
movq %rax, %r15
incq %r12
cmpq %r12, %r13
jne 0x2adeb
cmpl $0x0, 0x8(%rsp)
jle 0x2ae8c
xorl %r12d, %r12d
movq 0x410(%rsp,%r12,8), %rdi
movq 0x10(%rsp,%r12,8), %rsi
callq 0x2f74a
incq %r12
cmpq %r12, %r13
jne 0x2ae15
cmpl $0x0, 0x8(%rsp)
jle 0x2ae8c
xorl %r12d, %r12d
movq 0x410(%rsp,%r12,8), %rdi
movq 0x10(%rsp,%r12,8), %rsi
callq 0x2f74a
incq %r12
cmpq %r12, %r13
jne 0x2ae39
cmpl $0x0, 0x8(%rsp)
jle 0x2ae8c
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x410(%rsp,%rbp,8), %rsi
movq 0x10(%rsp,%rbp,8), %rdx
movq %r12, %rdi
callq 0x2f7e4
movq %rax, %r12
incq %rbp
cmpq %rbp, %r13
jne 0x2ae5f
jmp 0x2ae8f
xorl %r15d, %r15d
jmp 0x2ae8c
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq %rbx, %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