// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/memtest.c
// Function: memtest_preserving_test
int memtest_preserving_test(unsigned long *m, size_t bytes, int passes) {
    unsigned long backup[MEMTEST_BACKUP_WORDS];
    unsigned long *p = m;
    unsigned long *end = (unsigned long*) (((unsigned char*)m)+(bytes-MEMTEST_DECACHE_SIZE));
    size_t left = bytes;
    int errors = 0;

    if (bytes & 4095) return 0; /* Can't test across 4k page boundaries. */
    if (bytes < 4096*2) return 0; /* Can't test a single page. */

    while(left) {
        /* If we have to test a single final page, go back a single page
         * so that we can test two pages, since the code can't test a single
         * page but at least two. */
        if (left == 4096) {
            left += 4096;
            p -= 4096/sizeof(unsigned long);
        }

        int pass = 0;
        size_t len = (left > sizeof(backup)) ? sizeof(backup) : left;

        /* Always test an even number of pages. */
        if (len/4096 % 2) len -= 4096;

        memcpy(backup,p,len); /* Backup. */
        while(pass != passes) {
            pass++;
            errors += memtest_addressing(p,len,0);
            memtest_fill_random(p,len,0);
            if (bytes >= MEMTEST_DECACHE_SIZE) {
                memtest_compare_times(m,MEMTEST_DECACHE_SIZE,pass,1,0);
                memtest_compare_times(end,MEMTEST_DECACHE_SIZE,pass,1,0);
            }
            errors += memtest_compare_times(p,len,pass,4,0);
            memtest_fill_value(p,len,0,(unsigned long)-1,'S',0);
            if (bytes >= MEMTEST_DECACHE_SIZE) {
                memtest_compare_times(m,MEMTEST_DECACHE_SIZE,pass,1,0);
                memtest_compare_times(end,MEMTEST_DECACHE_SIZE,pass,1,0);
            }
            errors += memtest_compare_times(p,len,pass,4,0);
            memtest_fill_value(p,len,ULONG_ONEZERO,ULONG_ZEROONE,'C',0);
            if (bytes >= MEMTEST_DECACHE_SIZE) {
                memtest_compare_times(m,MEMTEST_DECACHE_SIZE,pass,1,0);
                memtest_compare_times(end,MEMTEST_DECACHE_SIZE,pass,1,0);
            }
            errors += memtest_compare_times(p,len,pass,4,0);
        }
        memcpy(p,backup,len); /* Restore. */
        left -= len;
        p += len/sizeof(unsigned long);
    }
    return errors;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x100018, %rsp         # imm = 0x100018
movl %edx, (%rsp)
testl $0xfff, %esi            # imm = 0xFFF
setne %al
cmpq $0x2000, %rsi           # imm = 0x2000
setb %cl
xorl %r13d, %r13d
orb %al, %cl
je 0x77093
movl %r13d, %eax
addq $0x100018, %rsp         # imm = 0x100018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r14
xorl %r13d, %r13d
leaq 0x10(%rsp), %rbx
cmpq $0x1000, %rsi           # imm = 0x1000
je 0x770ae
testq %rsi, %rsi
jne 0x770ba
jmp 0x7707e
addq $-0x1000, %r14          # imm = 0xF000
movl $0x2000, %esi           # imm = 0x2000
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %rsi
movq %rsi, 0x8(%rsp)
cmovbq %rsi, %rax
leaq -0x1000(%rax), %r12
btl $0xc, %eax
cmovaeq %rax, %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x26c60
cmpl $0x0, (%rsp)
je 0x771ca
xorl %ebx, %ebx
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x769fd
movl %eax, %r15d
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x76ae1
incl %ebx
movl %ebx, 0x4(%rsp)
movl $0x4, %ebp
xorl %ebx, %ebx
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x76d2a
addl %eax, %ebx
decl %ebp
jne 0x7711e
addl %r13d, %r15d
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq $-0x1, %rcx
movl $0x53, %r8d
xorl %r9d, %r9d
callq 0x76c06
movl $0x4, %ebp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x76d2a
addl %eax, %r13d
decl %ebp
jne 0x77159
addl %ebx, %r15d
xorl %ebx, %ebx
movq %r14, %rdi
movq %r12, %rsi
movabsq $-0x5555555555555556, %rdx # imm = 0xAAAAAAAAAAAAAAAA
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
movl $0x43, %r8d
xorl %r9d, %r9d
callq 0x76c06
movl $0x4, %ebp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x76d2a
addl %eax, %ebx
decl %ebp
jne 0x7719f
addl %r13d, %r15d
addl %ebx, %r15d
movl %r15d, %r13d
movl 0x4(%rsp), %ebx
cmpl (%rsp), %ebx
jne 0x770f4
jmp 0x771cd
movl %r13d, %r15d
movq %r14, %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rdx
callq 0x26c60
movq 0x8(%rsp), %rsi
subq %r12, %rsi
andq $-0x8, %r12
addq %r12, %r14
movl %r15d, %r13d
jmp 0x7709e