// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/cluster.c
// Function: clusterBuildMessageHdr
void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
    int totlen = 0;
    uint64_t offset;
    clusterNode *master;

    /* If this node is a master, we send its slots bitmap and configEpoch.
     * If this node is a slave we send the master's information instead (the
     * node is flagged as slave so the receiver knows that it is NOT really
     * in charge for this slots. */
    master = (nodeIsSlave(myself) && myself->slaveof) ?
              myself->slaveof : myself;

    memset(hdr,0,sizeof(*hdr));
    hdr->ver = htons(CLUSTER_PROTO_VER);
    hdr->sig[0] = 'R';
    hdr->sig[1] = 'C';
    hdr->sig[2] = 'm';
    hdr->sig[3] = 'b';
    hdr->type = htons(type);
    memcpy(hdr->sender,myself->name,CLUSTER_NAMELEN);

    memcpy(hdr->myslots,master->slots,sizeof(hdr->myslots));
    memset(hdr->slaveof,0,CLUSTER_NAMELEN);
    if (myself->slaveof != NULL)
        memcpy(hdr->slaveof,myself->slaveof->name, CLUSTER_NAMELEN);
    hdr->port = htons(server.port);
    hdr->flags = htons(myself->flags);
    hdr->state = server.cluster->state;

    /* Set the currentEpoch and configEpochs. */
    hdr->currentEpoch = htonu64(server.cluster->currentEpoch);
    hdr->configEpoch = htonu64(master->configEpoch);

    /* Set the replication offset. */
    if (nodeIsSlave(myself))
        offset = replicationGetSlaveOffset();
    else
        offset = server.master_repl_offset;
    hdr->offset = htonu64(offset);

    /* Set the message flags. */
    if (nodeIsMaster(myself) && server.cluster->mf_end)
        hdr->mflags[0] |= CLUSTERMSG_FLAG0_PAUSED;

    /* Compute the message length for certain messages. For other messages
     * this is up to the caller. */
    if (type == CLUSTERMSG_TYPE_FAIL) {
        totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
        totlen += sizeof(clusterMsgDataFail);
    } else if (type == CLUSTERMSG_TYPE_UPDATE) {
        totlen = sizeof(clusterMsg)-sizeof(union clusterMsgData);
        totlen += sizeof(clusterMsgDataUpdate);
    }
    hdr->totlen = htonl(totlen);
    /* For PING, PONG, and MEET, fixing the totlen field is up to the caller. */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq 0x10b973(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x8121d
movq 0x10b961(%rip), %rax    # 0x18cb60
cmpq $0x0, 0x850(%rax)
je 0x8121d
movq 0x10b950(%rip), %rax    # 0x18cb60
movq 0x850(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x81228
movq 0x10b93c(%rip), %rax    # 0x18cb60
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x10d0, %edx           # imm = 0x10D0
callq 0x26110
xorl %edi, %edi
callq 0x26280
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x8(%rbp), %rax
movb $0x52, (%rax)
movq -0x8(%rbp), %rax
movb $0x43, 0x1(%rax)
movq -0x8(%rbp), %rax
movb $0x6d, 0x2(%rax)
movq -0x8(%rbp), %rax
movb $0x62, 0x3(%rax)
movl -0xc(%rbp), %eax
movzwl %ax, %edi
callq 0x26280
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc(%rax)
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
movq 0x10b8ca(%rip), %rsi    # 0x18cb60
addq $0x8, %rsi
movl $0x28, %edx
callq 0x26c60
movq -0x8(%rbp), %rdi
addq $0x50, %rdi
movq -0x20(%rbp), %rsi
addq $0x40, %rsi
movl $0x800, %edx            # imm = 0x800
callq 0x26c60
movq -0x8(%rbp), %rdi
addq $0x850, %rdi            # imm = 0x850
xorl %esi, %esi
movl $0x28, %edx
callq 0x26110
movq 0x10b884(%rip), %rax    # 0x18cb60
cmpq $0x0, 0x850(%rax)
je 0x8130d
movq -0x8(%rbp), %rdi
addq $0x850, %rdi            # imm = 0x850
movq 0x10b868(%rip), %rax    # 0x18cb60
movq 0x850(%rax), %rsi
addq $0x8, %rsi
movl $0x28, %edx
callq 0x26c60
leaq 0xf6ec4(%rip), %rax     # 0x1781d8
movl 0xa0(%rax), %eax
movzwl %ax, %edi
callq 0x26280
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x898(%rax)
movq 0x10b829(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
movzwl %ax, %edi
callq 0x26280
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x89a(%rax)
leaq 0xf6e81(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl 0x10(%rax), %eax
movb %al, %cl
movq -0x8(%rbp), %rax
movb %cl, 0x89c(%rax)
leaq 0xf6e64(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x87850
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x87850
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq 0x10b7b2(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x813c4
callq 0x523d0
movq %rax, -0x18(%rbp)
jmp 0x813d6
leaq 0xf6e0d(%rip), %rax     # 0x1781d8
movq 0x7c0(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x87850
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq 0x10b76f(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x81428
leaq 0xf6dd5(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
cmpq $0x0, 0x60058(%rax)
je 0x81428
movq -0x8(%rbp), %rax
movzbl 0x89d(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x89d(%rax)
cmpl $0x3, -0xc(%rbp)
jne 0x81442
movl $0x8a0, -0x10(%rbp)     # imm = 0x8A0
movslq -0x10(%rbp), %rax
addq $0x28, %rax
movl %eax, -0x10(%rbp)
jmp 0x8145e
cmpl $0x7, -0xc(%rbp)
jne 0x8145c
movl $0x8a0, -0x10(%rbp)     # imm = 0x8A0
movslq -0x10(%rbp), %rax
addq $0x830, %rax            # imm = 0x830
movl %eax, -0x10(%rbp)
jmp 0x8145e
movl -0x10(%rbp), %edi
callq 0x26b20
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)