// File: /workspace/github_c_makefile_star2_O3/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 0x31fab
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x327bb
movl %eax, %ebp
movq (%r15), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x325f0
leaq 0x26491(%rip), %rcx     # 0x58a5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x325f2
movq -0x11(%rsi), %rdx
jmp 0x325f2
movzwl -0x5(%rsi), %edx
jmp 0x325f2
movl -0x9(%rsi), %edx
jmp 0x325f2
movzbl -0x3(%rsi), %edx
jmp 0x325f2
xorl %edx, %edx
movq %r14, %rdi
callq 0x321bf
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x327bb
movl 0x38(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x31fab
cmpl $-0x1, %eax
je 0x327bb
movl %eax, %r13d
fldl 0x50(%r15)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32332
cmpl $-0x1, %eax
je 0x327bb
movl %eax, 0x14(%rsp)
movl 0x58(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x31fab
cmpl $-0x1, %eax
je 0x327bb
movl %eax, 0x1c(%rsp)
movl 0x5c(%r15), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x31fab
cmpl $-0x1, %eax
je 0x327bb
movl %eax, 0x18(%rsp)
movq 0x8(%r15), %rax
movl 0x28(%rax), %eax
leaq 0x20(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x31fab
cmpl $-0x1, %eax
je 0x327bb
movslq %r12d, %rcx
movl %ebp, %edx
movl %r13d, %esi
addq %rdx, %rsi
movl 0x14(%rsp), %edx
addq %rsi, %rdx
movl 0x1c(%rsp), %esi
addq %rdx, %rsi
movl 0x18(%rsp), %edx
addq %rsi, %rdx
addq %rcx, %rdx
movl %eax, %ebx
addq %rdx, %rbx
movq 0x8(%r15), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x16717
movq %r15, %rdi
callq 0x16734
testq %rax, %rax
je 0x327bb
movq 0x10(%rax), %r13
leaq 0x8(%r13), %rsi
movl $0x28, %edx
movq %r14, %rdi
callq 0x321bf
movq %rax, %r15
cmpl $-0x1, %r15d
je 0x327b4
fldt 0x30(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32332
cmpl $-0x1, %eax
je 0x327b4
movl %eax, %ebp
movq 0x40(%r13), %rax
movq %rax, 0x30(%rsp)
movl $0x8, %edx
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x31fab
cmpl $-0x1, %eax
je 0x327b4
movl %eax, %r12d
movl %ebp, 0x14(%rsp)
movq %r15, %rbp
fldt 0x50(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32332
cmpl $-0x1, %eax
je 0x327b4
movl %eax, %r15d
fldt 0x60(%r13)
fstpt (%rsp)
movq %r14, %rdi
callq 0x32332
cmpl $-0x1, %eax
je 0x327b4
movslq %ebp, %rcx
movl 0x14(%rsp), %edx
addq %rdx, %rbx
movl %r12d, %edx
addq %rbx, %rdx
movl %r15d, %esi
addq %rdx, %rsi
movl %eax, %ebx
addq %rsi, %rbx
addq %rcx, %rbx
leaq 0x20(%rsp), %rdi
jmp 0x326f1
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x327bb
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq