// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxUnixUtil.c
// Function: Hax_WaitPids
int
Hax_WaitPids(
    ClientData clientData,
    int numPids,		/* Number of pids to wait on:  gives size
				 * of array pointed to by pidPtr. */
    int *pidPtr,		/* Pids to wait on:  return when one of
				 * these processes exits or suspends. */
    int *statusPtr		/* Wait status is returned here. */)
{
    UnixClientData *unixClientData = (UnixClientData *) clientData;
    int i, count, pid;
    WaitInfo *waitPtr;
    int anyProcesses;
    int status;

    while (1) {
	/*
	 * Scan the table of child processes to see if one of the
	 * specified children has already exited or suspended.  If so,
	 * remove it from the table and return its status.
	 */

	anyProcesses = 0;
	for (waitPtr = unixClientData->waitTable,
		count = unixClientData->waitTableUsed;
		count > 0; waitPtr++, count--) {
	    for (i = 0; i < numPids; i++) {
		if (pidPtr[i] != waitPtr->pid) {
		    continue;
		}
		anyProcesses = 1;
		if (waitPtr->flags & WI_READY) {
		    *statusPtr = *((int *) &waitPtr->status);
		    pid = waitPtr->pid;
		    if (WIFEXITED(waitPtr->status)
			    || WIFSIGNALED(waitPtr->status)) {
			*waitPtr = unixClientData->waitTable
				[unixClientData->waitTableUsed-1];
			unixClientData->waitTableUsed--;
		    } else {
			waitPtr->flags &= ~WI_READY;
		    }
		    return pid;
		}
	    }
	}

	/*
	 * Make sure that the caller at least specified one valid
	 * process to wait for.
	 */

	if (!anyProcesses) {
	    errno = ECHILD;
	    return -1;
	}

	/*
	 * Wait for a process to exit or suspend, then update its
	 * entry in the table and go back to the beginning of the
	 * loop to see if it's one of the desired processes.
	 */

	pid = wait(&status);
	if (pid < 0) {
	    return pid;
	}
	for (waitPtr = unixClientData->waitTable,
	     count = unixClientData->waitTableUsed; ;
		waitPtr++, count--) {
	    if (count == 0) {
		break;			/* Ignore unknown processes. */
	    }
	    if (pid != waitPtr->pid) {
		continue;
	    }

	    /*
	     * If the process has been detached, then ignore anything
	     * other than an exit, and drop the entry on exit.
	     */

	    if (waitPtr->flags & WI_DETACHED) {
		if (WIFEXITED(status) || WIFSIGNALED(status)) {
		    *waitPtr = unixClientData->waitTable
			[unixClientData->waitTableUsed-1];
		    unixClientData->waitTableUsed--;
		}
	    } else {
		waitPtr->status = status;
		waitPtr->flags |= WI_READY;
	    }
	    break;
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %r12d
xorl %eax, %eax
testl %esi, %esi
cmovlel %eax, %r12d
movq %rdi, %rbx
movl 0x94(%rdi), %ecx
pushq $0x1
popq %rbp
leaq 0x4(%rsp), %r13
movq 0x88(%rbx), %rsi
movq %rsi, %rdx
xorl %eax, %eax
testl %ecx, %ecx
jle 0x6f42
xorl %edi, %edi
cmpq %rdi, %r12
je 0x6f3a
movl (%r15,%rdi,4), %r8d
cmpl (%rdx), %r8d
jne 0x6f35
testb $0x1, 0x8(%rdx)
movl %ebp, %eax
jne 0x6fe0
incq %rdi
jmp 0x6f1b
addq $0xc, %rdx
decl %ecx
jmp 0x6f15
testl %eax, %eax
je 0x7033
movq %r13, %rdi
callq 0x35e0
testl %eax, %eax
js 0x7024
movq 0x88(%rbx), %rsi
movl 0x94(%rbx), %ecx
movslq %ecx, %rdi
leaq 0x8(%rsi), %rdx
movl %ecx, %r8d
subl $0x1, %r8d
jb 0x6f09
cmpl -0x8(%rdx), %eax
je 0x6f82
addq $0xc, %rdx
jmp 0x6f71
movl (%rdx), %r8d
movl 0x4(%rsp), %eax
testb $0x2, %r8b
jne 0x6f9e
movl %eax, -0x4(%rdx)
orl $0x1, %r8d
movl %r8d, (%rdx)
jmp 0x6f09
andl $0x7f, %eax
je 0x6fb6
shll $0x18, %eax
addl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x2000000, %eax        # imm = 0x2000000
jl 0x6f09
addq $-0x8, %rdx
imulq $0xc, %rdi, %rax
movl -0x4(%rsi,%rax), %ecx
movl %ecx, 0x8(%rdx)
movq -0xc(%rsi,%rax), %rax
movq %rax, (%rdx)
movl 0x94(%rbx), %ecx
decl %ecx
movl %ecx, 0x94(%rbx)
jmp 0x6f09
movl 0x4(%rdx), %ecx
movl %ecx, (%r14)
movl (%rdx), %eax
andl $0x7f, %ecx
je 0x6ffe
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x7020
movslq 0x94(%rbx), %rcx
imulq $0xc, %rcx, %rcx
movl -0x4(%rsi,%rcx), %edi
movl %edi, 0x8(%rdx)
movq -0xc(%rsi,%rcx), %rcx
movq %rcx, (%rdx)
decl 0x94(%rbx)
jmp 0x7024
andb $-0x2, 0x8(%rdx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3080
movl $0xa, (%rax)
pushq $-0x1
popq %rax
jmp 0x7024