// File: /workspace/github_c_makefile_star2_O0/michaelforney[P]cproc/driver.c
// Function: spawnphase
static int
spawnphase(struct stageinfo *phase, int *fd, char *input, char *output, bool last)
{
	int ret, pipefd[2];
	posix_spawn_file_actions_t actions;

	phase->cmd.len = phase->cmdbase;
	if (last && output) {
		arrayaddptr(&phase->cmd, "-o");
		arrayaddptr(&phase->cmd, output);
	}
	if (input && *fd == -1)
		arrayaddptr(&phase->cmd, input);
	arrayaddptr(&phase->cmd, NULL);

	ret = posix_spawn_file_actions_init(&actions);
	if (ret)
		goto err0;
	if (*fd != -1)
		ret = posix_spawn_file_actions_adddup2(&actions, *fd, 0);
	if (!last) {
		if (pipe(pipefd) < 0) {
			ret = errno;
			goto err1;
		}
		if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) < 0) {
			ret = errno;
			goto err2;
		}
		if (fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) < 0) {
			ret = errno;
			goto err2;
		}
		ret = posix_spawn_file_actions_adddup2(&actions, pipefd[1], 1);
		if (ret)
			goto err2;
	}

	ret = spawn(&phase->pid, &phase->cmd, &actions);
	if (ret)
		goto err2;
	if (!last) {
		*fd = pipefd[0];
		close(pipefd[1]);
	}
	posix_spawn_file_actions_destroy(&actions);

	return 0;

err2:
	if (!last) {
		close(pipefd[0]);
		close(pipefd[1]);
	}
err1:
	posix_spawn_file_actions_destroy(&actions);
err0:
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
testb $0x1, -0x29(%rbp)
je 0x3af5
cmpq $0x0, -0x28(%rbp)
je 0x3af5
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
leaq 0x1a0b(%rip), %rsi      # 0x54ea
callq 0x4260
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x28(%rbp), %rsi
callq 0x4260
cmpq $0x0, -0x20(%rbp)
je 0x3b16
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x3b16
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x20(%rbp), %rsi
callq 0x4260
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4260
leaq -0x88(%rbp), %rdi
callq 0x2030
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x3b41
jmp 0x3c6d
movq -0x18(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x3b61
movq -0x18(%rbp), %rax
movl (%rax), %esi
leaq -0x88(%rbp), %rdi
xorl %edx, %edx
callq 0x2220
movl %eax, -0x30(%rbp)
testb $0x1, -0x29(%rbp)
jne 0x3bf6
leaq -0x38(%rbp), %rdi
callq 0x2120
cmpl $0x0, %eax
jge 0x3b88
callq 0x2040
movl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x3c61
movl -0x38(%rbp), %edi
movl $0x2, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x20a0
cmpl $0x0, %eax
jge 0x3bb0
callq 0x2040
movl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x3c49
movl -0x34(%rbp), %edi
movl $0x2, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x20a0
cmpl $0x0, %eax
jge 0x3bd5
callq 0x2040
movl (%rax), %eax
movl %eax, -0x30(%rbp)
jmp 0x3c49
movl -0x34(%rbp), %esi
leaq -0x88(%rbp), %rdi
movl $0x1, %edx
callq 0x2220
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x3bf4
jmp 0x3c49
jmp 0x3bf6
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
leaq -0x88(%rbp), %rdx
callq 0x3d40
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x3c1d
jmp 0x3c49
testb $0x1, -0x29(%rbp)
jne 0x3c34
movl -0x38(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x34(%rbp), %edi
callq 0x2110
leaq -0x88(%rbp), %rdi
callq 0x20b0
movl $0x0, -0x4(%rbp)
jmp 0x3c73
testb $0x1, -0x29(%rbp)
jne 0x3c5f
movl -0x38(%rbp), %edi
callq 0x2110
movl -0x34(%rbp), %edi
callq 0x2110
jmp 0x3c61
leaq -0x88(%rbp), %rdi
callq 0x20b0
movl -0x30(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop