// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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 $0x148, %rsp            # imm = 0x148
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x28(%rsp)
andl $0x0, 0x10(%rdi)
leaq 0xa22f7(%rip), %rsi     # 0xf98a8
movl 0x610(%rsi), %eax
xorl %r15d, %r15d
pushq $0x14
popq %r13
leaq 0x80(%rsp), %r14
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x57a3d
movq 0x28(%rsi), %r8
movq %r15, %rcx
shlq $0x6, %rcx
movq (%r8,%rcx), %rdi
movq 0x28(%rdi), %rdx
addq 0x48(%rdi), %rdx
je 0x57a35
addq %rcx, %r8
movq %r8, 0x50(%rsp)
callq 0x2a9c4
movq %rax, 0x30(%rsp)
movq %r15, 0x48(%rsp)
movl %r15d, %eax
bswapl %eax
movl %eax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x57513
movq 0x30(%rsp), %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x57a19
movq %rax, %rbp
movq %r13, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andl $0x0, 0x20(%rsp)
movq (%rax), %r15
movq %r15, %rdi
callq 0x574db
movq %r15, %rdi
movq %rax, %rsi
callq 0x39e29
movq %rax, %r13
movq %r15, %rdi
callq 0x574db
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x57513
movq 0x8(%rbp), %rbp
movl (%rbp), %eax
andl $0xf, %eax
shll $0x18, %eax
movl %eax, 0x8(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x57513
movq 0x50(%rsp), %rdi
movq %r13, 0x60(%rsp)
movq %r13, %rsi
callq 0x3c0d3
movl (%rbp), %esi
movl %esi, %ecx
andl $0xf, %ecx
cmpl $0x4, %ecx
ja 0x57a6f
leaq 0x5faba(%rip), %rdx     # 0xb7180
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
movq %rbx, %r13
movq %rax, 0x58(%rsp)
jmpq *%rcx
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x57550
jmp 0x579e0
movq %rbp, %rdi
callq 0x4cd29
movq %rax, %rbp
leaq 0x10(%rsp), %r12
movq %rbp, %rdi
callq 0x4cdb1
cmpl $-0x1, %eax
je 0x5776e
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andl $0x0, 0x90(%rsp)
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x4cf5d
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x57550
movq %r15, %rdi
callq 0x3a265
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x4cf5d
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x57550
movq %r15, %rdi
callq 0x3a265
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x57448
jmp 0x576fc
movq %rbp, %rdi
callq 0x4cd95
jmp 0x579e0
movq %rbp, %rdi
callq 0x45fc4
movq %rax, %rbp
leaq 0x10(%rsp), %r12
movq %rbp, %rdi
callq 0x460cf
testq %rax, %rax
je 0x577b0
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x574a1
movq %r15, %rdi
callq 0x3a265
jmp 0x5778b
movq %rbp, %rdi
callq 0x4602d
jmp 0x579e0
shrl $0x4, %esi
andl $0xf, %esi
cmpl $0x7, %esi
je 0x5794a
cmpl $0x5, %esi
leaq 0xc0(%rsp), %rbx
jne 0x57aae
movq 0x8(%rbp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x35aca
movq %rax, 0x40(%rsp)
testq %rax, %rax
leaq 0x78(%rsp), %r15
leaq 0x10(%rsp), %r12
je 0x57a99
movq %rbp, %rdi
movq %rax, %rsi
callq 0x35b60
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x57a84
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x579e0
movq %r15, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x70(%rsp), %rcx
callq 0x35be8
testl %eax, %eax
je 0x57a4f
movq 0x38(%rsp), %rdi
callq 0x48535
andl $0x0, 0x90(%rsp)
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq 0x78(%rsp), %rsi
testq %rsi, %rsi
je 0x5787a
movl 0xc(%rsp), %edx
movq %r14, %rdi
jmp 0x5789d
movq 0x70(%rsp), %rdx
movl $0x80, %esi
movq %rbx, %rdi
callq 0x39796
movq %rbx, %rdi
callq 0x26500
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x57513
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x5a0a2(%rip), %rdx     # 0xb1953
movsd 0x68(%rsp), %xmm0
movb $0x1, %al
callq 0x26120
movq %rbx, %rdi
callq 0x26500
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x57513
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x57448
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x486f3
jmp 0x5781c
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x442b8
movq %rax, %rbp
leaq 0x10(%rsp), %r12
movq %rbp, %rdi
movq %r14, %rsi
callq 0x44347
testl %eax, %eax
je 0x5793d
movq %r14, %rdi
callq 0x443a6
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x57550
movq %r15, %rdi
callq 0x3a265
jmp 0x5790e
movq %rbp, %rdi
callq 0x44331
jmp 0x579e0
movq 0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x2a99f
movq %rax, %rbp
leaq 0xc0(%rsp), %rbx
leaq 0x10(%rsp), %r12
movq %rbp, %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x579d8
movq (%rax), %r15
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movl $0x80, %esi
movq %rbx, %rdi
leaq 0x59fc6(%rip), %rdx     # 0xb1953
movb $0x1, %al
callq 0x26120
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
andl $0x0, 0x90(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x57550
movq %rbx, %rdi
callq 0x26500
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x57513
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x57448
jmp 0x57966
movq %rbp, %rdi
callq 0x2aa94
cmpq $-0x1, 0x58(%rsp)
je 0x579fa
movq %r12, %rdi
leaq 0x5f7ce(%rip), %rsi     # 0xb71c0
pushq $0xa
popq %rdx
callq 0x57448
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x57448
movq 0x60(%rsp), %rdi
callq 0x3a265
jmp 0x57621
movq 0x30(%rsp), %rdi
callq 0x2aa94
leaq 0xa1e7e(%rip), %rsi     # 0xf98a8
movl 0x610(%rsi), %eax
movq 0x48(%rsp), %r15
incq %r15
jmp 0x575c6
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5effa(%rip), %rdi     # 0xb6a50
leaq 0x5f75b(%rip), %rsi     # 0xb71b8
movl $0xbf, %edx
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0
leaq 0x5ab88(%rip), %rdi     # 0xb25fe
leaq 0x5f73b(%rip), %rsi     # 0xb71b8
movl $0xf5, %edx
jmp 0x57ac1
leaq 0x5d477(%rip), %rdi     # 0xb4f02
leaq 0x5f726(%rip), %rsi     # 0xb71b8
movl $0xbc, %edx
jmp 0x57a62
leaq 0x5d13b(%rip), %rdi     # 0xb4bdb
leaq 0x5f711(%rip), %rsi     # 0xb71b8
movl $0xba, %edx
jmp 0x57a62
leaq 0x5aae9(%rip), %rdi     # 0xb259e
leaq 0x5f6fc(%rip), %rsi     # 0xb71b8
movl $0xe0, %edx
callq 0x57b45
jmp 0x57a67