// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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, %ebx
leaq 0xbcdd6(%rip), %r13     # 0x1018a8
cmpl $0x0, 0x814(%r13)
setne %bpl
leaq 0x7cb0a(%rip), %rax     # 0xc15ef
leaq 0x7d25b(%rip), %rdx     # 0xc1d47
testb %bpl, %bl
cmovneq %rax, %rdx
leaq 0x7cacc(%rip), %rsi     # 0xc15c6
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
testb %bpl, %bl
je 0x44b19
callq 0x4ac8d
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x44b84
jmp 0x44b98
movq 0x748(%r13), %rdi
callq 0x49797
cmpl $-0x1, %eax
je 0x44b98
movl %eax, %ebx
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2b3b7
movq %r14, %rdi
callq 0x2b3d4
testq %rax, %rax
je 0x44b84
leaq 0x8(%rsp), %r14
movq 0x10(%rax), %rdi
cmpl $0x6, 0xa0(%rdi)
jne 0x44b77
movq 0x7c0(%r13), %rsi
cmpq $0x1, 0x7d0(%r13)
adcq $0x0, %rsi
callq 0x44798
movq %r14, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x44b52
testl %ebx, %ebx
jne 0x44c25
callq 0x44c36
xorl %ebx, %ebx
jmp 0x44c25
leaq 0x7ca5f(%rip), %rsi     # 0xc15fe
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2b3b7
movq %rbx, %rdi
callq 0x2b3d4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x44c25
leaq 0x7ca44(%rip), %r14     # 0xc161c
leaq 0x8(%rsp), %r15
movq 0x10(%rax), %r12
cmpl $0x6, 0xa0(%r12)
jne 0x44c18
andb $-0x2, 0x98(%r12)
movq 0x1e0(%r13), %rdi
movq %rax, %rsi
callq 0x2b331
movq %r12, %rdi
movq %r14, %rsi
callq 0x3cc06
orb $0x40, 0x98(%r12)
movq %r15, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x44bdd
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq