// File: /workspace/github_c_makefile_star2_O2/rakitzis[P]rc/redir.c
// Function: doredirs
extern void doredirs() {
	List *fname;
	int fd, p[2];
	Rq *r;
	for (r = redirq; r != NULL; r = r->n) {
		switch(r->r->type) {
		default:
			panic("unexpected node in doredirs");
			/* NOTREACHED */
		case nRedir:
			if (r->r->u[0].i == rHerestring) {
				fname = flatten(glom(r->r->u[2].p)); /* fname is really a string */
				if (pipe(p) < 0) {
					uerror("pipe");
					rc_error(NULL);
				}
				if (rc_fork() == 0) { /* child writes to pipe */
					setsigdefaults(FALSE);
					close(p[0]);
					if (fname != NULL)
						writeall(p[1], fname->w, strlen(fname->w));
					exit(0);
				} else {
					close(p[1]);
					if (mvfd(p[0], r->r->u[1].i) < 0)
						rc_error(NULL);
				}
			} else {
				fname = glob(glom(r->r->u[2].p));
				if (fname == NULL)
					rc_error("null filename in redirection");
				if (fname->n != NULL)
					rc_error("multi-word filename in redirection");
				switch (r->r->u[0].i) {
				default:
					panic("unexpected node in doredirs");
					/* NOTREACHED */
				case rCreate: case rAppend: case rFrom:
					fd = rc_open(fname->w, r->r->u[0].i);
					break;
				}
				if (fd < 0) {
					uerror(fname->w);
					rc_error(NULL);
				}
				if (mvfd(fd, r->r->u[1].i) < 0)
					rc_error(NULL);
			}
			break;
		case nDup:
			if (r->r->u[2].i == -1)
				close(r->r->u[1].i);
			else if (r->r->u[2].i != r->r->u[1].i) {
				if (dup2(r->r->u[2].i, r->r->u[1].i) < 0) {
					uerror("dup2");
					rc_error(NULL);
				}
			}
		}
	}
	redirq = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0xea7e(%rip), %r12      # 0x19ac8
movq %rsp, %r14
leaq 0x7bf6(%rip), %r13      # 0x12c4a
leaq 0x7c28(%rip), %rbp      # 0x12c83
movq (%r12), %r12
testq %r12, %r12
je 0xb1a3
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0xc, %ecx
je 0xb0e4
cmpl $0x14, %ecx
je 0xb084
movq %r13, %rdi
callq 0xbeea
movq (%r12), %rax
movl 0x8(%rax), %ebx
movq 0x18(%rax), %rdi
callq 0x6914
movq %rax, %rdi
cmpl $0x4, %ebx
jne 0xb116
callq 0x66e1
movq %rax, %rbx
movq %r14, %rdi
callq 0x3180
testl %eax, %eax
jns 0xb0bf
leaq 0x7cf2(%rip), %rdi      # 0x12da5
callq 0xbe9d
xorl %edi, %edi
callq 0x45b7
callq 0xc5b0
testl %eax, %eax
je 0xb1bd
movl 0x4(%rsp), %edi
callq 0x3170
movl (%rsp), %edi
movq (%r12), %rax
movl 0x10(%rax), %esi
jmp 0xb181
movl 0x10(%rax), %esi
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0xb193
cmpl %esi, %edi
je 0xb19a
callq 0x3110
testl %eax, %eax
jns 0xb19a
leaq 0x7b97(%rip), %rdi      # 0x12ca6
callq 0xbe9d
jmp 0xb18a
callq 0x5e5f
movq %rax, %rbx
testq %rax, %rax
jne 0xb12f
leaq 0x7b3c(%rip), %rdi      # 0x12c66
callq 0x45b7
cmpq $0x0, 0x10(%rbx)
je 0xb13e
movq %rbp, %rdi
callq 0x45b7
movq (%r12), %rax
movl 0x8(%rax), %esi
cmpl $0x3, %esi
jb 0xb159
movq %r13, %rdi
callq 0xbeea
movq (%r12), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdi
callq 0x9afc
movl %eax, %r15d
testl %eax, %eax
jns 0xb177
movq (%rbx), %rdi
callq 0xbe9d
xorl %edi, %edi
callq 0x45b7
movq (%r12), %rax
movl 0x10(%rax), %esi
movl %r15d, %edi
callq 0xbf88
testl %eax, %eax
jns 0xb19a
xorl %edi, %edi
callq 0x45b7
jmp 0xb19a
movl %esi, %edi
callq 0x3170
addq $0x8, %r12
jmp 0xb05b
leaq 0xe91e(%rip), %rax      # 0x19ac8
andq $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x4c71
movl (%rsp), %edi
callq 0x3170
testq %rbx, %rbx
je 0xb1ed
movl 0x4(%rsp), %ebp
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x30f0
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xb7c0
xorl %edi, %edi
callq 0x3330