// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelCollectTerminatedScripts
void sentinelCollectTerminatedScripts(void) {
    int statloc;
    pid_t pid;

    while ((pid = wait3(&statloc,WNOHANG,NULL)) > 0) {
        int exitcode = WEXITSTATUS(statloc);
        int bysignal = 0;
        listNode *ln;
        sentinelScriptJob *sj;

        if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc);
        sentinelEvent(LL_DEBUG,"-script-child",NULL,"%ld %d %d",
            (long)pid, exitcode, bysignal);

        ln = sentinelGetScriptListNodeByPid(pid);
        if (ln == NULL) {
            serverLog(LL_WARNING,"wait3() returned a pid (%ld) we can't find in our scripts execution queue!", (long)pid);
            continue;
        }
        sj = ln->value;

        /* If the script was terminated by a signal or returns an
         * exit code of "1" (that means: please retry), we reschedule it
         * if the max number of retries is not already reached. */
        if ((bysignal || exitcode == 1) &&
            sj->retry_num != SENTINEL_SCRIPT_MAX_RETRY)
        {
            sj->flags &= ~SENTINEL_SCRIPT_RUNNING;
            sj->pid = 0;
            sj->start_time = mstime() +
                             sentinelScriptRetryDelay(sj->retry_num);
        } else {
            /* Otherwise let's remove the script, but log the event if the
             * execution did not terminated in the best of the ways. */
            if (bysignal || exitcode != 0) {
                sentinelEvent(LL_WARNING,"-script-error",NULL,
                              "%s %d %d", sj->argv[0], bysignal, exitcode);
            }
            listDelNode(sentinel.scripts_queue,ln);
            sentinelReleaseScriptJob(sj);
            sentinel.running_scripts--;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x14(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x26870
testl %eax, %eax
jle 0x77202
movl %eax, %r13d
leaq 0x14(%rsp), %r12
movl 0x14(%rsp), %ebx
movzbl %bh, %ebp
andl $0x7f, %ebx
movl %ebx, %eax
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
movl $0x0, %eax
cmovll %eax, %ebx
movl %r13d, %r15d
movl %ebx, (%rsp)
xorl %edi, %edi
leaq 0x55258(%rip), %rsi     # 0xcc36d
xorl %edx, %edx
leaq 0x5525d(%rip), %rcx     # 0xcc37b
movq %r15, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x76a24
movl %r13d, %edi
callq 0x76f11
testq %rax, %rax
je 0x7719d
movq %rax, %r14
movq 0x10(%rax), %r13
cmpl $0x1, %ebp
je 0x77148
testl %ebx, %ebx
je 0x7714f
cmpl $0xa, 0x4(%r13)
jne 0x771b5
movl %ebx, %eax
orl %ebp, %eax
je 0x7717e
movq 0x8(%r13), %rax
movq (%rax), %r8
movl %ebp, (%rsp)
movl $0x3, %edi
leaq 0x551e6(%rip), %rsi     # 0xcc351
xorl %edx, %edx
movl %ebx, %r9d
leaq 0x5561e(%rip), %rcx     # 0xcc795
xorl %eax, %eax
callq 0x76a24
movq 0x9f5ab(%rip), %rdi     # 0x116730
movq %r14, %rsi
callq 0x2b331
movq %r13, %rdi
callq 0x76ecb
decl 0x9f581(%rip)           # 0x11671c
jmp 0x771e8
movl $0x3, %edi
leaq 0x551dc(%rip), %rsi     # 0xcc385
movq %r15, %rdx
xorl %eax, %eax
callq 0x2fdad
jmp 0x771e8
andb $-0x2, (%r13)
movl $0x0, 0x18(%r13)
callq 0x2ffce
movl 0x4(%r13), %ecx
movl $0x7530, %edx           # imm = 0x7530
cmpl $0x2, %ecx
jl 0x771e1
incl %ecx
addq %rdx, %rdx
decl %ecx
cmpl $0x2, %ecx
ja 0x771d7
addq %rax, %rdx
movq %rdx, 0x10(%r13)
movq %r12, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x26870
movl %eax, %r13d
testl %eax, %eax
jg 0x770e5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq