// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/cluster.c
// Function: clusterSendShardToNode
void clusterSendShardToNode(counter *cntr, clusterNode *node) {
    unsigned char buf[sizeof(clusterMsg) + 64], *payload;
    clusterMsg *hdr = (clusterMsg*) buf;
    uint32_t totlen;

    if (node->link == NULL) return;

    totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
    totlen += sizeof(clusterMsgDataCounter) - sizeof(hdr->data.counter.shard.name);
    totlen += sdslen(cntr->name);

    clusterBuildMessageHdr(hdr,CLUSTERMSG_TYPE_COUNTER);
    hdr->totlen = htonl(totlen);

    hdr->data.counter.shard.revision       = intrev32ifbe(cntr->revision);
    hdr->data.counter.shard.predict_time   = intrev64ifbe(cntr->myshard->predict_time);
    hdr->data.counter.shard.predict_value  = intrev64ifbe(pack754(cntr->myshard->predict_value, 64, 11));
    hdr->data.counter.shard.predict_change = intrev64ifbe(pack754(cntr->myshard->predict_change, 64, 11));
    hdr->data.counter.shard.name_length    = intrev16ifbe(sdslen(cntr->name));

    if (totlen < sizeof(buf)) {
        payload = buf;
    } else {
        payload = zmalloc(totlen);
        memcpy(payload,buf,sizeof(clusterMsg));
        hdr = (clusterMsg*) payload;

        serverLog(LL_DEBUG,"Need to resize payload buffer to %u bytes for counter for %s",
            totlen, cntr->name);
    }

    memcpy(hdr->data.counter.shard.name, cntr->name, sdslen(cntr->name));

    clusterSendMessage(node->link,payload,totlen);

    if (totlen >= sizeof(buf)) {
        zfree(payload);
    }
}

// Assembly:
cmpq $0x0, 0x88(%rsi)
je 0x2ed10
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x120, %rsp            # imm = 0x120
movq %rsi, %rbx
movq %rdi, %r12
movq (%rdi), %rax
movzbl -0x1(%rax), %r14d
movl %r14d, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2eb35
leaq 0x27e80(%rip), %rdx     # 0x5698c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %r14d
jmp 0x2eb38
movq -0x11(%rax), %r14
jmp 0x2eb38
movzwl -0x5(%rax), %r14d
jmp 0x2eb38
movl -0x9(%rax), %r14d
jmp 0x2eb38
movzbl -0x3(%rax), %r14d
jmp 0x2eb38
xorl %r14d, %r14d
addl $0x7e, %r14d
leaq 0x10(%rsp), %r15
xorl %r13d, %r13d
movl $0xc8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x12380
movl $0x5a756244, (%r15)     # imm = 0x5A756244
movw $0x400, 0xc(%r15)       # imm = 0x400
movq 0x54a38(%rip), %rax     # 0x835a0
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm0, 0x10(%r15)
movaps %xmm1, 0x20(%r15)
movq 0x20(%rax), %rcx
movq %rcx, 0x30(%r15)
leaq 0x40500(%rip), %rcx     # 0x6f088
movzwl 0xb4(%rcx), %edx
rolw $0x8, %dx
movw %dx, 0x58(%r15)
movzwl 0x30(%rax), %eax
rolw $0x8, %ax
movw %ax, 0x5a(%r15)
movq 0x668(%rcx), %rax
movb 0x8(%rax), %al
movb %al, 0x5c(%r15)
movl %r14d, %eax
bswapl %eax
movl %eax, 0x4(%r15)
movl 0x38(%r12), %eax
movl %eax, 0x78(%r15)
movq 0x10(%r12), %rax
movq 0x40(%rax), %rcx
movq %rcx, 0x60(%r15)
fldt 0x50(%rax)
fstpt (%rsp)
movl $0x40, %edi
movl $0xb, %esi
callq 0x2f070
movq %rax, 0x68(%r15)
movq 0x10(%r12), %rax
fldt 0x60(%rax)
fstpt (%rsp)
movl $0x40, %edi
movl $0xb, %esi
callq 0x2f070
movq %rax, 0x70(%r15)
movq (%r12), %rcx
movzbl -0x1(%rcx), %eax
movl %eax, %edx
andl $0x7, %edx
cmpl $0x4, %edx
ja 0x2ec4b
leaq 0x27d7e(%rip), %rsi     # 0x569a0
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
shrl $0x3, %eax
movq %rax, %r13
jmp 0x2ec4b
movq -0x11(%rcx), %r13
jmp 0x2ec4b
movzwl -0x5(%rcx), %r13d
jmp 0x2ec4b
movl -0x9(%rcx), %r13d
jmp 0x2ec4b
movzbl -0x3(%rcx), %r13d
movw %r13w, 0x8c(%rsp)
movl %r14d, %r13d
cmpl $0x108, %r14d           # imm = 0x108
jb 0x2ec94
movq %r13, %rdi
callq 0x1fea5
movq %rax, %r15
leaq 0x10(%rsp), %rsi
movl $0xc8, %edx
movq %rax, %rdi
callq 0x12520
movq (%r12), %rcx
leaq 0x286c5(%rip), %rsi     # 0x5734d
xorl %edi, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x19fb1
leaq 0x7e(%r15), %rdi
movq (%r12), %rsi
movzbl -0x1(%rsi), %edx
movl %edx, %eax
andl $0x7, %eax
cmpl $0x4, %eax
ja 0x2ecd6
leaq 0x27d03(%rip), %rcx     # 0x569b4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x3, %edx
jmp 0x2ecd8
movq -0x11(%rsi), %rdx
jmp 0x2ecd8
movzwl -0x5(%rsi), %edx
jmp 0x2ecd8
movl -0x9(%rsi), %edx
jmp 0x2ecd8
movzbl -0x3(%rsi), %edx
jmp 0x2ecd8
xorl %edx, %edx
callq 0x12520
movq 0x88(%rbx), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2dec0
cmpl $0x108, %r14d           # imm = 0x108
jb 0x2ed00
movq %r15, %rdi
callq 0x1ffff
addq $0x120, %rsp            # imm = 0x120
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq