// File: /workspace/github_c_makefile_star2_O2/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 0xbc096(%rip), %r13     # 0xf98a8
cmpl $0x0, 0x814(%r13)
setne %bpl
leaq 0x7551a(%rip), %rax     # 0xb2d3f
leaq 0x75c6b(%rip), %rdx     # 0xb3497
testb %bpl, %bl
cmovneq %rax, %rdx
leaq 0x754dc(%rip), %rsi     # 0xb2d16
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
testb %bpl, %bl
je 0x3d871
callq 0x42d60
movl %eax, %ebx
cmpl $-0x1, %eax
je 0x3d8cc
testl %ebx, %ebx
jne 0x3d860
callq 0x3d949
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x748(%r13), %rdi
callq 0x41b62
cmpl $-0x1, %eax
je 0x3d8cc
movl %eax, %ebx
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2702c
movq %r14, %rdi
callq 0x27046
testq %rax, %rax
je 0x3d855
movq 0x10(%rax), %rdi
cmpl $0x6, 0xa0(%rdi)
jne 0x3d898
movq 0x7c0(%r13), %rsi
cmpq $0x1, 0x7d0(%r13)
adcq $0x0, %rsi
callq 0x3d4fe
jmp 0x3d898
leaq 0x7547b(%rip), %rsi     # 0xb2d4e
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq 0x1e0(%r13), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x2702c
pushq $-0x1
popq %rbx
leaq 0x75471(%rip), %r15     # 0xb2d6c
movq %r14, %rdi
callq 0x27046
testq %rax, %rax
je 0x3d860
movq 0x10(%rax), %r12
cmpl $0x6, 0xa0(%r12)
jne 0x3d8fb
andb $-0x2, 0x98(%r12)
movq 0x1e0(%r13), %rdi
movq %rax, %rsi
callq 0x26fa8
movq %r12, %rdi
movq %r15, %rsi
callq 0x36b6f
orb $0x40, 0x98(%r12)
jmp 0x3d8fb