// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
leaq -0x4(%rbp), %rdi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x26870
movl %eax, -0x8(%rbp)
cmpl $0x0, %eax
jle 0x954d9
movl -0x4(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movl %eax, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x4(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x953b7
movl -0x4(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x10(%rbp)
movslq -0x8(%rbp), %r8
movl -0xc(%rbp), %r9d
movl -0x10(%rbp), %eax
xorl %edi, %edi
leaq 0xb0cae(%rip), %rsi     # 0x146079
xorl %ecx, %ecx
movl %ecx, %edx
leaq 0xb0cb1(%rip), %rcx     # 0x146087
movl %eax, (%rsp)
movb $0x0, %al
callq 0x94990
movl -0x8(%rbp), %edi
callq 0x95110
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x9540f
movslq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0xb0c8e(%rip), %rsi     # 0x146091
movb $0x0, %al
callq 0x2fc60
jmp 0x95368
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x95427
cmpl $0x1, -0xc(%rbp)
jne 0x9546d
movq -0x20(%rbp), %rax
cmpl $0xa, 0x4(%rax)
je 0x9546d
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x18(%rax)
callq 0x2ff70
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x95320
movq -0x28(%rbp), %rcx
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x954d4
cmpl $0x0, -0x10(%rbp)
jne 0x95479
cmpl $0x0, -0xc(%rbp)
je 0x954ac
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %r8
movl -0x10(%rbp), %r9d
movl -0xc(%rbp), %eax
movl $0x3, %edi
leaq 0xb0bc6(%rip), %rsi     # 0x14605d
xorl %ecx, %ecx
movl %ecx, %edx
leaq 0xb0fff(%rip), %rcx     # 0x1464a1
movl %eax, (%rsp)
movb $0x0, %al
callq 0x94990
movq 0xf7bad(%rip), %rdi     # 0x18d060
movq -0x18(%rbp), %rsi
callq 0x271e0
movq -0x20(%rbp), %rdi
callq 0x950a0
movl 0xf7b81(%rip), %eax     # 0x18d04c
addl $-0x1, %eax
movl %eax, 0xf7b78(%rip)     # 0x18d04c
jmp 0x95368
addq $0x30, %rsp
popq %rbp
retq
nop