// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/debug.c
// Function: computeDatasetDigest
void computeDatasetDigest(unsigned char *final) {
    unsigned char digest[20];
    char buf[128];
    dictIterator *di = NULL;
    dictEntry *de;
    int j;
    uint32_t aux;

    memset(final,0,20); /* Start with a clean result */

    for (j = 0; j < server.dbnum; j++) {
        redisDb *db = server.db+j;

        if (dictSize(db->dict) == 0) continue;
        di = dictGetSafeIterator(db->dict);

        /* hash the DB id, so the same dataset moved in a different
         * DB will lead to a different digest */
        aux = htonl(j);
        mixDigest(final,&aux,sizeof(aux));

        /* Iterate this DB writing every entry */
        while((de = dictNext(di)) != NULL) {
            sds key;
            robj *keyobj, *o;
            long long expiretime;

            memset(digest,0,20); /* This key-val digest */
            key = dictGetKey(de);
            keyobj = createStringObject(key,sdslen(key));

            mixDigest(digest,key,sdslen(key));

            o = dictGetVal(de);

            aux = htonl(o->type);
            mixDigest(digest,&aux,sizeof(aux));
            expiretime = getExpire(db,keyobj);

            /* Save the key and associated value */
            if (o->type == OBJ_STRING) {
                mixObjectDigest(digest,o);
            } else if (o->type == OBJ_LIST) {
                listTypeIterator *li = listTypeInitIterator(o,0,LIST_TAIL);
                listTypeEntry entry;
                while(listTypeNext(li,&entry)) {
                    robj *eleobj = listTypeGet(&entry);
                    mixObjectDigest(digest,eleobj);
                    decrRefCount(eleobj);
                }
                listTypeReleaseIterator(li);
            } else if (o->type == OBJ_SET) {
                setTypeIterator *si = setTypeInitIterator(o);
                robj *ele;
                while((ele = setTypeNextObject(si)) != NULL) {
                    xorObjectDigest(digest,ele);
                    decrRefCount(ele);
                }
                setTypeReleaseIterator(si);
            } else if (o->type == OBJ_ZSET) {
                unsigned char eledigest[20];

                if (o->encoding == OBJ_ENCODING_ZIPLIST) {
                    unsigned char *zl = o->ptr;
                    unsigned char *eptr, *sptr;
                    unsigned char *vstr;
                    unsigned int vlen;
                    long long vll;
                    double score;

                    eptr = ziplistIndex(zl,0);
                    serverAssert(eptr != NULL);
                    sptr = ziplistNext(zl,eptr);
                    serverAssert(sptr != NULL);

                    while (eptr != NULL) {
                        serverAssert(ziplistGet(eptr,&vstr,&vlen,&vll));
                        score = zzlGetScore(sptr);

                        memset(eledigest,0,20);
                        if (vstr != NULL) {
                            mixDigest(eledigest,vstr,vlen);
                        } else {
                            ll2string(buf,sizeof(buf),vll);
                            mixDigest(eledigest,buf,strlen(buf));
                        }

                        snprintf(buf,sizeof(buf),"%.17g",score);
                        mixDigest(eledigest,buf,strlen(buf));
                        xorDigest(digest,eledigest,20);
                        zzlNext(zl,&eptr,&sptr);
                    }
                } else if (o->encoding == OBJ_ENCODING_SKIPLIST) {
                    zset *zs = o->ptr;
                    dictIterator *di = dictGetIterator(zs->dict);
                    dictEntry *de;

                    while((de = dictNext(di)) != NULL) {
                        robj *eleobj = dictGetKey(de);
                        double *score = dictGetVal(de);

                        snprintf(buf,sizeof(buf),"%.17g",*score);
                        memset(eledigest,0,20);
                        mixObjectDigest(eledigest,eleobj);
                        mixDigest(eledigest,buf,strlen(buf));
                        xorDigest(digest,eledigest,20);
                    }
                    dictReleaseIterator(di);
                } else {
                    serverPanic("Unknown sorted set encoding");
                }
            } else if (o->type == OBJ_HASH) {
                hashTypeIterator *hi;
                robj *obj;

                hi = hashTypeInitIterator(o);
                while (hashTypeNext(hi) != C_ERR) {
                    unsigned char eledigest[20];

                    memset(eledigest,0,20);
                    obj = hashTypeCurrentObject(hi,OBJ_HASH_KEY);
                    mixObjectDigest(eledigest,obj);
                    decrRefCount(obj);
                    obj = hashTypeCurrentObject(hi,OBJ_HASH_VALUE);
                    mixObjectDigest(eledigest,obj);
                    decrRefCount(obj);
                    xorDigest(digest,eledigest,20);
                }
                hashTypeReleaseIterator(hi);
            } else {
                serverPanic("Unknown object type");
            }
            /* If the key has an expire, add it to the mix */
            if (expiretime != -1) xorDigest(digest,"!!expire!!",10);
            /* We can finally xor the key-val digest to the final digest */
            xorDigest(final,digest,20);
            decrRefCount(keyobj);
        }
        dictReleaseIterator(di);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x28(%rsp)
movl $0x0, 0x10(%rdi)
leaq 0xa1936(%rip), %rcx     # 0x106858
cmpl $0x0, 0x600(%rcx)
jle 0x65454
xorl %r14d, %r14d
leaq 0x70(%rsp), %r15
leaq 0x90(%rsp), %r13
movq 0x28(%rcx), %rax
movq %r14, %rbx
shlq $0x6, %rbx
movq %rax, 0x38(%rsp)
movq (%rax,%rbx), %rdi
movq 0x28(%rdi), %rax
addq 0x48(%rdi), %rax
je 0x65441
callq 0x320e5
movq %rax, %rbp
movq %r14, 0x50(%rsp)
movl %r14d, %eax
bswapl %eax
movl %eax, 0xc(%rsp)
movl $0x4, %edx
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x64e50
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
callq 0x32116
testq %rax, %rax
je 0x6542b
movq %rax, %r14
addq %rbx, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movl $0x0, 0x80(%rsp)
movq (%r14), %rbp
movzbl -0x1(%rbp), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x64ff9
leaq 0x63ea0(%rip), %rcx     # 0xc8e74
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x64ffb
movq -0x11(%rbp), %rsi
jmp 0x64ffb
movzwl -0x5(%rbp), %esi
jmp 0x64ffb
movl -0x9(%rbp), %esi
jmp 0x64ffb
movzbl -0x3(%rbp), %esi
jmp 0x64ffb
xorl %esi, %esi
movq %rbp, %rdi
callq 0x43ba8
movq %rax, 0x40(%rsp)
movzbl -0x1(%rbp), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
leaq 0x5df4c(%rip), %rbx     # 0xc2f67
ja 0x65049
leaq 0x63e64(%rip), %rcx     # 0xc8e88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x6504b
movq -0x11(%rbp), %rdx
jmp 0x6504b
movzwl -0x5(%rbp), %edx
jmp 0x6504b
movl -0x9(%rbp), %edx
jmp 0x6504b
movzbl -0x3(%rbp), %edx
jmp 0x6504b
xorl %edx, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x64e50
movq 0x8(%r14), %rbp
movl (%rbp), %eax
andl $0xf, %eax
shll $0x18, %eax
movl %eax, 0xc(%rsp)
movl $0x4, %edx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x64e50
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x46484
movq %rax, %r12
movl (%rbp), %eax
andl $0xf, %eax
cmpl $0x4, %eax
ja 0x65488
leaq 0x63df8(%rip), %rcx     # 0xc8e9c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
movq %rbp, %rsi
callq 0x64e8f
jmp 0x653e1
movq %rbp, %rdi
callq 0x5960a
movq %rax, %rbp
movq %rax, %rdi
callq 0x59696
cmpl $-0x1, %eax
xorps %xmm0, %xmm0
je 0x65151
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x59867
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0x64e8f
movq %rbx, %rdi
callq 0x440f3
movq %rbp, %rdi
movl $0x2, %esi
callq 0x59867
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0x64e8f
movq %rbx, %rdi
callq 0x440f3
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x64d58
movq %rbp, %rdi
callq 0x59696
xorps %xmm0, %xmm0
cmpl $-0x1, %eax
jne 0x650d8
movq %rbp, %rdi
callq 0x5967a
jmp 0x653e1
movq %rbp, %rdi
callq 0x51af7
movq %rax, %rbp
movq %rax, %rdi
callq 0x51c10
testq %rax, %rax
je 0x6519c
movq %rax, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x64daf
movq %rbx, %rdi
callq 0x440f3
movq %rbp, %rdi
callq 0x51c10
movq %rax, %rbx
testq %rax, %rax
jne 0x65179
movq %rbp, %rdi
callq 0x51b67
jmp 0x653e1
movl (%rbp), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
movq %r12, 0x20(%rsp)
je 0x65337
cmpl $0x5, %eax
jne 0x6549d
movq 0x8(%rbp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x3ea40
movq %rax, 0x10(%rsp)
testq %rax, %rax
leaq 0xd0(%rsp), %r12
je 0x654b7
movq %rbp, %rdi
movq %rax, %rsi
callq 0x3ead6
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x654cc
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x653dc
leaq 0x68(%rsp), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x3eb60
testl %eax, %eax
je 0x65466
movq 0x48(%rsp), %rdi
callq 0x54417
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq 0x68(%rsp), %rsi
testq %rsi, %rsi
je 0x65269
movl 0x1c(%rsp), %edx
movq %r13, %rdi
jmp 0x6528c
movq 0x60(%rsp), %rdx
movl $0x80, %esi
movq %r12, %rdi
callq 0x433e5
movq %r12, %rdi
callq 0x26510
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x64e50
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rdx
movsd 0x58(%rsp), %xmm0
movb $0x1, %al
callq 0x26120
movq %r12, %rdi
callq 0x26510
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x64e50
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x64d58
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x545d7
jmp 0x65206
movq %rbp, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4fc5a
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
callq 0x4fcf2
testl %eax, %eax
je 0x6532a
movq %r13, %rdi
callq 0x4fd57
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x64e8f
movq %rbx, %rdi
callq 0x440f3
movq %rbp, %rdi
jmp 0x652fb
movq %rbp, %rdi
callq 0x4fcdc
jmp 0x653e1
movq 0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x320bb
movq %rax, %rbp
movq %rax, %rdi
callq 0x32116
testq %rax, %rax
leaq 0xd0(%rsp), %r12
je 0x653cf
movq %rbx, %r14
movq (%rax), %rbx
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movl $0x80, %esi
movq %r12, %rdi
movq %r14, %rdx
movb $0x1, %al
callq 0x26120
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64e8f
movq %r12, %rdi
callq 0x26510
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x64e50
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x64d58
movq %rbp, %rdi
callq 0x32116
testq %rax, %rax
jne 0x6535e
movq %rbp, %rdi
callq 0x321d3
movq 0x40(%rsp), %r14
movq 0x20(%rsp), %r12
cmpq $-0x1, %r12
je 0x653fb
movl $0xa, %edx
movq %r15, %rdi
leaq 0x63b32(%rip), %rsi     # 0xc8f28
callq 0x64d58
movl $0x14, %edx
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x64d58
movq %r14, %rdi
callq 0x440f3
movq 0x30(%rsp), %rdi
callq 0x32116
movq %rax, %r14
testq %rax, %rax
jne 0x64fa9
movq 0x30(%rsp), %rdi
callq 0x321d3
leaq 0xa141c(%rip), %rcx     # 0x106858
movq 0x50(%rsp), %r14
incq %r14
movslq 0x600(%rcx), %rax
cmpq %rax, %r14
jl 0x64f3f
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x63276(%rip), %rdi     # 0xc86e3
leaq 0x63aac(%rip), %rsi     # 0xc8f20
movl $0xbf, %edx
callq 0x654e1
movl $0x1, %edi
callq 0x263d0
leaq 0x5e847(%rip), %rdi     # 0xc3cd6
leaq 0x63a8a(%rip), %rsi     # 0xc8f20
movl $0xf5, %edx
jmp 0x654b0
leaq 0x5e7d2(%rip), %rdi     # 0xc3c76
leaq 0x63a75(%rip), %rsi     # 0xc8f20
movl $0xe0, %edx
callq 0x6558d
jmp 0x6547e
leaq 0x61221(%rip), %rdi     # 0xc66df
leaq 0x63a5b(%rip), %rsi     # 0xc8f20
movl $0xba, %edx
jmp 0x65479
leaq 0x61533(%rip), %rdi     # 0xc6a06
leaq 0x63a46(%rip), %rsi     # 0xc8f20
movl $0xbc, %edx
jmp 0x65479