// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/replication.c
// Function: updateSlavesWaitingBgsave
void updateSlavesWaitingBgsave(int bgsaveerr, int type) {
    listNode *ln;
    int startbgsave = 0;
    int mincapa = -1;
    listIter li;

    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        client *slave = ln->value;

        if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
            startbgsave = 1;
            mincapa = (mincapa == -1) ? slave->slave_capa :
                                        (mincapa & slave->slave_capa);
        } else if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END) {
            struct redis_stat buf;

            /* If this was an RDB on disk save, we have to prepare to send
             * the RDB from disk to the slave socket. Otherwise if this was
             * already an RDB -> Slaves socket transfer, used in the case of
             * diskless replication, our work is trivial, we can just put
             * the slave online. */
            if (type == RDB_CHILD_TYPE_SOCKET) {
                serverLog(LL_NOTICE,
                    "Streamed RDB transfer with slave %s succeeded (socket). Waiting for REPLCONF ACK from slave to enable streaming",
                        replicationGetSlaveName(slave));
                /* Note: we wait for a REPLCONF ACK message from slave in
                 * order to really put it online (install the write handler
                 * so that the accumulated data can be transfered). However
                 * we change the replication state ASAP, since our slave
                 * is technically online now. */
                slave->replstate = SLAVE_STATE_ONLINE;
                slave->repl_put_online_on_ack = 1;
                slave->repl_ack_time = server.unixtime; /* Timeout otherwise. */
            } else {
                if (bgsaveerr != C_OK) {
                    freeClient(slave);
                    serverLog(LL_WARNING,"SYNC failed. BGSAVE child returned an error");
                    continue;
                }
                if ((slave->repldbfd = open(server.rdb_filename,O_RDONLY)) == -1 ||
                    redis_fstat(slave->repldbfd,&buf) == -1) {
                    freeClient(slave);
                    serverLog(LL_WARNING,"SYNC failed. Can't open/stat DB after BGSAVE: %s", strerror(errno));
                    continue;
                }
                slave->repldboff = 0;
                slave->repldbsize = buf.st_size;
                slave->replstate = SLAVE_STATE_SEND_BULK;
                slave->replpreamble = sdscatprintf(sdsempty(),"$%lld\r\n",
                    (unsigned long long) slave->repldbsize);

                aeDeleteFileEvent(server.el,slave->fd,AE_WRITABLE);
                if (aeCreateFileEvent(server.el, slave->fd, AE_WRITABLE, sendBulkToSlave, slave) == AE_ERR) {
                    freeClient(slave);
                    continue;
                }
            }
        }
    }
    if (startbgsave) startBgsaveForReplication(mincapa);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %esi, %ebx
movl %edi, %ebp
leaq 0xbb7f5(%rip), %r13     # 0xf98a8
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x2702c
movb $0x1, %al
movl %eax, 0x4(%rsp)
pushq $-0x1
popq %rax
movl %eax, (%rsp)
pushq $0x2
popq %r14
movq %r15, %rdi
callq 0x27046
testq %rax, %rax
je 0x3e270
movq 0x10(%rax), %r12
movl 0xa0(%r12), %eax
cmpl $0x7, %eax
je 0x3e116
cmpl $0x6, %eax
jne 0x3e0d7
movl (%rsp), %eax
andl 0x148(%r12), %eax
movl %eax, (%rsp)
movl $0x0, 0x4(%rsp)
jmp 0x3e0d7
cmpl $0x2, %ebx
jne 0x3e161
movq %r12, %rdi
callq 0x3cc38
movl %r14d, %edi
leaq 0x74f8b(%rip), %rsi     # 0xb30b8
leaq 0xd002c(%rip), %rdx     # 0x10e160
xorl %eax, %eax
callq 0x2b699
movabsq $0x100000009, %rax      # imm = 0x100000009
movq %rax, 0xa0(%r12)
movq 0x978(%r13), %rax
movq %rax, 0xd8(%r12)
jmp 0x3e0d7
testl %ebp, %ebp
je 0x3e183
movq %r12, %rdi
callq 0x37527
pushq $0x3
popq %rdi
leaq 0x74fb1(%rip), %rsi     # 0xb3128
xorl %eax, %eax
callq 0x2b699
jmp 0x3e0d7
movq 0x748(%r13), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x26690
movl %eax, 0xa8(%r12)
cmpl $-0x1, %eax
je 0x3e243
movl %eax, %edi
leaq 0x18(%rsp), %rsi
callq 0x266e0
cmpl $-0x1, %eax
je 0x3e243
andq $0x0, 0xb0(%r12)
movq 0x48(%rsp), %rax
movq %rax, 0xb8(%r12)
movl $0x8, 0xa0(%r12)
callq 0x3114c
movq 0xb8(%r12), %rdx
movq %rax, %rdi
leaq 0x74f93(%rip), %rsi     # 0xb3185
xorl %eax, %eax
callq 0x31a38
movq %rax, 0xc0(%r12)
movq 0x40(%r13), %rdi
movl 0x8(%r12), %esi
movl %r14d, %edx
callq 0x28ba8
movq 0x40(%r13), %rdi
movl 0x8(%r12), %esi
movl %r14d, %edx
leaq -0x334(%rip), %rcx      # 0x3def1
movq %r12, %r8
callq 0x28ae8
cmpl $-0x1, %eax
jne 0x3e0d7
movq %r12, %rdi
callq 0x37527
jmp 0x3e0d7
movq %r12, %rdi
callq 0x37527
callq 0x26880
movl (%rax), %edi
callq 0x26680
pushq $0x3
popq %rdi
leaq 0x74ef3(%rip), %rsi     # 0xb3154
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x3e0d7
testb $0x1, 0x4(%rsp)
jne 0x3e27f
movl (%rsp), %edi
callq 0x3d7fb
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq