// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/rdb.c
// Function: backgroundSaveDoneHandlerSocket
void backgroundSaveDoneHandlerSocket(int exitcode, int bysignal) {
    uint64_t *ok_slaves;

    if (!bysignal && exitcode == 0) {
        serverLog(LL_NOTICE,
            "Background RDB transfer terminated with success");
    } else if (!bysignal && exitcode != 0) {
        serverLog(LL_WARNING, "Background transfer error");
    } else {
        serverLog(LL_WARNING,
            "Background transfer terminated by signal %d", bysignal);
    }
    server.rdb_child_pid = -1;
    server.rdb_child_type = RDB_CHILD_TYPE_NONE;
    server.rdb_save_time_start = -1;

    /* If the child returns an OK exit code, read the set of slave client
     * IDs and the associated status code. We'll terminate all the slaves
     * in error state.
     *
     * If the process returned an error, consider the list of slaves that
     * can continue to be emtpy, so that it's just a special case of the
     * normal code path. */
    ok_slaves = zmalloc(sizeof(uint64_t)); /* Make space for the count. */
    ok_slaves[0] = 0;
    if (!bysignal && exitcode == 0) {
        int readlen = sizeof(uint64_t);

        if (read(server.rdb_pipe_read_result_from_child, ok_slaves, readlen) ==
                 readlen)
        {
            readlen = ok_slaves[0]*sizeof(uint64_t)*2;

            /* Make space for enough elements as specified by the first
             * uint64_t element in the array. */
            ok_slaves = zrealloc(ok_slaves,sizeof(uint64_t)+readlen);
            if (readlen &&
                read(server.rdb_pipe_read_result_from_child, ok_slaves+1,
                     readlen) != readlen)
            {
                ok_slaves[0] = 0;
            }
        }
    }

    close(server.rdb_pipe_read_result_from_child);
    close(server.rdb_pipe_write_result_to_parent);

    /* We can continue the replication process with all the slaves that
     * correctly received the full payload. Others are terminated. */
    listNode *ln;
    listIter li;

    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        client *slave = ln->value;

        if (slave->replstate == SLAVE_STATE_WAIT_BGSAVE_END) {
            uint64_t j;
            int errorcode = 0;

            /* Search for the slave ID in the reply. In order for a slave to
             * continue the replication process, we need to find it in the list,
             * and it must have an error code set to 0 (which means success). */
            for (j = 0; j < ok_slaves[0]; j++) {
                if (slave->id == ok_slaves[2*j+1]) {
                    errorcode = ok_slaves[2*j+2];
                    break; /* Found in slaves list. */
                }
            }
            if (j == ok_slaves[0] || errorcode != 0) {
                serverLog(LL_WARNING,
                "Closing slave %s: child->slave RDB transfer failed: %s",
                    replicationGetSlaveName(slave),
                    (errorcode == 0) ? "RDB transfer child aborted"
                                     : strerror(errorcode));
                freeClient(slave);
            } else {
                serverLog(LL_WARNING,
                "Slave %s correctly received the streamed RDB file.",
                    replicationGetSlaveName(slave));
                /* Restore the socket as non-blocking. */
                anetNonBlock(NULL,slave->fd);
                anetSendTimeout(NULL,slave->fd,0);
            }
        }
    }
    zfree(ok_slaves);

    updateSlavesWaitingBgsave((!bysignal && exitcode == 0) ? C_OK : C_ERR, RDB_CHILD_TYPE_SOCKET);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
orl %edi, %ebx
je 0x4e125
movl %esi, %edx
testl %esi, %esi
setne %al
testl %edi, %edi
sete %cl
orb %al, %cl
jne 0x4e13a
leaq 0x77d75(%rip), %rsi     # 0xc5e93
movl $0x3, %edi
jmp 0x4e131
leaq 0x77d37(%rip), %rsi     # 0xc5e63
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
jmp 0x4e14d
leaq 0x77d6c(%rip), %rsi     # 0xc5ead
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
leaq 0xb8704(%rip), %r15     # 0x106858
movl $0xffffffff, 0x720(%r15) # imm = 0xFFFFFFFF
movl $0x0, 0x76c(%r15)
movq $-0x1, 0x760(%r15)
movl $0x8, %edi
callq 0x3b29d
movq %rax, %rbp
movq $0x0, (%rax)
testl %ebx, %ebx
movl %ebx, 0x4(%rsp)
jne 0x4e1eb
movl 0x77c(%r15), %edi
movl $0x8, %edx
movq %rbp, %rsi
callq 0x26350
cmpq $0x8, %rax
jne 0x4e1eb
movl (%rbp), %eax
shll $0x4, %eax
movslq %eax, %r14
leaq 0x8(%r14), %rsi
movq %rbp, %rdi
callq 0x3b349
movq %rax, %rbp
testl %r14d, %r14d
je 0x4e1eb
movl 0x77c(%r15), %edi
movq %rbp, %rsi
addq $0x8, %rsi
movq %r14, %rdx
callq 0x26350
cmpq %r14, %rax
je 0x4e1eb
movq $0x0, (%rbp)
movl 0x77c(%r15), %edi
callq 0x26180
movl 0x778(%r15), %edi
callq 0x26180
movq 0x1e0(%r15), %rdi
leaq 0x18(%rsp), %r14
movq %r14, %rsi
callq 0x2e582
movq %r14, %rdi
callq 0x2e59f
testq %rax, %rax
je 0x4e30f
leaq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x18(%rsp), %r12
movq %rbp, 0x8(%rsp)
movq 0x10(%rax), %r13
cmpl $0x7, 0xa0(%r13)
jne 0x4e2fe
movq (%rbp), %rbx
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x4e27b
movq (%r13), %rax
movq 0x10(%rsp), %rcx
xorl %r15d, %r15d
cmpq -0x8(%rcx), %rax
je 0x4e280
incq %r15
addq $0x10, %rcx
cmpq %r15, %rbx
jne 0x4e264
movq %rbx, %r15
jmp 0x4e282
xorl %r15d, %r15d
jmp 0x4e282
movl (%rcx), %ebp
movq %r13, %rdi
callq 0x47084
movq %rax, %r14
cmpq %rbx, %r15
je 0x4e2c6
testl %ebp, %ebp
jne 0x4e2c6
movl $0x3, %edi
leaq 0x77c89(%rip), %rsi     # 0xc5f2b
movq %r14, %rdx
xorl %eax, %eax
callq 0x32ea6
movl 0x8(%r13), %esi
xorl %edi, %edi
callq 0x30779
movl 0x8(%r13), %esi
xorl %edi, %edi
xorl %edx, %edx
callq 0x309c8
jmp 0x4e2f9
leaq 0x77c43(%rip), %rcx     # 0xc5f10
testl %ebp, %ebp
je 0x4e2db
movl %ebp, %edi
callq 0x26690
movq %rax, %rcx
movl $0x3, %edi
leaq 0x77bf2(%rip), %rsi     # 0xc5ed9
movq %r14, %rdx
xorl %eax, %eax
callq 0x32ea6
movq %r13, %rdi
callq 0x40b04
movq 0x8(%rsp), %rbp
movq %r12, %rdi
callq 0x2e59f
testq %rax, %rax
jne 0x4e23b
movq %rbp, %rdi
callq 0x3b3df
xorl %edi, %edi
negl 0x4(%rsp)
sbbl %edi, %edi
movl $0x2, %esi
callq 0x486fb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq