// File: /workspace/github_c_makefile_star2_O1/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
subq $0x28, %rsp
movq %rdi, %r15
xorl %esi, %esi
callq 0x32822
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x335cc
movq %rax, %rbx
movq %rax, %rdi
callq 0x3134d
movq %rax, %r14
movq %r15, %rdi
callq 0x3272e
movl %eax, 0x38(%r14)
cmpl $-0x1, %eax
je 0x335ae
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x32a11
cmpl $-0x1, %eax
je 0x335ae
fldt 0x10(%rsp)
fstpl 0x50(%r14)
movq %r15, %rdi
callq 0x3272e
movl %eax, 0x58(%r14)
cmpl $-0x1, %eax
je 0x335ae
movq %r15, %rdi
callq 0x3272e
movl %eax, 0x5c(%r14)
cmpl $-0x1, %eax
je 0x335ae
movq %r15, %rdi
callq 0x3272e
cmpl $-0x1, %eax
je 0x335ae
movl %eax, %ebp
testl %eax, %eax
jne 0x3358f
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x334a9
leaq 0x3bc03(%rip), %rcx     # 0x6f088
movl 0x628(%rcx), %ecx
testq %rcx, %rcx
je 0x334a9
movq 0x30(%r14), %rdx
shlq $0x4, %rcx
xorl %esi, %esi
fldt 0x30(%rax)
fstpt (%rdx,%rsi)
addq $0x10, %rsi
cmpq %rsi, %rcx
jne 0x3349a
movq %rbx, %rdi
callq 0x1ded3
xorl %r12d, %r12d
jmp 0x335cc
movzbl -0x1(%rbx), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x334f3
leaq 0x255b2(%rip), %rdx     # 0x58a80
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x334f5
movq -0x11(%rbx), %rax
jmp 0x334f5
movzwl -0x5(%rbx), %eax
jmp 0x334f5
movl -0x9(%rbx), %eax
jmp 0x334f5
movzbl -0x3(%rbx), %eax
jmp 0x334f5
xorl %eax, %eax
cmpq $0x28, %rax
jne 0x335ae
movl %ebp, 0xc(%rsp)
movq %rbx, %rdi
callq 0x2bf3f
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x313de
movq %rax, %rbp
leaq 0x30(%rax), %rsi
movq %r15, %rdi
callq 0x32a11
cmpl $-0x1, %eax
je 0x335ae
leaq 0x40(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x32680
cmpl $-0x1, %eax
je 0x335a8
leaq 0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x32a11
cmpl $-0x1, %eax
je 0x335a8
addq $0x60, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x32a11
cmpl $-0x1, %eax
je 0x335a8
leaq 0x50030(%rip), %rax     # 0x835a0
cmpq (%rax), %r13
jne 0x3357d
movq $0x0, (%r12)
movl 0xc(%rsp), %ebp
decl %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
je 0x33475
movq %r15, %rdi
movq %rbx, %rsi
callq 0x32822
movq %rax, %rbx
testq %rax, %rax
jne 0x334b9
jmp 0x335ae
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x1ded3
leaq 0x3bacb(%rip), %rax     # 0x6f088
movq 0x618(%rax), %rdi
movq (%r14), %rsi
callq 0x18e09
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq