// File: /workspace/github_c_makefile_star2_O0/michaelforney[P]cproc/driver.c
// Function: buildobj
static void
buildobj(struct input *input, char *output)
{
	const char *phase;
	size_t i, npids;
	pid_t pid;
	int status, ret, fd;
	bool success = true;

	if (input->filetype == OBJ)
		return;
	if (input->stages & 1<<LINK) {
		input->stages &= ~(1<<LINK);
		output = strdup("/tmp/cproc-XXXXXX");
		if (!output)
			fatal("strdup:");
		fd = mkstemp(output);
		if (fd < 0)
			fatal("mkstemp:");
		close(fd);
	} else if (output) {
		if (strcmp(output, "-") == 0)
			output = NULL;
	} else if (input->stages & 1<<ASSEMBLE) {
		output = changeext(input->name, "o");
	} else if (input->stages & 1<<CODEGEN) {
		output = changeext(input->name, "s");
	} else if (input->stages & 1<<COMPILE) {
		output = changeext(input->name, "qbe");
	}
	if (strcmp(input->name, "-") == 0)
		input->name = NULL;

	npids = 0;
	for (i = PREPROCESS, fd = -1; input->stages; ++i) {
		if (!(input->stages & 1<<i))
			continue;
		input->stages &= ~(1<<i);
		ret = spawnphase(&stages[i], &fd, input->name, output, !input->stages);
		if (ret) {
			warn("%s: spawn \"%s\": %s", stages[i].name, *(char **)stages[i].cmd.val, strerror(ret));
			goto kill;
		}
		++npids;
	}
	input->name = output;

	while (npids > 0) {
		pid = wait(&status);
		if (pid < 0)
			fatal("waitpid:");
		for (i = 0; i < LEN(stages); ++i) {
			if (pid == stages[i].pid) {
				--npids;
				stages[i].pid = 0;
				phase = stages[i].name;
				break;
			}
		}
		if (i == LEN(stages))
			continue;  /* unknown process */
		if (!succeeded(phase, pid, status)) {
kill:
			if (success && npids > 0) {
				for (i = 0; i < LEN(stages); ++i) {
					if (stages[i].pid)
						kill(stages[i].pid, SIGTERM);
				}
			}
			success = false;
		}
	}
	if (!success) {
		if (output)
			unlink(output);
		exit(1);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x1, -0x39(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x6, 0xc(%rax)
jne 0x33f3
jmp 0x378c
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x3461
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
andl $-0x11, %ecx
movl %ecx, 0x8(%rax)
leaq 0x209d(%rip), %rdi      # 0x54b3
callq 0x2230
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3434
leaq 0x1fce(%rip), %rdi      # 0x53fb
movb $0x0, %al
callq 0x3f60
movq -0x10(%rbp), %rdi
callq 0x21a0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jge 0x3454
leaq 0x2078(%rip), %rdi      # 0x54c5
movb $0x0, %al
callq 0x3f60
movl -0x38(%rbp), %edi
callq 0x2110
jmp 0x3505
cmpq $0x0, -0x10(%rbp)
je 0x3487
movq -0x10(%rbp), %rdi
leaq 0x1cb2(%rip), %rsi      # 0x5125
callq 0x2150
cmpl $0x0, %eax
jne 0x3485
movq $0x0, -0x10(%rbp)
jmp 0x3503
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x34af
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x2047(%rip), %rsi      # 0x54eb
callq 0x39a0
movq %rax, -0x10(%rbp)
jmp 0x3501
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x34d7
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x2013(%rip), %rsi      # 0x54df
callq 0x39a0
movq %rax, -0x10(%rbp)
jmp 0x34ff
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x34fd
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x1ce3(%rip), %rsi      # 0x51d7
callq 0x39a0
movq %rax, -0x10(%rbp)
jmp 0x34ff
jmp 0x3501
jmp 0x3503
jmp 0x3505
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq 0x1c12(%rip), %rsi      # 0x5125
callq 0x2150
cmpl $0x0, %eax
jne 0x3528
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x20(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x363d
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x356d
jmp 0x362c
movq -0x20(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
xorl $-0x1, %ecx
movq -0x8(%rbp), %rax
andl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
leaq 0x3bb0(%rip), %rdi      # 0x7140
imulq $0x30, -0x20(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
setne %al
xorb $-0x1, %al
movzbl %al, %r8d
andl $0x1, %r8d
leaq -0x38(%rbp), %rsi
callq 0x3a90
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3620
leaq 0x3b6f(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq 0x3b59(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %edi
callq 0x2240
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rax, %rcx
leaq 0x1eba(%rip), %rdi      # 0x54ce
movb $0x0, %al
callq 0x3e10
jmp 0x3704
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x353f
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, -0x28(%rbp)
jbe 0x376c
leaq -0x30(%rbp), %rdi
callq 0x2250
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x3673
leaq 0x1e75(%rip), %rdi      # 0x54e1
movb $0x0, %al
callq 0x3f60
movq $0x0, -0x20(%rbp)
cmpq $0x5, -0x20(%rbp)
jae 0x36e3
movl -0x2c(%rbp), %eax
leaq 0x3ab4(%rip), %rcx      # 0x7140
imulq $0x30, -0x20(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x28(%rcx), %eax
jne 0x36d3
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
leaq 0x3a94(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movl $0x0, 0x28(%rax)
leaq 0x3a7e(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x36e3
jmp 0x36d5
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x367b
cmpq $0x5, -0x20(%rbp)
jne 0x36ef
jmp 0x3648
movq -0x18(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x3c80
testb $0x1, %al
jne 0x3767
jmp 0x3704
testb $0x1, -0x39(%rbp)
je 0x3763
cmpq $0x0, -0x28(%rbp)
jbe 0x3763
movq $0x0, -0x20(%rbp)
cmpq $0x5, -0x20(%rbp)
jae 0x3761
leaq 0x3a19(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0x28(%rax)
je 0x3751
leaq 0x3a04(%rip), %rax      # 0x7140
imulq $0x30, -0x20(%rbp), %rcx
addq %rcx, %rax
movl 0x28(%rax), %edi
movl $0xf, %esi
callq 0x2180
jmp 0x3753
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3719
jmp 0x3763
movb $0x0, -0x39(%rbp)
jmp 0x3648
testb $0x1, -0x39(%rbp)
jne 0x378c
cmpq $0x0, -0x10(%rbp)
je 0x3782
movq -0x10(%rbp), %rdi
callq 0x2050
movl $0x1, %edi
callq 0x2210
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)