// File: /workspace/github_c_makefile_star2_O3/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 $0x158, %rsp            # imm = 0x158
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, 0x30(%rsp)
movl $0x0, 0x10(%rdi)
leaq 0xa057e(%rip), %rax     # 0x1018a8
movl 0x610(%rax), %eax
testl %eax, %eax
jle 0x6187b
leaq 0xa0569(%rip), %rcx     # 0x1018a8
movq 0x28(%rcx), %rcx
movq %rcx, 0x10(%rsp)
xorl %ebx, %ebx
leaq 0x70(%rsp), %r15
leaq 0x90(%rsp), %rbp
movq %rbx, %r12
shlq $0x6, %r12
movq 0x10(%rsp), %rcx
movq (%rcx,%r12), %rdi
movq 0x28(%rdi), %rcx
addq 0x48(%rdi), %rcx
je 0x6186c
callq 0x2efe5
movq %rax, %r13
movq %rbx, 0x50(%rsp)
movl %ebx, %eax
bswapl %eax
movl %eax, 0xc(%rsp)
movl $0x4, %edx
movq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x61258
movq %r13, 0x38(%rsp)
movq %r13, %rdi
callq 0x2f015
testq %rax, %rax
je 0x61847
movq %rax, %rbx
addq %r12, 0x10(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movl $0x0, 0x80(%rsp)
movq (%rbx), %r13
movzbl -0x1(%r13), %esi
movl %esi, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x61410
leaq 0x64b0c(%rip), %rcx     # 0xc5ef4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %esi
jmp 0x61412
movq -0x11(%r13), %rsi
jmp 0x61412
movzwl -0x5(%r13), %esi
jmp 0x61412
movl -0x9(%r13), %esi
jmp 0x61412
movzbl -0x3(%r13), %esi
jmp 0x61412
xorl %esi, %esi
movq %r13, %rdi
callq 0x40744
movq %rax, 0x40(%rsp)
movzbl -0x1(%r13), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
leaq 0x5eb7c(%rip), %r12     # 0xbffaf
ja 0x61464
leaq 0x64acc(%rip), %rcx     # 0xc5f08
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x61466
movq -0x11(%r13), %rdx
jmp 0x61466
movzwl -0x5(%r13), %edx
jmp 0x61466
movl -0x9(%r13), %edx
jmp 0x61466
movzbl -0x3(%r13), %edx
jmp 0x61466
xorl %edx, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x61258
movq 0x8(%rbx), %r13
movl (%r13), %eax
andl $0xf, %eax
shll $0x18, %eax
movl %eax, 0xc(%rsp)
movl $0x4, %edx
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0x61258
movq 0x10(%rsp), %rdi
movq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x4302f
movq %rax, %r14
movl (%r13), %eax
movl %eax, %ecx
andl $0xf, %ecx
cmpl $0x4, %ecx
ja 0x618af
leaq 0x64a59(%rip), %rdx     # 0xc5f1c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %r15, %rdi
movq %r13, %rsi
callq 0x61297
jmp 0x617fd
movq %r13, %rdi
callq 0x55c77
movq %rax, %r13
movq %rax, %rdi
callq 0x55d03
cmpl $-0x1, %eax
xorps %xmm0, %xmm0
je 0x61570
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq %r13, %rdi
movl $0x1, %esi
callq 0x55eb7
movq %rax, %r12
movq %rbp, %rdi
movq %rax, %rsi
callq 0x61297
movq %r12, %rdi
callq 0x40c8f
movq %r13, %rdi
movl $0x2, %esi
callq 0x55eb7
movq %rax, %r12
movq %rbp, %rdi
movq %rax, %rsi
callq 0x61297
movq %r12, %rdi
callq 0x40c8f
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x61160
movq %r13, %rdi
callq 0x55d03
xorps %xmm0, %xmm0
cmpl $-0x1, %eax
jne 0x614f7
movq %r13, %rdi
callq 0x55ce7
jmp 0x617fd
movq %r13, %rdi
callq 0x4e3b6
movq %rax, %r13
movq %rax, %rdi
callq 0x4e4cf
testq %rax, %rax
je 0x615bb
movq %rax, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x611b7
movq %r12, %rdi
callq 0x40c8f
movq %r13, %rdi
callq 0x4e4cf
movq %rax, %r12
testq %rax, %rax
jne 0x61598
movq %r13, %rdi
callq 0x4e426
jmp 0x617fd
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x7, %eax
movq %r14, 0x28(%rsp)
je 0x61753
cmpl $0x5, %eax
jne 0x618c4
movq 0x8(%r13), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x3b680
movq %rax, 0x18(%rsp)
testq %rax, %rax
leaq 0xd0(%rsp), %r14
je 0x618de
movq %r13, %rdi
movq %rax, %rsi
callq 0x3b745
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x618f3
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x617f8
leaq 0x68(%rsp), %rsi
leaq 0x24(%rsp), %rdx
leaq 0x60(%rsp), %rcx
callq 0x3b7cf
testl %eax, %eax
je 0x6188d
movq 0x48(%rsp), %rdi
callq 0x50d7b
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq 0x68(%rsp), %rsi
testq %rsi, %rsi
je 0x61685
movl 0x24(%rsp), %edx
movq %rbp, %rdi
jmp 0x616a8
movq 0x60(%rsp), %rdx
movl $0x80, %esi
movq %r14, %rdi
callq 0x3ff83
movq %r14, %rdi
callq 0x26500
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x61258
movl $0x80, %esi
movq %r14, %rdi
movq %r12, %rdx
movsd 0x58(%rsp), %xmm0
movb $0x1, %al
callq 0x26120
movq %r14, %rdi
callq 0x26500
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x61258
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x61160
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x50f41
jmp 0x61622
movq %r13, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x4c4e8
movq %rax, %r13
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4c580
testl %eax, %eax
je 0x61746
movq %rbp, %rdi
callq 0x4c5e5
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
callq 0x61297
movq %r12, %rdi
callq 0x40c8f
movq %r13, %rdi
jmp 0x61717
movq %r13, %rdi
callq 0x4c56a
jmp 0x617fd
movq 0x8(%r13), %rax
movq (%rax), %rdi
callq 0x2efbb
movq %rax, %r13
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
leaq 0xd0(%rsp), %r14
je 0x617eb
movq %r12, %rbx
movq (%rax), %r12
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movl $0x80, %esi
movq %r14, %rdi
movq %rbx, %rdx
movb $0x1, %al
callq 0x26120
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movl $0x0, 0xa0(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x61297
movq %r14, %rdi
callq 0x26500
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x61258
movl $0x14, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x61160
movq %r13, %rdi
callq 0x2f015
testq %rax, %rax
jne 0x6177a
movq %r13, %rdi
callq 0x2f0dd
movq 0x40(%rsp), %rbx
movq 0x28(%rsp), %r14
cmpq $-0x1, %r14
je 0x61817
movl $0xa, %edx
movq %r15, %rdi
leaq 0x64772(%rip), %rsi     # 0xc5f84
callq 0x61160
movl $0x14, %edx
movq 0x30(%rsp), %rdi
movq %r15, %rsi
callq 0x61160
movq %rbx, %rdi
callq 0x40c8f
movq 0x38(%rsp), %rdi
callq 0x2f015
movq %rax, %rbx
testq %rax, %rax
jne 0x613bc
movq 0x38(%rsp), %rdi
callq 0x2f0dd
leaq 0xa0050(%rip), %rax     # 0x1018a8
movq 0x28(%rax), %rcx
movq %rcx, 0x10(%rsp)
movl 0x610(%rax), %eax
movq 0x50(%rsp), %rbx
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x61357
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x63ed0(%rip), %rdi     # 0xc5764
leaq 0x646e1(%rip), %rsi     # 0xc5f7c
movl $0xbf, %edx
callq 0x61908
movl $0x1, %edi
callq 0x263c0
leaq 0x5f470(%rip), %rdi     # 0xc0d26
leaq 0x646bf(%rip), %rsi     # 0xc5f7c
movl $0xf5, %edx
jmp 0x618d7
leaq 0x5f3fb(%rip), %rdi     # 0xc0cc6
leaq 0x646aa(%rip), %rsi     # 0xc5f7c
movl $0xe0, %edx
callq 0x619b4
jmp 0x618a5
leaq 0x61e7a(%rip), %rdi     # 0xc375f
leaq 0x64690(%rip), %rsi     # 0xc5f7c
movl $0xba, %edx
jmp 0x618a0
leaq 0x6218c(%rip), %rdi     # 0xc3a86
leaq 0x6467b(%rip), %rsi     # 0xc5f7c
movl $0xbc, %edx
jmp 0x618a0