// File: /workspace/github_c_makefile_star2_O1/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, 0x30(%rsp)
movl $0x0, 0x10(%rdi)
leaq 0x7d4ba(%rip), %rcx     # 0xc9fa8
cmpl $0x0, 0x480(%rcx)
jle 0x4cfaa
xorl %r14d, %r14d
leaq 0x80(%rsp), %r15
leaq 0x50(%rsp), %r13
leaq 0xa0(%rsp), %r12
movq 0x10(%rcx), %rax
movq %r14, %rbx
shlq $0x6, %rbx
movq %rax, 0x40(%rsp)
movq (%rax,%rbx), %rdi
movq 0x28(%rdi), %rax
addq 0x48(%rdi), %rax
je 0x4cf97
callq 0x228b5
movq %rax, %rbp
movq %r14, 0x68(%rsp)
movl %r14d, %eax
bswapl %eax
movl %eax, 0x14(%rsp)
movl $0x4, %edx
movq 0x30(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x4ca54
movq %rbp, 0x38(%rsp)
movq %rbp, %rdi
callq 0x22913
testq %rax, %rax
je 0x4cf81
movq %rax, %r14
addq %rbx, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movl $0x0, 0x90(%rsp)
movq (%r14), %rbp
movslq -0x8(%rbp), %rsi
movq %rbp, %rdi
callq 0x303b7
movq %rax, %rbx
movslq -0x8(%rbp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4ca54
movq 0x8(%r14), %rbp
movl (%rbp), %eax
andl $0xf, %eax
shll $0x18, %eax
movl %eax, 0x14(%rsp)
movl $0x4, %edx
movq %r15, %rdi
leaq 0x14(%rsp), %rsi
callq 0x4ca54
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x326b1
movq %rax, %r14
movl (%rbp), %eax
andl $0xf, %eax
cmpl $0x4, %eax
ja 0x4cfde
leaq 0x4e4eb(%rip), %rcx     # 0x9b0e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4ca93
jmp 0x4cf37
movq %r14, 0x8(%rsp)
movq %rbp, %rdi
callq 0x4288e
movq %rax, %rbp
movq %rax, %rdi
callq 0x4291a
cmpl $-0x1, %eax
xorps %xmm0, %xmm0
je 0x4cca9
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq %rbp, %rdi
movl $0x1, %esi
callq 0x42aeb
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0x4ca93
movq %r14, %rdi
callq 0x30834
movq %rbp, %rdi
movl $0x2, %esi
callq 0x42aeb
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0x4ca93
movq %r14, %rdi
callq 0x30834
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c9cc
movq %rbp, %rdi
callq 0x4291a
xorps %xmm0, %xmm0
cmpl $-0x1, %eax
jne 0x4cc36
movq %rbp, %rdi
callq 0x428fe
jmp 0x4cf32
movq %r14, 0x8(%rsp)
movq %rbp, %rdi
callq 0x3b9ce
movq %rax, %rbp
movq %rax, %rdi
callq 0x3bab2
testq %rax, %rax
je 0x4ccf9
movq %rax, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x4ca23
movq %r14, %rdi
callq 0x30834
movq %rbp, %rdi
callq 0x3bab2
movq %rax, %r14
testq %rax, %rax
jne 0x4ccd6
movq %rbp, %rdi
callq 0x3ba3e
jmp 0x4cf32
movl (%rbp), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
movq %r14, 0x8(%rsp)
je 0x4ce92
cmpl $0x5, %eax
jne 0x4cff3
movq 0x8(%rbp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2bff5
movq %rax, 0x20(%rsp)
testq %rax, %rax
leaq 0x4a054(%rip), %r14     # 0x96d97
je 0x4d00d
movq %rbp, %rdi
movq %rax, %rsi
callq 0x2c2b3
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x4d022
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4cf32
leaq 0x78(%rsp), %rsi
leaq 0x2c(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x2c351
testl %eax, %eax
je 0x4cfbc
movq 0x48(%rsp), %rdi
callq 0x3ddbd
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
je 0x4cdbf
movl 0x2c(%rsp), %edx
movq %r13, %rdi
jmp 0x4cde2
movq 0x70(%rsp), %rdx
movl $0x80, %esi
movq %r12, %rdi
callq 0x2fe12
movq %r12, %rdi
callq 0x1f4f0
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4ca54
movl $0x80, %esi
movq %r12, %rdi
movq %r14, %rdx
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x1f120
movq %r12, %rdi
callq 0x1f4f0
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4ca54
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c9cc
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x3df7d
jmp 0x4cd62
movq %r14, 0x8(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x39935
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
callq 0x399ca
testl %eax, %eax
je 0x4ce85
movq %r13, %rdi
callq 0x39a7f
movq %rax, %r14
movq %r15, %rdi
movq %rax, %rsi
callq 0x4ca93
movq %r14, %rdi
callq 0x30834
movq %rbp, %rdi
jmp 0x4ce56
movq %rbp, %rdi
callq 0x399c5
jmp 0x4cf32
movq %rbx, 0x18(%rsp)
movq 0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x228b5
movq %rax, %rbp
movq %rax, %rdi
callq 0x22913
testq %rax, %rax
leaq 0x49edf(%rip), %rbx     # 0x96d97
je 0x4cf25
movq (%rax), %r14
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movl $0x80, %esi
movq %r12, %rdi
movq %rbx, %rdx
movb $0x1, %al
callq 0x1f120
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x0, 0x60(%rsp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x4ca93
movq %r12, %rdi
callq 0x1f4f0
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4ca54
movl $0x14, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4c9cc
movq %rbp, %rdi
callq 0x22913
testq %rax, %rax
jne 0x4ceba
movq %rbp, %rdi
callq 0x229b9
movq 0x18(%rsp), %rbx
movq 0x8(%rsp), %r14
cmpq $-0x1, %r14
je 0x4cf51
movl $0xa, %edx
movq %r15, %rdi
leaq 0x4e1e4(%rip), %rsi     # 0x9b130
callq 0x4c9cc
movl $0x14, %edx
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x4c9cc
movq %rbx, %rdi
callq 0x30834
movq 0x38(%rsp), %rdi
callq 0x22913
movq %rax, %r14
testq %rax, %rax
jne 0x4cb7d
movq 0x38(%rsp), %rdi
callq 0x229b9
leaq 0x7d016(%rip), %rcx     # 0xc9fa8
movq 0x68(%rsp), %r14
incq %r14
movslq 0x480(%rcx), %rax
cmpq %rax, %r14
jl 0x4cb13
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4db56(%rip), %rdi     # 0x9ab19
leaq 0x4e15e(%rip), %rsi     # 0x9b128
movl $0xb7, %edx
callq 0x4d037
movl $0x1, %edi
callq 0x1f3b0
leaq 0x4a3ce(%rip), %rdi     # 0x973b3
leaq 0x4e13c(%rip), %rsi     # 0x9b128
movl $0xed, %edx
jmp 0x4d006
leaq 0x4a359(%rip), %rdi     # 0x97353
leaq 0x4e127(%rip), %rsi     # 0x9b128
movl $0xd8, %edx
callq 0x4d0e5
jmp 0x4cfd4
leaq 0x4c22b(%rip), %rdi     # 0x9923f
leaq 0x4e10d(%rip), %rsi     # 0x9b128
movl $0xb2, %edx
jmp 0x4cfcf
leaq 0x4c4d3(%rip), %rdi     # 0x994fc
leaq 0x4e0f8(%rip), %rsi     # 0x9b128
movl $0xb4, %edx
jmp 0x4cfcf