// File: /workspace/github_c_makefile_star2_O3/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 0xbc40e(%rip), %rax     # 0x1018a8
movq 0x1e0(%rax), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2b3b7
movq %r14, %rdi
callq 0x2b3d4
testq %rax, %rax
je 0x45683
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
leaq 0x8(%rsp), %r13
xorl %r12d, %r12d
movq 0x10(%rax), %r15
movl 0xa0(%r15), %eax
cmpl $0x7, %eax
je 0x454f8
cmpl $0x6, %eax
jne 0x45665
andl 0x148(%r15), %r14d
movl $0x1, %r12d
jmp 0x45665
cmpl $0x2, %ebx
jne 0x4554a
movq %r15, %rdi
callq 0x43e7c
movl $0x2, %edi
leaq 0x7c457(%rip), %rsi     # 0xc1968
leaq 0xd0c48(%rip), %rdx     # 0x116160
xorl %eax, %eax
callq 0x2fdad
movabsq $0x100000009, %rax      # imm = 0x100000009
movq %rax, 0xa0(%r15)
leaq 0xbc371(%rip), %rax     # 0x1018a8
movq 0x978(%rax), %rax
movq %rax, 0xd8(%r15)
jmp 0x45665
testl %ebp, %ebp
je 0x4556e
movq %r15, %rdi
callq 0x3d73b
movl $0x3, %edi
leaq 0x7c476(%rip), %rsi     # 0xc19d8
xorl %eax, %eax
callq 0x2fdad
jmp 0x45665
leaq 0xbc333(%rip), %rax     # 0x1018a8
movq 0x748(%rax), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x26690
movl %eax, 0xa8(%r15)
cmpl $-0x1, %eax
je 0x4563b
movl %eax, %edi
leaq 0x18(%rsp), %rsi
callq 0x266e0
cmpl $-0x1, %eax
je 0x4563b
movq $0x0, 0xb0(%r15)
movq 0x48(%rsp), %rax
movq %rax, 0xb8(%r15)
movl $0x8, 0xa0(%r15)
callq 0x3628d
movq 0xb8(%r15), %rdx
movq %rax, %rdi
leaq 0x7c453(%rip), %rsi     # 0xc1a35
xorl %eax, %eax
callq 0x36f2d
movq %rax, 0xc0(%r15)
leaq 0xbc2b1(%rip), %rax     # 0x1018a8
movq 0x40(%rax), %rdi
movl 0x8(%r15), %esi
movl $0x2, %edx
callq 0x2cf0e
leaq 0xbc298(%rip), %rax     # 0x1018a8
movq 0x40(%rax), %rdi
movl 0x8(%r15), %esi
movl $0x2, %edx
leaq -0x3b3(%rip), %rcx      # 0x45271
movq %r15, %r8
callq 0x2ce46
cmpl $-0x1, %eax
jne 0x45665
movq %r15, %rdi
callq 0x3d73b
jmp 0x45665
movq %r15, %rdi
callq 0x3d73b
callq 0x26880
movl (%rax), %edi
callq 0x26680
movl $0x3, %edi
leaq 0x7c3a9(%rip), %rsi     # 0xc1a04
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
movq %r13, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x454cd
testl %r12d, %r12d
je 0x45683
movl %r14d, %edi
callq 0x44abb
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq