// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3540
movq %rax, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5549
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rdx
movslq -0x38(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movl $0x1, %esi
leaq -0x44(%rbp), %rcx
callq 0x3310
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x3c(%rbp)
jne 0x5354
movq -0x8(%rbp), %rax
movq %rax, -0x490(%rbp)
movq -0x8(%rbp), %rdi
callq 0x31b0
movq -0x490(%rbp), %rdi
movq %rax, %rdx
leaq 0x6439(%rip), %rsi      # 0xb77d
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x3510
jmp 0x553b
movl -0x44(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x5373
movl -0x44(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
cmpl $0x0, %eax
je 0x5539
movl $0x1, -0x34(%rbp)
leaq -0x60(%rbp), %rdi
movl -0x3c(%rbp), %edx
leaq 0x61ee(%rip), %rsi      # 0xb576
movb $0x0, %al
callq 0x35a0
movl -0x44(%rbp), %eax
andl $0x7f, %eax
cmpl $0x0, %eax
jne 0x53dc
leaq -0x80(%rbp), %rdi
movl -0x44(%rbp), %edx
andl $0xff00, %edx           # imm = 0xFF00
sarl $0x8, %edx
leaq 0x61c5(%rip), %rsi      # 0xb576
movb $0x0, %al
callq 0x35a0
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0x63d6(%rip), %rsi      # 0xb7a1
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x3490
jmp 0x5537
movl -0x44(%rbp), %eax
andl $0x7f, %eax
addl $0x1, %eax
movsbl %al, %eax
sarl %eax
cmpl $0x0, %eax
jle 0x547b
movl -0x44(%rbp), %edi
andl $0x7f, %edi
callq 0x3640
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4a0(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x498(%rbp)
movl -0x44(%rbp), %edi
andl $0x7f, %edi
callq 0x32e0
movq -0x4a0(%rbp), %rdi
movq -0x498(%rbp), %rdx
movq %rax, %rcx
movq -0x88(%rbp), %r8
leaq 0x6368(%rip), %rsi      # 0xb7ad
xorl %eax, %eax
movl %eax, %r9d
movb $0x0, %al
callq 0x3490
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq 0x6356(%rip), %rsi      # 0xb7b9
leaq 0x639d(%rip), %rcx      # 0xb807
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x3510
jmp 0x5535
movl -0x44(%rbp), %eax
andl $0xff, %eax
cmpl $0x7f, %eax
jne 0x551d
movl -0x44(%rbp), %edi
andl $0xff00, %edi           # imm = 0xFF00
sarl $0x8, %edi
callq 0x3640
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4b0(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movl -0x44(%rbp), %edi
andl $0xff00, %edi           # imm = 0xFF00
sarl $0x8, %edi
callq 0x32e0
movq -0x4b0(%rbp), %rdi
movq -0x4a8(%rbp), %rdx
movq %rax, %rcx
movq -0x90(%rbp), %r8
leaq 0x62de(%rip), %rsi      # 0xb7c8
xorl %eax, %eax
movl %eax, %r9d
movb $0x0, %al
callq 0x3490
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rdx
leaq 0x62ca(%rip), %rsi      # 0xb7d2
leaq 0x62f8(%rip), %rcx      # 0xb807
xorl %eax, %eax
movl %eax, %r8d
movb $0x0, %al
callq 0x3510
jmp 0x5533
movq -0x8(%rbp), %rdi
leaq 0x62bc(%rip), %rsi      # 0xb7e4
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x3510
jmp 0x5535
jmp 0x5537
jmp 0x5539
jmp 0x553b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x52e9
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq 0x5cb3(%rip), %rdx      # 0xb20b
movl $0x6cb, %ecx            # imm = 0x6CB
callq 0x31f0
cmpl $0x0, -0x24(%rbp)
jl 0x5600
jmp 0x556e
movl -0x24(%rbp), %edi
leaq -0x480(%rbp), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x32f0
movl %eax, -0x484(%rbp)
cmpl $0x0, -0x484(%rbp)
jne 0x5593
jmp 0x55f8
cmpl $0x0, -0x484(%rbp)
jge 0x55ce
movq -0x8(%rbp), %rax
movq %rax, -0x4b8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x31b0
movq -0x4b8(%rbp), %rdi
movq %rax, %rdx
leaq 0x6248(%rip), %rsi      # 0xb809
xorl %eax, %eax
movl %eax, %ecx
movb $0x0, %al
callq 0x3510
jmp 0x55f8
movslq -0x484(%rbp), %rax
movb $0x0, -0x480(%rbp,%rax)
movq -0x8(%rbp), %rdi
leaq -0x480(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0x3510
jmp 0x556e
movl -0x24(%rbp), %edi
callq 0x3290
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3190
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jle 0x5642
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x5642
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %eax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
nop