// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/redis-check-dump.c
// Function: process
void process() {
    uint64_t num_errors = 0, num_valid_ops = 0, num_valid_bytes = 0;
    entry entry;
    int dump_version = processHeader();

    /* Exclude the final checksum for RDB >= 5. Will be checked at the end. */
    if (dump_version >= 5) {
        if (positions[0].size < 8) {
            printf("RDB version >= 5 but no room for checksum.\n");
            exit(1);
        }
        positions[0].size -= 8;;
    }

    level = 1;
    while(positions[0].offset < positions[0].size) {
        positions[1] = positions[0];

        entry = loadEntry();
        if (!entry.success) {
            printValid(num_valid_ops, num_valid_bytes);
            printErrorStack(&entry);
            num_errors++;
            num_valid_ops = 0;
            num_valid_bytes = 0;

            /* search for next valid entry */
            uint64_t offset = positions[0].offset + 1;
            int i = 0;

            while (!entry.success && offset < positions[0].size) {
                positions[1].offset = offset;

                /* find 3 consecutive valid entries */
                for (i = 0; i < 3; i++) {
                    entry = loadEntry();
                    if (!entry.success) break;
                }
                /* check if we found 3 consecutive valid entries */
                if (i < 3) {
                    offset++;
                }
            }

            /* print how many bytes we have skipped to find a new valid opcode */
            if (offset < positions[0].size) {
                printSkipped(offset - positions[0].offset, offset);
            }

            positions[0].offset = offset;
        } else {
            num_valid_ops++;
            num_valid_bytes += positions[1].offset - positions[0].offset;

            /* advance position */
            positions[0] = positions[1];
        }
        free(entry.key);
    }

    /* because there is another potential error,
     * print how many valid ops we have processed */
    printValid(num_valid_ops, num_valid_bytes);

    /* expect an eof */
    if (entry.type != REDIS_EOF) {
        /* last byte should be EOF, add error */
        errors.level = 0;
        SHIFT_ERROR(positions[0].offset, "Expected EOF, got %s", types[entry.type]);

        /* this is an EOF error so reset type */
        entry.type = -1;
        printErrorStack(&entry);

        num_errors++;
    }

    /* Verify checksum */
    if (dump_version >= 5) {
        uint64_t crc = crc64(0,positions[0].data,positions[0].size);
        uint64_t crc2;
        unsigned char *p = (unsigned char*)positions[0].data+positions[0].size;
        crc2 = ((uint64_t)p[0] << 0) |
               ((uint64_t)p[1] << 8) |
               ((uint64_t)p[2] << 16) |
               ((uint64_t)p[3] << 24) |
               ((uint64_t)p[4] << 32) |
               ((uint64_t)p[5] << 40) |
               ((uint64_t)p[6] << 48) |
               ((uint64_t)p[7] << 56);
        if (crc != crc2) {
            SHIFT_ERROR(positions[0].offset, "RDB CRC64 does not match.");
        } else {
            printf("CRC64 checksum is OK\n");
        }
    }

    /* print summary on errors */
    if (num_errors) {
        printf("\n");
        printf("Total unprocessable opcodes: %llu\n",
            (unsigned long long) num_errors);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
callq 0x12ec
cmpl $0x5, %eax
jb 0x21a9
movq 0x3f54(%rip), %rcx      # 0x60e8
cmpq $0x7, %rcx
jbe 0x2410
addq $-0x8, %rcx
movq %rcx, 0x3f3f(%rip)      # 0x60e8
movl %eax, 0x4(%rsp)
movb $0x1, 0x40ac(%rip)      # 0x6260
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x3f29(%rip), %rax      # 0x60f0
cmpq 0x3f1a(%rip), %rax      # 0x60e8
jae 0x22e0
movq 0x3f15(%rip), %rax      # 0x60f0
movq %rax, 0x3f26(%rip)      # 0x6108
movaps 0x3ef7(%rip), %xmm0     # 0x60e0
movups %xmm0, 0x3f08(%rip)     # 0x60f8
callq 0x1c7b
movq %rax, %r12
movq %rdx, %r15
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdx, %rax
shrq $0x20, %rax
testb %al, %al
je 0x223e
movq 0x3ef1(%rip), %rax      # 0x6108
addq %rax, %r13
subq 0x3ecf(%rip), %r13      # 0x60f0
incq %rbp
movups 0x3ecd(%rip), %xmm0     # 0x60f8
movaps %xmm0, 0x3eae(%rip)     # 0x60e0
movq %rax, 0x3eb7(%rip)      # 0x60f0
jmp 0x22d3
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1fbd
movq %r14, %rdi
callq 0x2023
movq 0x3e98(%rip), %r13      # 0x60f0
incq %r13
xorl %eax, %eax
movq 0x3e84(%rip), %rcx      # 0x60e8
testb %al, %al
jne 0x22a3
cmpq %rcx, %r13
jae 0x22a3
movq %r13, 0x3e94(%rip)      # 0x6108
xorl %eax, %eax
xorl %ecx, %ecx
movl %ecx, %ebp
cmpl $0x3, %ecx
je 0x229a
callq 0x1c7b
movq %rax, %r12
movq %rdx, %r15
movq %rdx, %rax
shrq $0x20, %rax
leal 0x1(%rbp), %ecx
testb %al, %al
jne 0x2278
xorl %eax, %eax
cmpl $0x3, %ebp
adcq $0x0, %r13
jmp 0x225d
movq %r15, 0x10(%rsp)
movq %r12, 0x8(%rsp)
cmpq %rcx, %r13
jae 0x22c4
movq %r13, %rdi
subq 0x3e34(%rip), %rdi      # 0x60f0
movq %r13, %rsi
callq 0x1ff0
incq %rbx
movq %r13, 0x3e22(%rip)      # 0x60f0
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x1030
jmp 0x21c0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1fbd
cmpl $0xff, %r15d
je 0x2353
andq $0x0, 0x7fec(%rip)      # 0xa2e8
leaq 0x3f65(%rip), %r14      # 0x6268
movslq %r15d, %rax
shlq $0x4, %rax
leaq 0x7fff(%rip), %rdx      # 0xa310
addq %rax, %rdx
leaq 0x1077(%rip), %rsi      # 0x3392
movq %r14, %rdi
xorl %eax, %eax
callq 0x1140
movq 0x3dc4(%rip), %rax      # 0x60f0
movq 0x7fb5(%rip), %rcx      # 0xa2e8
movq %rax, 0x4000(%r14,%rcx,8)
incq 0x7fa6(%rip)            # 0xa2e8
leaq 0x8(%rsp), %rdi
orl $-0x1, 0x8(%rdi)
callq 0x2023
incq %rbx
movl 0x4(%rsp), %eax
cmpl $0x5, %eax
jb 0x23d5
movq 0x3d7d(%rip), %rsi      # 0x60e0
movq 0x3d7e(%rip), %rdx      # 0x60e8
xorl %edi, %edi
callq 0x2b08
movq 0x3d68(%rip), %rcx      # 0x60e0
movq 0x3d69(%rip), %rdx      # 0x60e8
cmpq (%rcx,%rdx), %rax
jne 0x2393
leaq 0x10fd(%rip), %rdi      # 0x3489
callq 0x1070
jmp 0x23d5
leaq 0x3ece(%rip), %rax      # 0x6268
movq 0x7f47(%rip), %rcx      # 0xa2e8
movq %rcx, %rdx
shlq $0xa, %rdx
movups 0x1002(%rip), %xmm0     # 0x33b1
movups %xmm0, 0xa(%rdx,%rax)
movups 0xfec(%rip), %xmm0      # 0x33a7
movups %xmm0, (%rdx,%rax)
movq 0x3d2a(%rip), %rdx      # 0x60f0
movq %rdx, 0x4000(%rax,%rcx,8)
incq 0x7f13(%rip)            # 0xa2e8
testq %rbx, %rbx
je 0x2401
pushq $0xa
popq %rdi
callq 0x1040
leaq 0xfd8(%rip), %rdi       # 0x33c1
movq %rbx, %rsi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10a0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1087(%rip), %rdi      # 0x349e
callq 0x1070
pushq $0x1
popq %rdi
callq 0x1150