// File: /workspace/github_c_makefile_star2_O2/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 0xbc938(%rip), %rax     # 0xf98a8
cmpq $0x0, 0x7d0(%rax)
je 0x3cfa6
movl %ecx, %r14d
movq %rdx, %rbx
movl %esi, %ebp
cmpl %esi, 0x7bc(%rax)
je 0x3d074
cmpl $0x9, %ebp
ja 0x3cfc0
movl %ebp, %eax
leaq 0xbd374(%rip), %rcx     # 0xfa310
movq 0x160(%rcx,%rax,8), %r12
jmp 0x3d010
cmpq $0x0, 0x28(%r15)
jne 0x3d18d
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %ebp, %rdx
leaq 0x40(%rsp), %r12
pushq $0x15
popq %rsi
movq %r12, %rdi
callq 0x39796
movl %eax, %r13d
callq 0x3114c
leaq 0x71f22(%rip), %rsi     # 0xaef04
movq %rax, %rdi
movl %r13d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0x31a38
xorl %edi, %edi
movq %rax, %rsi
callq 0x39d58
movq %rax, %r12
leaq 0xbc8a2(%rip), %rax     # 0xf98a8
cmpq $0x0, 0x7d0(%rax)
je 0x3d018
movq %r12, %rdi
callq 0x3ced5
leaq 0x30(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x2702c
movq %r13, %rdi
callq 0x27046
testq %rax, %rax
je 0x3d04c
movq 0x10(%rax), %rdi
cmpl $0x6, 0xa0(%rdi)
je 0x3d028
movq %r12, %rsi
callq 0x36987
jmp 0x3d028
cmpl $0xa, %ebp
jb 0x3d059
movq %r12, %rdi
callq 0x3a265
leaq 0xbc848(%rip), %rcx     # 0xf98a8
movl %ebp, 0x7bc(%rcx)
cmpq $0x0, 0x7d0(%rcx)
je 0x3d178
leaq 0x11(%rsp), %r12
movb $0x2a, -0x1(%r12)
movq %r14, %r15
movslq %r15d, %rdx
pushq $0x17
popq %rsi
movq %r12, %rdi
movq %rdx, 0x8(%rsp)
callq 0x39796
cltq
leaq 0x10(%rsp), %rbp
movw $0xa0d, 0x1(%rax,%rbp)  # imm = 0xA0D
addl $0x3, %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3ce0b
xorl %r14d, %r14d
testl %r15d, %r15d
cmovlel %r14d, %r15d
cmpq %r14, %r15
je 0x3d112
movq (%rbx,%r14,8), %rdi
callq 0x3a747
movb $0x24, 0x10(%rsp)
movq %r12, %rdi
pushq $0x17
popq %rsi
movq %rax, %rdx
callq 0x39796
movslq %eax, %r13
movw $0xa0d, 0x1(%r13,%rbp)  # imm = 0xA0D
leal 0x3(%r13), %eax
movslq %eax, %rsi
movq %rbp, %rdi
callq 0x3ce0b
movq (%rbx,%r14,8), %rdi
callq 0x3ced5
addq %r12, %r13
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x3ce0b
incq %r14
jmp 0x3d0bb
leaq 0xbc78f(%rip), %rcx     # 0xf98a8
movq 0x1e0(%rcx), %rdi
leaq 0x30(%rsp), %rbp
movq %rbp, %rsi
callq 0x2702c
movl %r15d, %r12d
movq 0x8(%rsp), %r15
movq %rbp, %rdi
callq 0x27046
testq %rax, %rax
je 0x3cfb1
movq 0x10(%rax), %r14
cmpl $0x6, 0xa0(%r14)
je 0x3d135
movq %r14, %rdi
movq %r15, %rsi
callq 0x370d9
xorl %r13d, %r13d
cmpq %r13, %r12
je 0x3d135
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
callq 0x36fd9
incq %r13
jmp 0x3d162
movslq %r14d, %rdx
xorl %eax, %eax
movq %rdx, 0x8(%rsp)
testl %edx, %edx
cmovgl %r14d, %eax
movl %eax, %r15d
jmp 0x3d119
leaq 0x75825(%rip), %rdi     # 0xb29b9
leaq 0x757f1(%rip), %rsi     # 0xb298c
movl $0xb8, %edx
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0