// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x3aee0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b687
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x3b940
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x3b170
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b6d6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %esi
callq 0x3b100
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b706
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
fldl 0x50(%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x3b380
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b73e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x58(%rax), %esi
callq 0x3b100
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b76e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x5c(%rax), %esi
callq 0x3b100
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b79e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movl %eax, %esi
callq 0x3b100
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b7d5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x13000
leaq -0x40(%rbp), %rdi
callq 0x13060
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x3b923
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq $0x8, %rsi
movl $0x28, %edx
callq 0x3b170
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b83f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
fldt 0x30(%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x3b380
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b877
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x3b080
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b8a8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
fldt 0x50(%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x3b380
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b8dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rcx
movq -0x28(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
fldt 0x60(%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x3b380
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
jne 0x3b912
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3b92a
movslq -0x1c(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3b7f2
movq -0x28(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)