// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 $0x100038, %rsp         # imm = 0x100038
movq %rdx, (%rsp)
testw $0xfff, %si             # imm = 0xFFF
setne %al
cmpq $0x2000, %rsi           # imm = 0x2000
setb %cl
xorl %r15d, %r15d
orb %al, %cl
je 0x67835
movl %r15d, %eax
addq $0x100038, %rsp         # imm = 0x100038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq (%rdi,%rsi), %rax
addq $-0x2000, %rax          # imm = 0xE000
movq %rax, 0x18(%rsp)
movq (%rsp), %rax
negl %eax
movq %rax, (%rsp)
xorl %r15d, %r15d
leaq 0x30(%rsp), %r13
movq %rdi, 0x20(%rsp)
movq %rdi, %r14
cmpq $0x1000, %rsi           # imm = 0x1000
je 0x6786e
testq %rsi, %rsi
jne 0x6787a
jmp 0x67820
addq $-0x1000, %r14          # imm = 0xF000
movl $0x2000, %esi           # imm = 0x2000
movl $0x100000, %eax         # imm = 0x100000
cmpq %rax, %rsi
movq %rsi, 0x28(%rsp)
cmovbq %rsi, %rax
leaq -0x1000(%rax), %rdx
btl $0xc, %eax
cmovaeq %rax, %rdx
movq %r13, %rdi
movq %r14, %rsi
movq %rdx, 0x10(%rsp)
callq 0x26c50
pushq $0x1
popq %rax
movl %eax, %r13d
movq (%rsp), %rax
addl %r13d, %eax
movq %r14, %rdi
cmpl $0x1, %eax
je 0x67a10
movq 0x10(%rsp), %r12
movq %r12, %rsi
xorl %edx, %edx
callq 0x67228
addl %r15d, %eax
movl %eax, 0xc(%rsp)
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x672f6
movl $0x2000, %esi           # imm = 0x2000
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl %r13d, %edx
pushq $0x1
popq %rbp
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x675d6
movl $0x2000, %esi           # imm = 0x2000
movq 0x18(%rsp), %r15
movq %r15, %rdi
movl %r13d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x675d6
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %edx
pushq $0x4
popq %rcx
xorl %r8d, %r8d
callq 0x675d6
movl %eax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
pushq $-0x1
popq %rcx
pushq $0x53
popq %r8
xorl %r9d, %r9d
callq 0x6740c
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdi
movl %r13d, %edx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x675d6
movl $0x2000, %esi           # imm = 0x2000
movq %r15, %rdi
movl %r13d, %edx
movl %ebp, %ecx
movl %ebp, %ebx
xorl %r8d, %r8d
callq 0x675d6
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %edx
pushq $0x4
popq %r15
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x675d6
movl %eax, %ebp
addl 0x8(%rsp), %ebp
addl 0xc(%rsp), %ebp
movq %r14, %rdi
movq %r12, %rsi
movabsq $-0x5555555555555556, %rdx # imm = 0xAAAAAAAAAAAAAAAA
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
pushq $0x43
popq %r8
xorl %r9d, %r9d
callq 0x6740c
movl $0x2000, %esi           # imm = 0x2000
movq 0x20(%rsp), %rdi
movl %r13d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x675d6
movl $0x2000, %esi           # imm = 0x2000
movq 0x18(%rsp), %rdi
movl %r13d, %edx
movl %ebx, %ecx
xorl %r8d, %r8d
callq 0x675d6
movq %r14, %rdi
movq %r12, %rsi
movl %r13d, %edx
movl %r15d, %ecx
xorl %r8d, %r8d
callq 0x675d6
movl %eax, %r15d
addl %ebp, %r15d
incl %r13d
jmp 0x678b0
leaq 0x30(%rsp), %r13
movq %r13, %rsi
movq 0x10(%rsp), %r12
movq %r12, %rdx
callq 0x26c50
movq 0x28(%rsp), %rsi
subq %r12, %rsi
andq $-0x8, %r12
addq %r12, %r14
jmp 0x6785e