// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0x4aa18
movl %esi, %edx
testl %esi, %esi
setne %al
testl %edi, %edi
sete %cl
orb %al, %cl
jne 0x4aa2d
leaq 0x78502(%rip), %rsi     # 0xc2f13
movl $0x3, %edi
jmp 0x4aa24
leaq 0x784c4(%rip), %rsi     # 0xc2ee3
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
jmp 0x4aa40
leaq 0x784f9(%rip), %rsi     # 0xc2f2d
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
leaq 0xb6e61(%rip), %r15     # 0x1018a8
movl $0xffffffff, 0x730(%r15) # imm = 0xFFFFFFFF
movl $0x0, 0x77c(%r15)
movq $-0x1, 0x770(%r15)
movl $0x8, %edi
callq 0x382d1
movq %rax, %r14
movq $0x0, (%rax)
testl %ebx, %ebx
movl %ebx, 0xc(%rsp)
jne 0x4aae4
movl 0x78c(%r15), %edi
movl $0x8, %edx
movq %r14, %rsi
callq 0x26340
cmpq $0x8, %rax
jne 0x4aae4
movl (%r14), %eax
shll $0x4, %eax
movq %r14, %rdi
movslq %eax, %r14
leaq 0x8(%r14), %rsi
callq 0x3837d
testl %r14d, %r14d
movq %rax, (%rsp)
je 0x4aae8
movq %rax, %r12
movl 0x78c(%r15), %edi
movq %rax, %rsi
addq $0x8, %rsi
movq %r14, %rdx
callq 0x26340
cmpq %r14, %rax
je 0x4aae8
movq $0x0, (%r12)
jmp 0x4aae8
movq %r14, (%rsp)
movl 0x78c(%r15), %edi
callq 0x26180
movl 0x788(%r15), %edi
callq 0x26180
movq 0x1e0(%r15), %rdi
leaq 0x18(%rsp), %r14
movq %r14, %rsi
callq 0x2b3b7
movq %r14, %rdi
callq 0x2b3d4
testq %rax, %rax
movq (%rsp), %r14
je 0x4ac21
leaq 0x10(%r14), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x18(%rsp), %r12
movq 0x10(%rax), %r13
cmpl $0x7, 0xa0(%r13)
jne 0x4ac10
movq (%r14), %r15
testq %r15, %r15
je 0x4ab82
movq (%r13), %rax
movq 0x10(%rsp), %rcx
xorl %ebx, %ebx
cmpq -0x8(%rcx), %rax
je 0x4ab89
incq %rbx
addq $0x10, %rcx
cmpq %rbx, %r15
jne 0x4ab5c
movq %r13, %rdi
callq 0x43e7c
movq %rax, %rbp
leaq 0x78410(%rip), %rcx     # 0xc2f90
jmp 0x4abf2
xorl %ebx, %ebx
xorl %r14d, %r14d
jmp 0x4ab8c
movl (%rcx), %r14d
movq %r13, %rdi
callq 0x43e7c
movq %rax, %rbp
cmpq %r15, %rbx
je 0x4abd5
testl %r14d, %r14d
jne 0x4abd5
movl $0x3, %edi
leaq 0x783fe(%rip), %rsi     # 0xc2fab
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2fdad
movl 0x8(%r13), %esi
xorl %edi, %edi
callq 0x2d6a1
movl 0x8(%r13), %esi
xorl %edi, %edi
xorl %edx, %edx
callq 0x2d8f0
movq (%rsp), %r14
jmp 0x4ac10
testl %r14d, %r14d
je 0x4abe7
movl %r14d, %edi
callq 0x26680
movq %rax, %rcx
jmp 0x4abee
leaq 0x783a2(%rip), %rcx     # 0xc2f90
movq (%rsp), %r14
movl $0x3, %edi
leaq 0x7835b(%rip), %rsi     # 0xc2f59
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2fdad
movq %r13, %rdi
callq 0x3d73b
movq %r12, %rdi
callq 0x2b3d4
testq %rax, %rax
jne 0x4ab37
movq %r14, %rdi
callq 0x38413
xorl %edi, %edi
negl 0xc(%rsp)
sbbl %edi, %edi
movl $0x2, %esi
callq 0x4547e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq