// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/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 = dictGetIterator(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 == REDIS_STRING) {
                mixObjectDigest(digest,o);
            } else if (o->type == REDIS_LIST) {
                listTypeIterator *li = listTypeInitIterator(o,0,REDIS_TAIL);
                listTypeEntry entry;
                while(listTypeNext(li,&entry)) {
                    robj *eleobj = listTypeGet(&entry);
                    mixObjectDigest(digest,eleobj);
                    decrRefCount(eleobj);
                }
                listTypeReleaseIterator(li);
            } else if (o->type == REDIS_SET) {
                setTypeIterator *si = setTypeInitIterator(o);
                robj *ele;
                while((ele = setTypeNextObject(si)) != NULL) {
                    xorObjectDigest(digest,ele);
                    decrRefCount(ele);
                }
                setTypeReleaseIterator(si);
            } else if (o->type == REDIS_ZSET) {
                unsigned char eledigest[20];

                if (o->encoding == REDIS_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);
                    redisAssert(eptr != NULL);
                    sptr = ziplistNext(zl,eptr);
                    redisAssert(sptr != NULL);

                    while (eptr != NULL) {
                        redisAssert(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 == REDIS_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 {
                    redisPanic("Unknown sorted set encoding");
                }
            } else if (o->type == REDIS_HASH) {
                hashTypeIterator *hi;
                robj *obj;

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

                    memset(eledigest,0,20);
                    obj = hashTypeCurrentObject(hi,REDIS_HASH_KEY);
                    mixObjectDigest(eledigest,obj);
                    decrRefCount(obj);
                    obj = hashTypeCurrentObject(hi,REDIS_HASH_VALUE);
                    mixObjectDigest(eledigest,obj);
                    decrRefCount(obj);
                    xorDigest(digest,eledigest,20);
                }
                hashTypeReleaseIterator(hi);
            } else {
                redisPanic("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 $0x128, %rsp            # imm = 0x128
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x38(%rsp)
movl $0x0, 0x10(%rdi)
leaq 0x7dad6(%rip), %rax     # 0xc9fa8
movl 0x480(%rax), %eax
testl %eax, %eax
jle 0x4c9a5
leaq 0x7dac1(%rip), %rcx     # 0xc9fa8
movq 0x10(%rcx), %rcx
movq %rcx, 0x18(%rsp)
xorl %ebx, %ebx
leaq 0x80(%rsp), %r15
leaq 0x50(%rsp), %rbp
leaq 0xa0(%rsp), %r14
movq %rbx, %r12
shlq $0x6, %r12
movq 0x18(%rsp), %rcx
movq (%rcx,%r12), %rdi
movq 0x28(%rdi), %rcx
addq 0x48(%rdi), %rcx
je 0x4c996
callq 0x22a71
movq %rax, %r13
movq %rbx, 0x68(%rsp)
movl %ebx, %eax
bswapl %eax
movl %eax, 0x14(%rsp)
movl $0x4, %edx
movq 0x38(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4c438
movq %r13, 0x40(%rsp)
movq %r13, %rdi
callq 0x22acf
testq %rax, %rax
je 0x4c971
movq %rax, %rbx
addq %r12, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movl $0x0, 0x90(%rsp)
movq (%rbx), %r13
movslq -0x8(%r13), %rsi
movq %r13, %rdi
callq 0x3068f
movq %rax, %r12
movslq -0x8(%r13), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c438
movq 0x8(%rbx), %r13
movl (%r13), %eax
andl $0xf, %eax
shll $0x18, %eax
movl %eax, 0x14(%rsp)
movl $0x4, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
callq 0x4c438
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x329dd
movq %rax, %rbx
movl (%r13), %eax
movl %eax, %ecx
andl $0xf, %ecx
cmpl $0x4, %ecx
ja 0x4c9d9
leaq 0x4eb48(%rip), %rdx     # 0x9b138
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c477
jmp 0x4c927
movq %rbx, 0x8(%rsp)
movq %r13, %rdi
callq 0x4275d
movq %rax, %r13
movq %rax, %rdi
callq 0x427e9
cmpl $-0x1, %eax
xorps %xmm0, %xmm0
je 0x4c69c
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq %r13, %rdi
movl $0x1, %esi
callq 0x4299d
movq %rax, %rbx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4c477
movq %rbx, %rdi
callq 0x30b0c
movq %r13, %rdi
movl $0x2, %esi
callq 0x4299d
movq %rax, %rbx
movq %rbp, %rdi
movq %rax, %rsi
callq 0x4c477
movq %rbx, %rdi
callq 0x30b0c
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4c3b0
movq %r13, %rdi
callq 0x427e9
xorps %xmm0, %xmm0
cmpl $-0x1, %eax
jne 0x4c629
movq %r13, %rdi
callq 0x427cd
jmp 0x4c922
movq %rbx, 0x8(%rsp)
movq %r13, %rdi
callq 0x3ba3a
movq %rax, %r13
movq %rax, %rdi
callq 0x3bb1e
testq %rax, %rax
je 0x4c6ec
movq %rax, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4c407
movq %rbx, %rdi
callq 0x30b0c
movq %r13, %rdi
callq 0x3bb1e
movq %rax, %rbx
testq %rax, %rax
jne 0x4c6c9
movq %r13, %rdi
callq 0x3baaa
jmp 0x4c922
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
movq %rbx, 0x8(%rsp)
je 0x4c882
cmpl $0x5, %eax
jne 0x4c9ee
movq 0x8(%r13), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x2c28b
movq %rax, 0x28(%rsp)
testq %rax, %rax
leaq 0x4a6c4(%rip), %rbx     # 0x96df7
je 0x4ca08
movq %r13, %rdi
movq %rax, %rsi
callq 0x2c558
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x4ca1d
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4c922
leaq 0x78(%rsp), %rsi
leaq 0x34(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x2c5f6
testl %eax, %eax
je 0x4c9b7
movq 0x48(%rsp), %rdi
callq 0x3ded9
movsd %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
je 0x4c7af
movl 0x34(%rsp), %edx
movq %rbp, %rdi
jmp 0x4c7d2
movq 0x70(%rsp), %rdx
movl $0x80, %esi
movq %r14, %rdi
callq 0x300c7
movq %r14, %rdi
callq 0x1f4f0
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4c438
movl $0x80, %esi
movq %r14, %rdi
movq %rbx, %rdx
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x1f120
movq %r14, %rdi
callq 0x1f4f0
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4c438
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4c3b0
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x3e09f
jmp 0x4c752
movq %rbx, 0x8(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x399c5
movq %rax, %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0x39a5a
testl %eax, %eax
je 0x4c875
movq %rbp, %rdi
callq 0x39b0f
movq %rax, %rbx
movq %r15, %rdi
movq %rax, %rsi
callq 0x4c477
movq %rbx, %rdi
callq 0x30b0c
movq %r13, %rdi
jmp 0x4c846
movq %r13, %rdi
callq 0x39a55
jmp 0x4c922
movq %r12, 0x20(%rsp)
movq 0x8(%r13), %rax
movq (%rax), %rdi
callq 0x22a71
movq %rax, %r13
movq %rax, %rdi
callq 0x22acf
testq %rax, %rax
leaq 0x4a54f(%rip), %r12     # 0x96df7
je 0x4c915
movq (%rax), %rbx
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movl $0x80, %esi
movq %r14, %rdi
movq %r12, %rdx
movb $0x1, %al
callq 0x1f120
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4c477
movq %r14, %rdi
callq 0x1f4f0
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4c438
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4c3b0
movq %r13, %rdi
callq 0x22acf
testq %rax, %rax
jne 0x4c8aa
movq %r13, %rdi
callq 0x22b86
movq 0x20(%rsp), %r12
movq 0x8(%rsp), %rbx
cmpq $-0x1, %rbx
je 0x4c941
movl $0xa, %edx
movq %r15, %rdi
leaq 0x4e834(%rip), %rsi     # 0x9b170
callq 0x4c3b0
movl $0x14, %edx
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x4c3b0
movq %r12, %rdi
callq 0x30b0c
movq 0x40(%rsp), %rdi
callq 0x22acf
movq %rax, %rbx
testq %rax, %rax
jne 0x4c56c
movq 0x40(%rsp), %rdi
callq 0x22b86
leaq 0x7d626(%rip), %rax     # 0xc9fa8
movq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
movl 0x480(%rax), %eax
movq 0x68(%rsp), %rbx
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x4c507
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4e1a3(%rip), %rdi     # 0x9ab61
leaq 0x4e7a3(%rip), %rsi     # 0x9b168
movl $0xb7, %edx
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
leaq 0x4aa33(%rip), %rdi     # 0x97413
leaq 0x4e781(%rip), %rsi     # 0x9b168
movl $0xed, %edx
jmp 0x4ca01
leaq 0x4a9be(%rip), %rdi     # 0x973b3
leaq 0x4e76c(%rip), %rsi     # 0x9b168
movl $0xd8, %edx
callq 0x4cae0
jmp 0x4c9cf
leaq 0x4c879(%rip), %rdi     # 0x99288
leaq 0x4e752(%rip), %rsi     # 0x9b168
movl $0xb2, %edx
jmp 0x4c9ca
leaq 0x4cb21(%rip), %rdi     # 0x99545
leaq 0x4e73d(%rip), %rsi     # 0x9b168
movl $0xb4, %edx
jmp 0x4c9ca