// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
leaq 0x9fc88(%rip), %rax     # 0x106858
movq 0x790(%rax), %rdi
cmpb $0x0, (%rdi)
je 0x66bf1
movl $0x441, %esi            # imm = 0x441
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x266a0
movl %eax, %ebx
jmp 0x66bf6
movl $0x1, %ebx
xorl %r15d, %r15d
testl %ebx, %ebx
je 0x66e3b
leaq 0x631a5(%rip), %rdi     # 0xc9dad
leaq 0x5bde6(%rip), %rsi     # 0xc29f5
callq 0x26af0
testq %rax, %rax
je 0x66e3b
movq %rax, %rbp
leaq 0xc10(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rax, %rdx
callq 0x26450
xorl %r15d, %r15d
movl $0x0, %ecx
movq %rcx, (%rsp)
testq %rax, %rax
je 0x66d94
leaq 0xc10(%rsp), %r14
movq $0x0, (%rsp)
movq %r14, %rdi
movl $0x2d, %esi
callq 0x26800
testq %rax, %rax
je 0x66ccc
movq %rax, %r13
incq %r13
movb $0x0, (%rax)
movq %r13, %rdi
movl $0x20, %esi
callq 0x26800
testq %rax, %rax
je 0x66ccc
movq %rax, %r12
incq %r12
movb $0x0, (%rax)
movq %r12, %rdi
leaq 0x63123(%rip), %rsi     # 0xc9dbd
callq 0x266c0
testq %rax, %rax
jne 0x66ccc
movq %r12, %rdi
leaq 0x63115(%rip), %rsi     # 0xc9dc3
callq 0x266c0
testq %rax, %rax
jne 0x66ccc
movq %r12, %rdi
leaq 0x63106(%rip), %rsi     # 0xc9dc8
callq 0x266c0
testq %rax, %rax
je 0x66cea
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbp, %rdx
callq 0x26450
testq %rax, %rax
jne 0x66c5a
jmp 0x66d94
movq %r12, %rdi
leaq 0x630dd(%rip), %rsi     # 0xc9dd1
callq 0x266c0
testq %rax, %rax
je 0x66ccc
movq %r12, %rdi
leaq 0x630cf(%rip), %rsi     # 0xc9dd7
callq 0x266c0
testq %rax, %rax
je 0x66ccc
movq %r14, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x26c30
movq %rax, %r12
movq %r13, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x26c30
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 0x6307c(%rip), %rdx     # 0xc9dda
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x26120
leaq 0x810(%rsp), %r12
movq %r12, %rdi
callq 0x26510
movl %ebx, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x26bc0
incl %r13d
movq %r13, (%rsp)
jmp 0x66ccc
movq %rbp, 0x8(%rsp)
movq (%rsp), %rax
testl %eax, %eax
jle 0x66e04
movl %eax, %r12d
xorl %r13d, %r13d
leaq 0x68d8b(%rip), %r14     # 0xcfb39
xorl %r15d, %r15d
movl %r15d, %ebp
movl $0x1, %edx
movl %ebx, %edi
leaq 0x66d91(%rip), %rsi     # 0xcdb53
callq 0x26bc0
movq 0x410(%rsp,%r13,8), %rdi
movq 0x10(%rsp,%r13,8), %rsi
movl $0x1, %edx
callq 0x77050
movl %eax, %r15d
movq %r14, %rsi
addl %ebp, %r15d
je 0x66df0
leaq 0x653d1(%rip), %rsi     # 0xcc1c1
movl $0x1, %edx
movl %ebx, %edi
callq 0x26bc0
incq %r13
cmpq %r13, %r12
jne 0x66db1
leaq 0x5b04c(%rip), %rsi     # 0xc1e57
movl $0x1, %edx
movl %ebx, %edi
callq 0x26bc0
movq 0x8(%rsp), %rdi
callq 0x26a20
leaq 0x9fa30(%rip), %rax     # 0x106858
movq 0x790(%rax), %rax
cmpb $0x0, (%rax)
je 0x66e3b
movl %ebx, %edi
callq 0x26180
movl %r15d, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq