// File: /workspace/github_c_makefile_star2_O1/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 0x16d3
cmpl $0x5, %eax
jb 0x2780
movq 0x396d(%rip), %rcx      # 0x60d8
cmpq $0x7, %rcx
jbe 0x2a8b
addq $-0x8, %rcx
movq %rcx, 0x3958(%rip)      # 0x60d8
movb $0x1, 0x3ac9(%rip)      # 0x6250
movq 0x3952(%rip), %rcx      # 0x60e0
cmpq 0x3943(%rip), %rcx      # 0x60d8
movl %eax, 0x1c(%rsp)
jae 0x2936
leaq 0x20(%rsp), %r15
leaq 0x8(%rsp), %r12
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %ebp, %ebp
movq 0x3929(%rip), %rax      # 0x60e0
movq %rax, 0x393a(%rip)      # 0x60f8
movaps 0x390b(%rip), %xmm0     # 0x60d0
movups %xmm0, 0x391c(%rip)     # 0x60e8
callq 0x2230
movq %rax, %r13
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x2813
movq 0x390c(%rip), %rax      # 0x60f8
addq %rax, %rbp
subq 0x38ea(%rip), %rbp      # 0x60e0
incq %r14
movups 0x38e8(%rip), %xmm0     # 0x60e8
movaps %xmm0, 0x38c9(%rip)     # 0x60d0
movq %rax, 0x38d2(%rip)      # 0x60e0
jmp 0x2918
movq %r15, %rdi
leaq 0xa8a(%rip), %rsi       # 0x32a7
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1130
movl $0x4, %edi
movl $0x50, %esi
movq %r15, %rdx
callq 0x24d3
movq %r12, %rdi
callq 0x25df
movq 0x3895(%rip), %rbp      # 0x60e0
incq %rbp
cmpb $0x0, 0x14(%rsp)
sete %cl
cmpq 0x387b(%rip), %rbp      # 0x60d8
setb %al
andb %al, %cl
cmpb $0x1, %cl
jne 0x28d0
movq %rbp, 0x388a(%rip)      # 0x60f8
callq 0x2230
movq %rax, %r13
movq %rdx, 0x10(%rsp)
cmpb $0x0, 0x14(%rsp)
je 0x28af
xorl %eax, %eax
movl %eax, %r14d
cmpl $0x2, %eax
je 0x28a4
callq 0x2230
movq %rax, %r13
movq %rdx, 0x10(%rsp)
leal 0x1(%r14), %eax
cmpb $0x0, 0x14(%rsp)
jne 0x2884
xorl %eax, %eax
cmpl $0x2, %r14d
setb %al
jmp 0x28b4
movl $0x1, %eax
addq %rax, %rbp
movq 0x381a(%rip), %rcx      # 0x60d8
cmpq %rcx, %rbp
setb %al
cmpb $0x0, 0x14(%rsp)
jne 0x28d0
cmpq %rcx, %rbp
jb 0x2867
movq %r13, 0x8(%rsp)
testb %al, %al
je 0x2909
movq %rbp, %rdx
subq 0x37fd(%rip), %rdx      # 0x60e0
movq %r15, %rdi
leaq 0x9e7(%rip), %rsi       # 0x32d4
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1130
movl $0x4, %edi
movl $0x50, %esi
movq %r15, %rdx
callq 0x24d3
incq %rbx
movq %rbp, 0x37cd(%rip)      # 0x60e0
xorl %ebp, %ebp
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x1030
movq 0x37b9(%rip), %rax      # 0x60e0
cmpq 0x37aa(%rip), %rax      # 0x60d8
jb 0x27b0
jmp 0x293d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %ebx, %ebx
leaq 0x963(%rip), %rsi       # 0x32a7
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 0x24d3
movslq 0x10(%rsp), %rax
cmpq $0xff, %rax
je 0x29da
movq $0x0, 0x7955(%rip) # 0xa2d8
leaq 0x38ce(%rip), %r14      # 0x6258
shlq $0x4, %rax
leaq 0x796b(%rip), %rdx      # 0xa300
addq %rax, %rdx
leaq 0x9bb(%rip), %rsi       # 0x335a
movq %r14, %rdi
xorl %eax, %eax
callq 0x1130
movq 0x3730(%rip), %rax      # 0x60e0
movq 0x7921(%rip), %rcx      # 0xa2d8
movq %rax, 0x4000(%r14,%rcx,8)
incq 0x7912(%rip)            # 0xa2d8
leaq 0x8(%rsp), %rdi
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
callq 0x25df
incq %rbx
movl 0x1c(%rsp), %eax
cmpl $0x5, %eax
jb 0x2a5c
movq 0x36e6(%rip), %rsi      # 0x60d0
movq 0x36e7(%rip), %rdx      # 0x60d8
xorl %edi, %edi
callq 0x2d84
movq 0x36d1(%rip), %rcx      # 0x60d0
movq 0x36d2(%rip), %rdx      # 0x60d8
cmpq (%rcx,%rdx), %rax
jne 0x2a1a
leaq 0xa3e(%rip), %rdi       # 0x3451
callq 0x1070
jmp 0x2a5c
leaq 0x3837(%rip), %rax      # 0x6258
movq 0x78b0(%rip), %rcx      # 0xa2d8
movq %rcx, %rdx
shlq $0xa, %rdx
movups 0x943(%rip), %xmm0      # 0x3379
movups %xmm0, 0xa(%rdx,%rax)
movups 0x92d(%rip), %xmm0      # 0x336f
movups %xmm0, (%rdx,%rax)
movq 0x3693(%rip), %rdx      # 0x60e0
movq %rdx, 0x4000(%rax,%rcx,8)
incq 0x787c(%rip)            # 0xa2d8
testq %rbx, %rbx
je 0x2a7c
movl $0xa, %edi
callq 0x1040
leaq 0x917(%rip), %rdi       # 0x3389
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 0x9d4(%rip), %rdi       # 0x3466
callq 0x1070
movl $0x1, %edi
callq 0x1140