// File: /workspace/github_c_makefile_star2_O2/erikdubbelboer[P]discnt/src/ddb.c
// Function: ddbSaveCounter
int ddbSaveCounter(rio *ddb, const counter* cntr) {
    int n;
    size_t nwritten = 0;
    listNode *ln;
    listIter li;

    if ((n = ddbSaveType(ddb,DDB_TYPE_COUNTER)) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveRawString(ddb,(unsigned char*)cntr->name,sdslen(cntr->name))) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveLen(ddb,cntr->revision)) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveLongDouble(ddb,cntr->precision)) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveLen(ddb,cntr->hits)) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveLen(ddb,cntr->misses)) == -1) return -1;
    nwritten += n;

    if ((n = ddbSaveLen(ddb,listLength(cntr->shards))) == -1) return -1;
    nwritten += n;

    listRewind(cntr->shards,&li);
    while ((ln = listNext(&li)) != NULL) {
        shard *shrd = listNodeValue(ln);

        /* We save the exact same information independent if it's our or another shard. */

        if ((n = ddbSaveRawString(ddb,(unsigned char*)shrd->node_name, CLUSTER_NAMELEN)) == -1) return -1;
        nwritten += n;

        if ((n = ddbSaveLongDouble(ddb,shrd->value)) == -1) return -1;
        nwritten += n;

        if ((n = ddbSaveLongLong(ddb,shrd->predict_time)) == -1) return -1;
        nwritten += n;

        if ((n = ddbSaveLongDouble(ddb,shrd->predict_value)) == -1) return -1;
        nwritten += n;

        if ((n = ddbSaveLongDouble(ddb,shrd->predict_change)) == -1) return -1;
        nwritten += n;
    }

    return nwritten;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movq %rdi, %r14
xorl %esi, %esi
callq 0x2adf3
pushq $-0x1
popq %rbx
cmpl $-0x1, %eax
je 0x2b3a6
movl %eax, %ebp
movq (%r15), %r12
movq %r12, %rdi
callq 0x2b3b9
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2af42
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x2b3a6
movl 0x38(%r15), %esi
movq %r14, %rdi
callq 0x2af06
cmpl $-0x1, %eax
je 0x2b3a6
movl %eax, %r13d
fldl 0x50(%r15)
fstpt (%rsp)
movq %r14, %rdi
callq 0x2b04d
cmpl $-0x1, %eax
je 0x2b3a6
movl %eax, 0x18(%rsp)
movl 0x58(%r15), %esi
movq %r14, %rdi
callq 0x2af06
cmpl $-0x1, %eax
je 0x2b3a6
movl %eax, 0x24(%rsp)
movl 0x5c(%r15), %esi
movq %r14, %rdi
callq 0x2af06
cmpl $-0x1, %eax
je 0x2b3a6
movl %eax, 0x20(%rsp)
movq 0x8(%r15), %rax
movl 0x28(%rax), %esi
movq %r14, %rdi
callq 0x2af06
cmpl $-0x1, %eax
je 0x2b3a6
movslq %r12d, %rcx
movl %ebp, %edx
movl %r13d, %esi
addq %rdx, %rsi
addq %rcx, %rsi
movl 0x18(%rsp), %ecx
movl 0x24(%rsp), %edx
addq %rcx, %rdx
movl 0x20(%rsp), %ecx
addq %rdx, %rcx
addq %rsi, %rcx
movl %eax, %ebx
addq %rcx, %rbx
movq 0x8(%r15), %rdi
leaq 0x28(%rsp), %rsi
callq 0x12d0c
leaq 0x28(%rsp), %rdi
callq 0x12d26
testq %rax, %rax
je 0x2b3b7
movq 0x10(%rax), %r13
leaq 0x8(%r13), %rsi
movq %r14, %rdi
pushq $0x28
popq %rdx
callq 0x2af42
movq %rax, %r15
cmpl $-0x1, %r15d
je 0x2b3a3
fldt 0x30(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x2b04d
cmpl $-0x1, %eax
je 0x2b3a3
movl %eax, %ebp
movq 0x40(%r13), %rsi
movq %r14, %rdi
callq 0x2aec3
cmpl $-0x1, %eax
je 0x2b3a3
movl %eax, %r12d
movq %rbx, 0x18(%rsp)
movq %r15, %rbx
fldt 0x50(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x2b04d
cmpl $-0x1, %eax
je 0x2b3a3
movl %eax, %r15d
fldt 0x60(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x2b04d
cmpl $-0x1, %eax
je 0x2b3a3
movslq %ebx, %rcx
movl %ebp, %edx
movq 0x18(%rsp), %rsi
addq %rdx, %rsi
addq %rcx, %rsi
movl %r12d, %ecx
movl %r15d, %edx
addq %rsi, %rdx
movl %eax, %ebx
addq %rdx, %rbx
addq %rcx, %rbx
jmp 0x2b2ed
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2b3a6