// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/debug.c
// Function: memtest_test_linux_anonymous_maps
int memtest_test_linux_anonymous_maps(void) {
    FILE *fp;
    char line[1024];
    char logbuf[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;

    int fd = openDirectLogFiledes();
    if (!fd) return 0;

    fp = fopen("/proc/self/maps","r");
    if (!fp) return 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;
        snprintf(logbuf,sizeof(logbuf),
            "*** Preparing to test memory region %lx (%lu bytes)\n",
                (unsigned long) start_vect[regions],
                (unsigned long) size_vect[regions]);
        if (write(fd,logbuf,strlen(logbuf)) == -1) { /* Nothing to do. */ }
        regions++;
    }

    int errors = 0;
    for (j = 0; j < regions; j++) {
        if (write(fd,".",1) == -1) { /* Nothing to do. */ }
        errors += memtest_preserving_test((void*)start_vect[j],size_vect[j],1);
        if (write(fd, errors ? "E" : "O",1) == -1) { /* Nothing to do. */ }
    }
    if (write(fd,"\n",1) == -1) { /* Nothing to do. */ }

    /* 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);
    closeDirectLogFiledes(fd);
    return errors;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
callq 0x58d4e
xorl %ebp, %ebp
testl %eax, %eax
je 0x59146
movl %eax, %ebx
leaq 0x5f0ec(%rip), %rdi     # 0xb8045
leaq 0x58735(%rip), %rsi     # 0xb1695
callq 0x26ae0
testq %rax, %rax
je 0x59146
movq %rax, %r14
leaq 0xc10(%rsp), %r15
pushq $0x2d
popq %rbp
movq $0x0, (%rsp)
movq %r15, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x26440
testq %rax, %rax
je 0x590bc
movq %r15, %rdi
movl %ebp, %esi
callq 0x267f0
testq %rax, %rax
je 0x58f84
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
movq %r13, %rdi
pushq $0x20
popq %rsi
callq 0x267f0
testq %rax, %rax
je 0x58f84
movq %rax, %r12
incq %r12
movb $0x0, (%rax)
movq %r12, %rdi
leaq 0x5f07d(%rip), %rsi     # 0xb8055
callq 0x266b0
testq %rax, %rax
jne 0x58f84
movq %r12, %rdi
leaq 0x5f06f(%rip), %rsi     # 0xb805b
callq 0x266b0
testq %rax, %rax
jne 0x58f84
movq %r12, %rdi
leaq 0x5f060(%rip), %rsi     # 0xb8060
callq 0x266b0
testq %rax, %rax
jne 0x58f84
movq %r12, %rdi
leaq 0x5f051(%rip), %rsi     # 0xb8069
callq 0x266b0
testq %rax, %rax
je 0x58f84
movq %r12, %rdi
leaq 0x5f03f(%rip), %rsi     # 0xb806f
callq 0x266b0
testq %rax, %rax
je 0x58f84
movq %r15, %rdi
xorl %esi, %esi
pushq $0x10
popq %rdx
callq 0x26c20
movq %rax, %r12
movq %r13, %rdi
xorl %esi, %esi
pushq $0x10
popq %rdx
callq 0x26c20
subq %r12, %rax
movq (%rsp), %r13
movslq %r13d, %r13
movq %r12, 0x410(%rsp,%r13,8)
movq %rax, 0x10(%rsp,%r13,8)
movl $0x400, %esi            # imm = 0x400
leaq 0x810(%rsp), %rdi
leaq 0x5efec(%rip), %rdx     # 0xb8072
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x26120
leaq 0x810(%rsp), %r12
movq %r12, %rdi
callq 0x26500
movl %ebx, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x26bb0
incl %r13d
movq %r13, (%rsp)
jmp 0x58f84
movq %r14, 0x8(%rsp)
xorl %r14d, %r14d
movq (%rsp), %r13
testl %r13d, %r13d
cmovlel %r14d, %r13d
pushq $0x1
popq %r12
leaq 0x647ab(%rip), %r15     # 0xbd885
xorl %ebp, %ebp
cmpq %r14, %r13
je 0x59124
movl %ebx, %edi
leaq 0x62931(%rip), %rsi     # 0xbba1b
movq %r12, %rdx
callq 0x26bb0
movq 0x410(%rsp,%r14,8), %rdi
movq 0x10(%rsp,%r14,8), %rsi
pushq $0x1
popq %rdx
callq 0x677f2
movq %r15, %rsi
addl %eax, %ebp
je 0x59115
leaq 0x6111c(%rip), %rsi     # 0xba231
movl %ebx, %edi
movq %r12, %rdx
callq 0x26bb0
incq %r14
jmp 0x590dc
leaq 0x57c8e(%rip), %rsi     # 0xb0db9
pushq $0x1
popq %rdx
movl %ebx, %edi
callq 0x26bb0
movq 0x8(%rsp), %rdi
callq 0x26a10
movl %ebx, %edi
callq 0x58d76
movl %ebp, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq