// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3b210
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x3c1ff
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c40e
movq -0x20(%rbp), %rdi
callq 0x39740
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3b130
movq -0x28(%rbp), %rcx
movl %eax, 0x38(%rcx)
cmpl $-0x1, %eax
jne 0x3c226
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x50, %rsi
callq 0x3b5f0
cmpl $-0x1, %eax
jne 0x3c241
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
callq 0x3b130
movq -0x28(%rbp), %rcx
movl %eax, 0x58(%rcx)
cmpl $-0x1, %eax
jne 0x3c25b
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
callq 0x3b130
movq -0x28(%rbp), %rcx
movl %eax, 0x5c(%rcx)
cmpl $-0x1, %eax
jne 0x3c275
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
callq 0x3b130
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x3c28b
jmp 0x3c3e4
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x3c388
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3b210
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x3c2ba
jmp 0x3c3e4
movq -0x20(%rbp), %rdi
callq 0x3b940
cmpq $0x28, %rax
je 0x3c2ce
jmp 0x3c3e4
movq -0x20(%rbp), %rdi
callq 0x31d30
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39810
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x30, %rsi
callq 0x3b490
cmpl $-0x1, %eax
jne 0x3c30b
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x40, %rsi
callq 0x3b0b0
cmpl $-0x1, %eax
jne 0x3c326
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x50, %rsi
callq 0x3b490
cmpl $-0x1, %eax
jne 0x3c341
jmp 0x3c3e4
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x60, %rsi
callq 0x3b490
cmpl $-0x1, %eax
jne 0x3c35c
jmp 0x3c3e4
movq -0x30(%rbp), %rax
leaq 0x97299(%rip), %rcx     # 0xd3600
cmpq (%rcx), %rax
jne 0x3c378
movq -0x38(%rbp), %rax
movq $0x0, 0x40(%rax)
jmp 0x3c37a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3c292
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x3c3d2
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
leaq 0x82d44(%rip), %rcx     # 0xbf0e8
cmpl 0x628(%rcx), %eax
jae 0x3c3d0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq 0x30(%rax), %rax
fldt 0x30(%rcx)
movl -0x18(%rbp), %ecx
shlq $0x4, %rcx
fstpt (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x3c39a
jmp 0x3c3d2
movq -0x20(%rbp), %rdi
callq 0x1e3c0
movl $0x0, -0x4(%rbp)
jmp 0x3c40e
movq -0x20(%rbp), %rdi
callq 0x1e3c0
leaq 0x82cf4(%rip), %rax     # 0xbf0e8
movq 0x618(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x16b60
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)