// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %r15
leaq 0x14(%rsp), %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x26870
testl %eax, %eax
jle 0x6aebf
movl %eax, %r12d
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 %r12d, %r14d
movl %ebx, (%rsp)
xorl %edi, %edi
leaq 0x521c8(%rip), %rsi     # 0xbcfb9
xorl %edx, %edx
leaq 0x521cd(%rip), %rcx     # 0xbcfc7
movq %r14, %r8
movl %ebp, %r9d
xorl %eax, %eax
callq 0x6a7bb
movl %r12d, %edi
callq 0x6ac29
testq %rax, %rax
je 0x6ae7c
movq %rax, %r13
movq 0x10(%rax), %r12
cmpl $0x1, %ebp
je 0x6ae24
testl %ebx, %ebx
je 0x6ae2c
cmpl $0xa, 0x4(%r12)
jne 0x6ae95
movl %ebx, %eax
orl %ebp, %eax
je 0x6ae5a
movq 0x8(%r12), %rax
movq (%rax), %r8
movl %ebp, (%rsp)
pushq $0x3
popq %rdi
leaq 0x52156(%rip), %rsi     # 0xbcf9d
xorl %edx, %edx
movl %ebx, %r9d
leaq 0x5258e(%rip), %rcx     # 0xbd3e1
xorl %eax, %eax
callq 0x6a7bb
movq 0xa38cf(%rip), %rdi     # 0x10e730
movq %r13, %rsi
callq 0x26fa8
movq %r12, %rdi
callq 0x6abf0
decl 0xa38a5(%rip)           # 0x10e71c
jmp 0x6ada7
pushq $0x3
popq %rdi
leaq 0x5214b(%rip), %rsi     # 0xbcfd1
movq %r14, %rdx
xorl %eax, %eax
callq 0x2b699
jmp 0x6ada7
andb $-0x2, (%r12)
andl $0x0, 0x18(%r12)
callq 0x2b8ae
movq %rax, %r14
movl 0x4(%r12), %edi
callq 0x6ad83
addq %r14, %rax
movq %rax, 0x10(%r12)
jmp 0x6ada7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq