// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0xbe141(%rip), %rax     # 0x106858
movq 0x1e0(%rax), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2e582
movq %r14, %rdi
callq 0x2e59f
testq %rax, %rax
je 0x488fb
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %r13
xorl %r12d, %r12d
movq 0x10(%rax), %r15
movl 0xa0(%r15), %eax
cmpl $0x7, %eax
je 0x48775
cmpl $0x6, %eax
jne 0x488e2
andl 0x148(%r15), %r14d
movl $0x1, %r12d
jmp 0x488e2
cmpl $0x2, %ebx
jne 0x487c7
movq %r15, %rdi
callq 0x47084
movl $0x2, %edi
leaq 0x7c146(%rip), %rsi     # 0xc48d4
leaq 0xd296b(%rip), %rdx     # 0x11b100
xorl %eax, %eax
callq 0x32ea6
movabsq $0x100000009, %rax      # imm = 0x100000009
movq %rax, 0xa0(%r15)
leaq 0xbe0a4(%rip), %rax     # 0x106858
movq 0x968(%rax), %rax
movq %rax, 0xd8(%r15)
jmp 0x488e2
testl %ebp, %ebp
je 0x487eb
movq %r15, %rdi
callq 0x40b04
movl $0x3, %edi
leaq 0x7c165(%rip), %rsi     # 0xc4944
xorl %eax, %eax
callq 0x32ea6
jmp 0x488e2
leaq 0xbe066(%rip), %rax     # 0x106858
movq 0x738(%rax), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x266a0
movl %eax, 0xa8(%r15)
cmpl $-0x1, %eax
je 0x488b8
movl %eax, %edi
leaq 0x18(%rsp), %rsi
callq 0x266f0
cmpl $-0x1, %eax
je 0x488b8
movq $0x0, 0xb0(%r15)
movq 0x48(%rsp), %rax
movq %rax, 0xb8(%r15)
movl $0x8, 0xa0(%r15)
callq 0x39222
movq 0xb8(%r15), %rdx
movq %rax, %rdi
leaq 0x7c142(%rip), %rsi     # 0xc49a1
xorl %eax, %eax
callq 0x39eb7
movq %rax, 0xc0(%r15)
leaq 0xbdfe4(%rip), %rax     # 0x106858
movq 0x40(%rax), %rdi
movl 0x8(%r15), %esi
movl $0x2, %edx
callq 0x2ffb6
leaq 0xbdfcb(%rip), %rax     # 0x106858
movq 0x40(%rax), %rdi
movl 0x8(%r15), %esi
movl $0x2, %edx
leaq -0x3b7(%rip), %rcx      # 0x484ea
movq %r15, %r8
callq 0x2fee7
cmpl $-0x1, %eax
jne 0x488e2
movq %r15, %rdi
callq 0x40b04
jmp 0x488e2
movq %r15, %rdi
callq 0x40b04
callq 0x26890
movl (%rax), %edi
callq 0x26690
movl $0x3, %edi
leaq 0x7c098(%rip), %rsi     # 0xc4970
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
movq %r13, %rdi
callq 0x2e59f
testq %rax, %rax
jne 0x4874a
testl %r12d, %r12d
sete %al
jmp 0x48903
movb $0x1, %al
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
jne 0x4890f
movl %r14d, %edi
callq 0x47cc7
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq