// File: /workspace/github_c_makefile_star2_O1/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
leaq 0x20(%rsp), %rsi
movb $0x0, (%rsi)
movl $0x1, %edx
callq 0x3254f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x32e0f
movl %eax, %ebp
movq (%r15), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x32c4f
leaq 0x25e42(%rip), %rcx     # 0x58a6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x32c51
movq -0x11(%rsi), %rdx
jmp 0x32c51
movzwl -0x5(%rsi), %edx
jmp 0x32c51
movl -0x9(%rsi), %edx
jmp 0x32c51
movzbl -0x3(%rsi), %edx
jmp 0x32c51
xorl %edx, %edx
movq %r14, %rdi
callq 0x327bc
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x32e0f
movl 0x38(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3254f
cmpl $-0x1, %eax
je 0x32e0f
movl %eax, %r13d
fldl 0x50(%r15)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32959
cmpl $-0x1, %eax
je 0x32e0f
movl %eax, 0x1c(%rsp)
movl 0x58(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3254f
cmpl $-0x1, %eax
je 0x32e0f
movl %eax, 0x18(%rsp)
movl 0x5c(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3254f
cmpl $-0x1, %eax
je 0x32e0f
movl %eax, 0x14(%rsp)
movq 0x8(%r15), %rax
movl 0x28(%rax), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x3254f
cmpl $-0x1, %eax
je 0x32e0f
movslq %r12d, %rcx
movl %ebp, %edx
movl %r13d, %esi
addq %rdx, %rsi
movl 0x1c(%rsp), %edx
addq %rsi, %rdx
movl 0x18(%rsp), %esi
addq %rdx, %rsi
movl 0x14(%rsp), %edx
addq %rsi, %rdx
addq %rcx, %rdx
movl %eax, %ebp
addq %rdx, %rbp
movq 0x8(%r15), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x16c72
movq %r15, %rdi
callq 0x16c8f
testq %rax, %rax
je 0x32e0d
movq 0x10(%rax), %r12
leaq 0x8(%r12), %rsi
movl $0x28, %edx
movq %r14, %rdi
callq 0x327bc
cmpl $-0x1, %eax
jne 0x32d80
xorl %eax, %eax
jmp 0x32e03
movslq %eax, %r13
addq %rbp, %r13
fldt 0x30(%r12)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32959
cmpl $-0x1, %eax
je 0x32dfe
movl %eax, %eax
addq %rax, %r13
movq 0x40(%r12), %rax
movq %rax, 0x30(%rsp)
movl $0x8, %edx
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3254f
cmpl $-0x1, %eax
je 0x32dfe
movl %eax, %eax
addq %rax, %r13
fldt 0x50(%r12)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32959
cmpl $-0x1, %eax
je 0x32dfe
movl %eax, %eax
addq %rax, %r13
fldt 0x60(%r12)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32959
cmpl $-0x1, %eax
je 0x32dfe
movl %eax, %eax
addq %rax, %r13
movb $0x1, %al
jmp 0x32e00
xorl %eax, %eax
movq %r13, %rbp
testb %al, %al
jne 0x32d4d
jmp 0x32e0f
movl %ebp, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq