// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/replication.c
// Function: replicationFeedSlaves
void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) {
    listNode *ln;
    listIter li;
    int j, len;
    char llstr[LONG_STR_SIZE];

    /* If there aren't slaves, and there is no backlog buffer to populate,
     * we can return ASAP. */
    if (server.repl_backlog == NULL && listLength(slaves) == 0) return;

    /* We can't have slaves attached and no backlog. */
    serverAssert(!(listLength(slaves) != 0 && server.repl_backlog == NULL));

    /* Send SELECT command to every slave if needed. */
    if (server.slaveseldb != dictid) {
        robj *selectcmd;

        /* For a few DBs we have pre-computed SELECT command. */
        if (dictid >= 0 && dictid < PROTO_SHARED_SELECT_CMDS) {
            selectcmd = shared.select[dictid];
        } else {
            int dictid_len;

            dictid_len = ll2string(llstr,sizeof(llstr),dictid);
            selectcmd = createObject(OBJ_STRING,
                sdscatprintf(sdsempty(),
                "*2\r\n$6\r\nSELECT\r\n$%d\r\n%s\r\n",
                dictid_len, llstr));
        }

        /* Add the SELECT command into the backlog. */
        if (server.repl_backlog) feedReplicationBacklogWithObject(selectcmd);

        /* Send it to slaves. */
        listRewind(slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;
            if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) continue;
            addReply(slave,selectcmd);
        }

        if (dictid < 0 || dictid >= PROTO_SHARED_SELECT_CMDS)
            decrRefCount(selectcmd);
    }
    server.slaveseldb = dictid;

    /* Write the command to the replication backlog if any. */
    if (server.repl_backlog) {
        char aux[LONG_STR_SIZE+3];

        /* Add the multi bulk reply length. */
        aux[0] = '*';
        len = ll2string(aux+1,sizeof(aux)-1,argc);
        aux[len+1] = '\r';
        aux[len+2] = '\n';
        feedReplicationBacklog(aux,len+3);

        for (j = 0; j < argc; j++) {
            long objlen = stringObjectLen(argv[j]);

            /* We need to feed the buffer with the object as a bulk reply
             * not just as a plain string, so create the $..CRLF payload len
             * and add the final CRLF */
            aux[0] = '$';
            len = ll2string(aux+1,sizeof(aux)-1,objlen);
            aux[len+1] = '\r';
            aux[len+2] = '\n';
            feedReplicationBacklog(aux,len+3);
            feedReplicationBacklogWithObject(argv[j]);
            feedReplicationBacklog(aux+len+1,2);
        }
    }

    /* Write the command to every slave. */
    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        client *slave = ln->value;

        /* Don't feed slaves that are still waiting for BGSAVE to start */
        if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) continue;

        /* Feed slaves that are waiting for the initial SYNC (so these commands
         * are queued in the output buffer until the initial SYNC completes),
         * or are already in sync with the master. */

        /* Add the multi bulk length. */
        addReplyMultiBulkLen(slave,argc);

        /* Finally any additional argument that was not stored inside the
         * static buffer if any (from j to argc). */
        for (j = 0; j < argc; j++)
            addReplyBulk(slave,argv[j]);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r15
leaq 0xbd6e7(%rip), %r14     # 0x1018a8
cmpq $0x0, 0x7d0(%r14)
je 0x44202
movq %rdx, %rbx
movl %esi, %r13d
movslq %ecx, %rax
movq %rax, 0x8(%rsp)
movl %eax, %ebp
cmpl %esi, 0x7bc(%r14)
je 0x442e8
cmpl $0x9, %r13d
ja 0x4422f
movl %r13d, %eax
leaq 0xbe118(%rip), %rcx     # 0x102310
movq 0x160(%rcx,%rax,8), %r12
jmp 0x44279
cmpq $0x0, 0x28(%r15)
je 0x443fa
leaq 0x7d055(%rip), %rdi     # 0xc1269
leaq 0x7d021(%rip), %rsi     # 0xc123c
movl $0xb8, %edx
callq 0x61908
movl $0x1, %edi
callq 0x263c0
movslq %r13d, %rdx
leaq 0x40(%rsp), %rdi
movl $0x15, %esi
callq 0x3ff83
movl %eax, %r12d
callq 0x3628d
leaq 0x78dc4(%rip), %rsi     # 0xbd014
movq %rax, %rdi
movl %r12d, %edx
leaq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x36f2d
xorl %edi, %edi
movq %rax, %rsi
callq 0x40650
movq %rax, %r12
cmpq $0x0, 0x7d0(%r14)
je 0x44281
movq %r12, %rdi
callq 0x44132
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %rsi, %r15
callq 0x2b3b7
movq %r15, %rdi
callq 0x2b3d4
testq %rax, %rax
je 0x442c5
leaq 0x10(%rsp), %r15
movq 0x10(%rax), %rdi
cmpl $0x6, 0xa0(%rdi)
je 0x442b8
movq %r12, %rsi
callq 0x3c854
movq %r15, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x442a3
cmpl $0xa, %r13d
jb 0x442d3
movq %r12, %rdi
callq 0x40c8f
movl %r13d, 0x7bc(%r14)
cmpq $0x0, 0x7d0(%r14)
je 0x4438c
leaq 0x21(%rsp), %r15
movb $0x2a, -0x1(%r15)
movl $0x17, %esi
movq %r15, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x3ff83
cltq
leaq 0x20(%rsp), %r12
movw $0xa0d, 0x1(%rax,%r12)  # imm = 0xA0D
addl $0x3, %eax
movslq %eax, %rsi
movq %r12, %rdi
callq 0x4405d
testl %r14d, %r14d
jle 0x44385
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0x41270
movb $0x24, 0x20(%rsp)
movl $0x17, %esi
movq %r15, %rdi
movq %rax, %rdx
callq 0x3ff83
movslq %eax, %r13
movw $0xa0d, 0x1(%r13,%r12)  # imm = 0xA0D
leal 0x3(%r13), %eax
movslq %eax, %rsi
movq %r12, %rdi
callq 0x4405d
movq (%rbx,%r14,8), %rdi
callq 0x44132
addq %r15, %r13
movl $0x2, %esi
movq %r13, %rdi
callq 0x4405d
incq %r14
cmpq %r14, %rbp
jne 0x4432c
leaq 0xbd51c(%rip), %r14     # 0x1018a8
movq 0x1e0(%r14), %rdi
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x2b3b7
movq %r15, %rdi
callq 0x2b3d4
testq %rax, %rax
movq 0x8(%rsp), %r13
je 0x443fa
leaq 0x10(%rsp), %r15
movq 0x10(%rax), %r12
cmpl $0x6, 0xa0(%r12)
je 0x443ed
movq %r12, %rdi
movq %r13, %rsi
callq 0x3d274
testl %r13d, %r13d
jle 0x443ed
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rsi
movq %r12, %rdi
callq 0x3d170
incq %r14
cmpq %r14, %rbp
jne 0x443d9
movq %r15, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x443b7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq