// File: /workspace/github_c_makefile_star2_O3/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 0x32225
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x32f5f
movq %rax, %rbx
movq %rax, %rdi
callq 0x30d95
movq %rax, %r14
movq %r15, %rdi
callq 0x3214d
movl %eax, 0x38(%r14)
cmpl $-0x1, %eax
je 0x32f41
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x323ea
cmpl $-0x1, %eax
je 0x32f41
fldt 0x10(%rsp)
fstpl 0x50(%r14)
movq %r15, %rdi
callq 0x3214d
movl %eax, 0x58(%r14)
cmpl $-0x1, %eax
je 0x32f41
movq %r15, %rdi
callq 0x3214d
movl %eax, 0x5c(%r14)
cmpl $-0x1, %eax
je 0x32f41
movq %r15, %rdi
callq 0x3214d
cmpl $-0x1, %eax
je 0x32f41
movl %eax, %ebp
testl %eax, %eax
jne 0x32f23
movq 0x10(%r14), %rdx
testq %rdx, %rdx
fldz
je 0x32e3d
fstp %st(0)
leaq 0x3c275(%rip), %rax     # 0x6f088
movl 0x628(%rax), %eax
testq %rax, %rax
fldz
je 0x32e3d
fstp %st(0)
movq 0x30(%r14), %rcx
fldt 0x30(%rdx)
shlq $0x4, %rax
xorl %edx, %edx
fld %st(0)
fstpt (%rcx,%rdx)
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x32e2f
fstp %st(0)
movq %rbx, %rdi
callq 0x1dc25
xorl %r12d, %r12d
jmp 0x32f5f
movq %rax, %rbx
movzbl -0x1(%rax), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x32f41
leaq 0x25c05(%rip), %rcx     # 0x58a70
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x3(%rbx), %eax
jmp 0x32e89
movl -0x9(%rbx), %eax
jmp 0x32e89
movq -0x11(%rbx), %rax
jmp 0x32e89
movzwl -0x5(%rbx), %eax
cmpq $0x28, %rax
jne 0x32f41
movl %ebp, 0xc(%rsp)
movq %rbx, %rdi
callq 0x2b952
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x30e26
movq %rax, %rbp
leaq 0x30(%rax), %rsi
movq %r15, %rdi
callq 0x323ea
cmpl $-0x1, %eax
je 0x32f41
leaq 0x40(%rbp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x320b3
cmpl $-0x1, %eax
je 0x32f3b
leaq 0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x323ea
cmpl $-0x1, %eax
je 0x32f3b
addq $0x60, %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x323ea
cmpl $-0x1, %eax
je 0x32f3b
leaq 0x5069c(%rip), %rax     # 0x835a0
cmpq (%rax), %r13
jne 0x32f11
movq $0x0, (%r12)
movl 0xc(%rsp), %ebp
decl %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
je 0x32dff
movq %r15, %rdi
movq %rbx, %rsi
callq 0x32225
testq %rax, %rax
jne 0x32e4f
xorl %ebx, %ebx
jmp 0x32f41
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x1dc25
leaq 0x3c138(%rip), %rax     # 0x6f088
movq 0x618(%rax), %rdi
movq (%r14), %rsi
callq 0x18a7c
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq