// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
callq 0x1700
movl %eax, %r13d
movq 0x39ae(%rip), %rax      # 0x60d8
cmpl $0x5, %r13d
jb 0x2745
cmpq $0x7, %rax
jbe 0x2a46
addq $-0x8, %rax
movq %rax, 0x3993(%rip)      # 0x60d8
movb $0x1, 0x3b04(%rip)      # 0x6250
cmpq %rax, 0x398d(%rip)      # 0x60e0
jae 0x28f5
movl %r13d, 0x1c(%rsp)
movabsq $0xff00000000, %r12     # imm = 0xFF00000000
leaq 0x20(%rsp), %r15
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x3965(%rip), %rax      # 0x60e0
movq %rax, 0x3976(%rip)      # 0x60f8
movaps 0x3947(%rip), %xmm0     # 0x60d0
movups %xmm0, 0x3958(%rip)     # 0x60e8
callq 0x21c7
movq %rax, %r13
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
testq %r12, %rdx
je 0x27d5
movq 0x394a(%rip), %rax      # 0x60f8
addq %rax, %rbp
subq 0x3928(%rip), %rbp      # 0x60e0
incq %r14
movups 0x3926(%rip), %xmm0     # 0x60e8
movaps %xmm0, 0x3907(%rip)     # 0x60d0
movq %rax, 0x3910(%rip)      # 0x60e0
jmp 0x28cd
movq %r15, %rdi
leaq 0xb00(%rip), %rsi       # 0x32df
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1130
movl $0x4, %edi
movl $0x50, %esi
movq %r15, %rdx
callq 0x2494
leaq 0x8(%rsp), %rdi
callq 0x25a0
movq 0x38d1(%rip), %rbp      # 0x60e0
incq %rbp
cmpq 0x38bf(%rip), %rbp      # 0x60d8
jae 0x2869
movq %rbp, 0x38d6(%rip)      # 0x60f8
callq 0x21c7
movq %rax, %r13
testq %r12, %rdx
je 0x2853
xorl %r14d, %r14d
cmpl $-0x2, %r14d
je 0x2870
callq 0x21c7
movq %rax, %r13
decl %r14d
testq %r12, %rdx
jne 0x2832
xorl %eax, %eax
cmpl $-0x2, %r14d
setae %al
jmp 0x2858
movl $0x1, %eax
addq %rax, %rbp
cmpq 0x3876(%rip), %rbp      # 0x60d8
jb 0x281b
movq %rdx, 0x10(%rsp)
movq %r13, 0x8(%rsp)
jmp 0x28be
negl %r14d
cmpl $0x2, %r14d
adcq $0x0, %rbp
movq %rdx, 0x10(%rsp)
movq %r13, 0x8(%rsp)
cmpq 0x384c(%rip), %rbp      # 0x60d8
jae 0x28be
movq %rbp, %rdx
subq 0x3848(%rip), %rdx      # 0x60e0
movq %r15, %rdi
leaq 0xa6a(%rip), %rsi       # 0x330c
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1130
movl $0x4, %edi
movl $0x50, %esi
movq %r15, %rdx
callq 0x2494
incq %rbx
movq %rbp, 0x3818(%rip)      # 0x60e0
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x1030
movq 0x3804(%rip), %rax      # 0x60e0
cmpq 0x37f5(%rip), %rax      # 0x60d8
jb 0x2774
movl 0x10(%rsp), %r12d
movl 0x1c(%rsp), %r13d
jmp 0x28fc
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %ebx, %ebx
leaq 0x9dc(%rip), %rsi       # 0x32df
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1130
movl $0x4, %edi
movl $0x50, %esi
movq %r15, %rdx
callq 0x2494
cmpl $0xff, %r12d
je 0x2998
movq $0x0, 0x799a(%rip) # 0xa2d8
leaq 0x3913(%rip), %r14      # 0x6258
movslq %r12d, %rax
shlq $0x4, %rax
leaq 0x79ad(%rip), %rdx      # 0xa300
addq %rax, %rdx
leaq 0xa35(%rip), %rsi       # 0x3392
movq %r14, %rdi
xorl %eax, %eax
callq 0x1130
movq 0x3772(%rip), %rax      # 0x60e0
movq 0x7963(%rip), %rcx      # 0xa2d8
movq %rax, 0x4000(%r14,%rcx,8)
incq 0x7954(%rip)            # 0xa2d8
leaq 0x8(%rsp), %rdi
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
callq 0x25a0
incq %rbx
cmpl $0x5, %r13d
jb 0x2a17
movq 0x372b(%rip), %rsi      # 0x60d0
movq 0x372c(%rip), %rdx      # 0x60d8
xorl %edi, %edi
callq 0x2d1c
movq 0x3716(%rip), %rcx      # 0x60d0
movq 0x3717(%rip), %rdx      # 0x60d8
cmpq (%rcx,%rdx), %rax
jne 0x29d5
leaq 0xabb(%rip), %rdi       # 0x3489
callq 0x1070
jmp 0x2a17
leaq 0x387c(%rip), %rax      # 0x6258
movq 0x78f5(%rip), %rcx      # 0xa2d8
movq %rcx, %rdx
shlq $0xa, %rdx
movups 0x9c0(%rip), %xmm0      # 0x33b1
movups %xmm0, 0xa(%rdx,%rax)
movups 0x9aa(%rip), %xmm0      # 0x33a7
movups %xmm0, (%rdx,%rax)
movq 0x36d8(%rip), %rdx      # 0x60e0
movq %rdx, 0x4000(%rax,%rcx,8)
incq 0x78c1(%rip)            # 0xa2d8
testq %rbx, %rbx
je 0x2a37
movl $0xa, %edi
callq 0x1040
leaq 0x994(%rip), %rdi       # 0x33c1
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa51(%rip), %rdi       # 0x349e
callq 0x1070
movl $0x1, %edi
callq 0x1140