// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/replication.c
// Function: startBgsaveForReplication
int startBgsaveForReplication(int mincapa) {
    int retval;
    int socket_target = server.repl_diskless_sync && (mincapa & SLAVE_CAPA_EOF);
    listIter li;
    listNode *ln;

    serverLog(LL_NOTICE,"Starting BGSAVE for SYNC with target: %s",
        socket_target ? "slaves sockets" : "disk");

    if (socket_target)
        retval = rdbSaveToSlavesSockets();
    else
        retval = rdbSaveBackground(server.rdb_filename);

    /* If we failed to BGSAVE, remove the slaves waiting for a full
     * resynchorinization from the list of salves, inform them with
     * an error about what happened, close the connection ASAP. */
    if (retval == C_ERR) {
        serverLog(LL_WARNING,"BGSAVE for replication failed");
        listRewind(server.slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;

            if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
                slave->flags &= ~CLIENT_SLAVE;
                listDelNode(server.slaves,ln);
                addReplyError(slave,
                    "BGSAVE failed, replication can't continue");
                slave->flags |= CLIENT_CLOSE_AFTER_REPLY;
            }
        }
        return retval;
    }

    /* If the target is socket, rdbSaveToSlavesSockets() already setup
     * the salves for a full resync. Otherwise for disk target do it now.*/
    if (!socket_target) {
        listRewind(server.slaves,&li);
        while((ln = listNext(&li))) {
            client *slave = ln->value;

            if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_START) {
                    replicationSetupSlaveForFullResync(slave,
                            getPsyncInitialOffset());
            }
        }
    }

    /* Flush the script cache, since we need that slave differences are
     * accumulated without requiring slaves to match our cached scripts. */
    if (retval == C_OK) replicationScriptCacheFlush();
    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebp
leaq 0xbeb7a(%rip), %r13     # 0x106858
cmpl $0x0, 0x804(%r13)
setne %al
andb %al, %bpl
leaq 0x7c868(%rip), %rax     # 0xc455b
leaq 0x7cfb9(%rip), %rdx     # 0xc4cb3
cmovneq %rax, %rdx
leaq 0x7c82d(%rip), %rsi     # 0xc4532
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
testb %bpl, %bpl
je 0x47d1d
callq 0x4e37b
jmp 0x47d29
movq 0x738(%r13), %rdi
callq 0x4cd9b
movl %eax, %ebx
cmpl $-0x1, %eax
je 0x47d9f
testb %bpl, %bpl
jne 0x47d8d
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2e582
movq %r14, %rdi
callq 0x2e59f
testq %rax, %rax
je 0x47d8d
leaq 0x8(%rsp), %r14
movq 0x10(%rax), %rdi
cmpl $0x6, 0xa0(%rdi)
jne 0x47d80
movq 0x7b0(%r13), %rsi
cmpq $0x1, 0x7c0(%r13)
adcq $0x0, %rsi
callq 0x479a4
movq %r14, %rdi
callq 0x2e59f
testq %rax, %rax
jne 0x47d5b
testl %ebx, %ebx
jne 0x47e27
callq 0x47e38
jmp 0x47e27
leaq 0x7c7c4(%rip), %rsi     # 0xc456a
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2e582
movq %r14, %rdi
callq 0x2e59f
testq %rax, %rax
je 0x47e27
leaq 0x7c7ae(%rip), %r14     # 0xc4588
leaq 0x8(%rsp), %r15
movq 0x10(%rax), %r12
cmpl $0x6, 0xa0(%r12)
jne 0x47e1a
andb $-0x2, 0x98(%r12)
movq 0x1e0(%r13), %rdi
movq %rax, %rsi
callq 0x2e4f4
movq %r12, %rdi
movq %r14, %rsi
callq 0x3ffcb
orb $0x40, 0x98(%r12)
movq %r15, %rdi
callq 0x2e59f
testq %rax, %rax
jne 0x47ddf
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq