// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxUnixAZ.c
// Function: CleanupChildren
static int
CleanupChildren(
    Hax_Interp *interp,		/* Used for error messages. */
    ClientData clientData,
    int numPids,		/* Number of entries in pidPtr array. */
    int *pidPtr,		/* Array of process ids of children. */
    int errorId			/* File descriptor index for file containing
				 * stderr output from pipeline.  -1 means
				 * there isn't any stderr output. */)
{
    Hax_Memoryp *memoryp;
    int result = HAX_OK;
    int i, pid, length;
    int waitStatus;

    memoryp = Hax_GetMemoryp(interp);

    for (i = 0; i < numPids; i++) {
	pid = Hax_WaitPids(clientData, 1, &pidPtr[i], (int *) &waitStatus);
	if (pid == -1) {
	    Hax_AppendResult(interp, "error waiting for process to exit: ",
		    Hax_UnixError(interp), (char *) NULL);
	    continue;
	}

	/*
	 * Create error messages for unusual process exits.  An
	 * extra newline gets appended to each error message, but
	 * it gets removed below (in the same fashion that an
	 * extra newline in the command's output is removed).
	 */

	if (!WIFEXITED(waitStatus) || (WEXITSTATUS(waitStatus) != 0)) {
	    char msg1[20], msg2[20];

	    result = HAX_ERROR;
	    sprintf(msg1, "%d", pid);
	    if (WIFEXITED(waitStatus)) {
		sprintf(msg2, "%d", WEXITSTATUS(waitStatus));
		Hax_SetErrorCode(interp, "CHILDSTATUS", msg1, msg2,
			(char *) NULL);
	    } else if (WIFSIGNALED(waitStatus)) {
		char *p;

		p = Hax_SignalMsg((int) (WTERMSIG(waitStatus)));
		Hax_SetErrorCode(interp, "CHILDKILLED", msg1,
			Hax_SignalId((int) (WTERMSIG(waitStatus))), p,
			(char *) NULL);
		Hax_AppendResult(interp, "child killed: ", p, "\n",
			(char *) NULL);
	    } else if (WIFSTOPPED(waitStatus)) {
		char *p;

		p = Hax_SignalMsg((int) (WSTOPSIG(waitStatus)));
		Hax_SetErrorCode(interp, "CHILDSUSP", msg1,
			Hax_SignalId((int) (WSTOPSIG(waitStatus))), p, (char *) NULL);
		Hax_AppendResult(interp, "child suspended: ", p, "\n",
			(char *) NULL);
	    } else {
		Hax_AppendResult(interp,
			"child wait status didn't make sense\n",
			(char *) NULL);
	    }
	}
    }
    ckfree(memoryp, (char *) pidPtr);

    /*
     * Read the standard error file.  If there's anything there,
     * then return an error and add the file's contents to the result
     * string.
     */

    if (errorId >= 0) {
	while (1) {
#	    define BUFFER_SIZE 1000
	    char buffer[BUFFER_SIZE+1];
	    int count;

	    count = read(errorId, buffer, BUFFER_SIZE);

	    if (count == 0) {
		break;
	    }
	    if (count < 0) {
		Hax_AppendResult(interp,
			"error reading stderr output file: ",
			Hax_UnixError(interp), (char *) NULL);
		break;
	    }
	    buffer[count] = 0;
	    Hax_AppendResult(interp, buffer, (char *) NULL);
	}
	close(errorId);
    }

    /*
     * If the last character of interp->result is a newline, then remove
     * the newline character (the newline would just confuse things).
     */

    length = strlen(interp->result);
    if ((length > 0) && (interp->result[length-1] == '\n')) {
	interp->result[length-1] = '\0';
    }

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movl %r8d, 0xc(%rsp)
movq %rcx, 0x10(%rsp)
movl %edx, %r15d
movq %rsi, 0x28(%rsp)
movq %rdi, %rbx
callq 0x3530
movq %rax, 0x18(%rsp)
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
shlq $0x2, %r15
leaq 0x50(%rsp), %r14
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r15, 0x20(%rsp)
cmpq %r13, %r15
je 0x4b37
movq %r14, %r12
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rdx
movq 0x28(%rsp), %rdi
pushq $0x1
popq %rsi
leaq 0x8(%rsp), %rcx
callq 0x3300
cmpl $-0x1, %eax
je 0x4a66
movzwl 0x8(%rsp), %ecx
testw $0xff7f, %cx            # imm = 0xFF7F
movq %r12, %r14
je 0x4b2e
movq %r14, %rdi
leaq 0x3c0d(%rip), %rbp      # 0x8603
movq %rbp, %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x3590
movl 0x8(%rsp), %eax
movl %eax, %ecx
andl $0x7f, %ecx
je 0x4a89
movl %ecx, %edx
shll $0x18, %edx
addl $0x1000000, %edx        # imm = 0x1000000
cmpl $0x2000000, %edx        # imm = 0x2000000
jl 0x4abf
movl %ecx, %edi
callq 0x3630
movq %rax, %rbp
movl 0x8(%rsp), %edi
andl $0x7f, %edi
callq 0x32d0
movq %rbx, %rdi
leaq 0x3df6(%rip), %rsi      # 0x883a
movq %r12, %rdx
movq %rax, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3480
movq %rbx, %rdi
leaq 0x3de5(%rip), %rsi      # 0x8846
jmp 0x4aff
movq %rbx, %rdi
callq 0x31b0
movq %rbx, %rdi
leaq 0x3d92(%rip), %rsi      # 0x880a
movq %rax, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3500
jmp 0x4b2b
movzbl %ah, %edx
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3590
movq %rbx, %rdi
leaq 0x3d86(%rip), %rsi      # 0x882e
movq %r14, %rdx
movq %r15, %rcx
movq 0x20(%rsp), %r15
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3480
jmp 0x4b28
cmpb $0x7f, %al
jne 0x4b15
movzbl %ah, %edi
callq 0x3630
movq %rax, %rbp
movzbl 0x9(%rsp), %edi
callq 0x32d0
movq %rbx, %rdi
leaq 0x3d73(%rip), %rsi      # 0x8855
movq %r12, %rdx
movq %rax, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3480
movq %rbx, %rdi
leaq 0x3d60(%rip), %rsi      # 0x885f
movq %rbp, %rdx
leaq 0x3d8b(%rip), %rcx      # 0x8894
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3500
jmp 0x4b28
movq %rbx, %rdi
leaq 0x3d52(%rip), %rsi      # 0x8871
xorl %edx, %edx
xorl %eax, %eax
callq 0x3500
pushq $0x1
popq %rbp
movq %r12, %r14
addq $0x4, %r13
jmp 0x49a9
leaq 0x375a(%rip), %rdx      # 0x8298
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl $0x6cb, %ecx            # imm = 0x6CB
callq 0x31f0
movl 0xc(%rsp), %r15d
testl %r15d, %r15d
js 0x4bb8
leaq 0x50(%rsp), %r14
movl $0x3e8, %edx            # imm = 0x3E8
movl %r15d, %edi
movq %r14, %rsi
callq 0x32e0
testl %eax, %eax
je 0x4bb0
js 0x4b92
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, 0x50(%rsp,%rax)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3500
jmp 0x4b61
movq %rbx, %rdi
callq 0x31b0
leaq 0x3cf5(%rip), %rsi      # 0x8896
movq %rbx, %rdi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3500
movl %r15d, %edi
callq 0x3280
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x3190
testl %eax, %eax
jle 0x4bd3
decl %eax
cmpb $0xa, (%rbx,%rax)
jne 0x4bd3
movb $0x0, (%rbx,%rax)
movl %ebp, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq