// File: /workspace/github_c_makefile_star2_O2/erikdubbelboer[P]discnt/src/ddb.c
// Function: ddbLoadCounter
int ddbLoadCounter(rio *ddb) {
    uint32_t n, i;
    sds name = NULL;
    counter *cntr = NULL;

    if ((name = ddbLoadSds(ddb,name)) == NULL) return -1;

    cntr = counterCreate(name);

    if ((cntr->revision = ddbLoadLen(ddb)) == DDB_LENERR) goto rerr;

    if (ddbLoadDouble(ddb,&cntr->precision) == -1) goto rerr;

    if ((cntr->hits = ddbLoadLen(ddb)) == DDB_LENERR) goto rerr;

    if ((cntr->misses = ddbLoadLen(ddb)) == DDB_LENERR) goto rerr;

    if ((n = ddbLoadLen(ddb)) == DDB_LENERR) goto rerr;

    for (i = 0; i < n; i++) {
        clusterNode *node;
        shard* shrd;

        if ((name = ddbLoadSds(ddb,name)) == NULL) goto rerr;

        if (sdslen(name) != CLUSTER_NAMELEN) {
            goto rerr;
        }

        node = clusterLookupNode(name);
        shrd = counterAddShard(cntr, node, name);

        if (ddbLoadLongDouble(ddb,&shrd->value) == -1) goto rerr;

        if (ddbLoadLongLong(ddb,&shrd->predict_time) == -1) goto rerr;

        if (ddbLoadLongDouble(ddb,&shrd->predict_value) == -1) goto rerr;

        if (ddbLoadLongDouble(ddb,&shrd->predict_change) == -1) goto rerr;

        /* Resend the predicion we just loaded. We do this in case we broadcast a
         * new prediction before we saved. */
        if (node == myself) {
            shrd->predict_time = 0;
        }
    }

    /* Update the history to have no change */
    if (cntr->myshard != NULL) {
        for (i = 0; i < server.history_size; i++) {
            cntr->history[i] = cntr->myshard->value;
        }
    }

    sdsfree(name);

    return 0;

rerr:
    sdsfree(name);
    dictDelete(server.counters,cntr->name);

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
xorl %esi, %esi
callq 0x2af97
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0x2bafd
movq %rax, %rbx
movq %rax, %rdi
callq 0x29e31
movq %rax, %r14
movq %r15, %rdi
callq 0x2af1b
movl %eax, 0x38(%r14)
cmpl $-0x1, %eax
je 0x2badf
movq %r14, %rsi
addq $0x50, %rsi
movq %r15, %rdi
callq 0x2b1c3
cmpl $-0x1, %eax
je 0x2badf
movq %r15, %rdi
callq 0x2af1b
movl %eax, 0x58(%r14)
cmpl $-0x1, %eax
je 0x2badf
movq %r15, %rdi
callq 0x2af1b
movl %eax, 0x5c(%r14)
cmpl $-0x1, %eax
je 0x2badf
movq %r15, %rdi
callq 0x2af1b
cmpl $-0x1, %eax
je 0x2badf
movl %eax, %r12d
movq %r14, (%rsp)
subl $0x1, %r12d
jb 0x2ba9d
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2af97
testq %rax, %rax
je 0x2bada
movq %rax, %rbx
movq %rax, %rdi
callq 0x2b3b9
cmpq $0x28, %rax
jne 0x2badc
movq %rbx, %rdi
callq 0x25290
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x29ec0
movq %rax, %r14
leaq 0x30(%rax), %rsi
movq %r15, %rdi
callq 0x2b101
cmpl $-0x1, %eax
je 0x2ba97
leaq 0x40(%r14), %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2aed7
cmpl $-0x1, %eax
je 0x2ba97
leaq 0x50(%r14), %rsi
movq %r15, %rdi
callq 0x2b101
cmpl $-0x1, %eax
je 0x2ba97
addq $0x60, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x2b101
cmpl $-0x1, %eax
je 0x2ba97
leaq 0x52b20(%rip), %rax     # 0x7e5a0
cmpq (%rax), %r13
movq (%rsp), %r14
jne 0x2b9e0
andq $0x0, (%rbp)
jmp 0x2b9e0
movq (%rsp), %r14
jmp 0x2badc
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x2bace
leaq 0x3e5db(%rip), %rcx     # 0x6a088
movl 0x628(%rcx), %ecx
shlq $0x4, %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2bace
fldt 0x30(%rax)
movq 0x30(%r14), %rsi
fstpt (%rsi,%rdx)
addq $0x10, %rdx
jmp 0x2bab9
movq %rbx, %rdi
callq 0x19548
xorl %ebp, %ebp
jmp 0x2bafd
xorl %ebx, %ebx
pushq $-0x1
popq %rbp
movq %rbx, %rdi
callq 0x19548
leaq 0x3e59a(%rip), %rax     # 0x6a088
movq 0x618(%rax), %rdi
movq (%r14), %rsi
callq 0x14b54
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq