// File: /workspace/github_c_makefile_star2_O3/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 0xe2f6(%rip), %rax      # 0x19ac8
movq (%rax), %r12
testq %r12, %r12
je 0xb92f
movq %rsp, %r14
leaq 0x8495(%rip), %r13      # 0x13c7d
leaq 0x84c7(%rip), %rbp      # 0x13cb6
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0xc, %ecx
je 0xb86b
cmpl $0x14, %ecx
je 0xb80b
movq %r13, %rdi
callq 0xc72e
movq (%r12), %rax
movl 0x8(%rax), %ebx
movq 0x18(%rax), %rdi
callq 0x6b88
movq %rax, %rdi
cmpl $0x4, %ebx
jne 0xb89d
callq 0x6946
movq %rax, %rbx
movq %r14, %rdi
callq 0x3180
testl %eax, %eax
jns 0xb846
leaq 0x859e(%rip), %rdi      # 0x13dd8
callq 0xc6dd
xorl %edi, %edi
callq 0x46c0
callq 0xce78
testl %eax, %eax
je 0xb94c
movl 0x4(%rsp), %edi
callq 0x3170
movl (%rsp), %edi
movq (%r12), %rax
movl 0x10(%rax), %esi
jmp 0xb908
movl 0x10(%rax), %esi
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0xb91a
cmpl %esi, %edi
je 0xb921
callq 0x3110
testl %eax, %eax
jns 0xb921
leaq 0x8443(%rip), %rdi      # 0x13cd9
callq 0xc6dd
jmp 0xb911
callq 0x603d
movq %rax, %rbx
testq %rax, %rax
jne 0xb8b6
leaq 0x83e8(%rip), %rdi      # 0x13c99
callq 0x46c0
cmpq $0x0, 0x10(%rbx)
je 0xb8c5
movq %rbp, %rdi
callq 0x46c0
movq (%r12), %rax
movl 0x8(%rax), %esi
cmpl $0x3, %esi
jb 0xb8e0
movq %r13, %rdi
callq 0xc72e
movq (%r12), %rax
movl 0x8(%rax), %esi
movq (%rbx), %rdi
callq 0xa08c
movl %eax, %r15d
testl %eax, %eax
jns 0xb8fe
movq (%rbx), %rdi
callq 0xc6dd
xorl %edi, %edi
callq 0x46c0
movq (%r12), %rax
movl 0x10(%rax), %esi
movl %r15d, %edi
callq 0xc7e5
testl %eax, %eax
jns 0xb921
xorl %edi, %edi
callq 0x46c0
jmp 0xb921
movl %esi, %edi
callq 0x3170
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0xb7ef
leaq 0xe192(%rip), %rax      # 0x19ac8
movq $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x4dba
movl (%rsp), %edi
callq 0x3170
testq %rbx, %rbx
je 0xb97c
movl 0x4(%rsp), %ebp
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x30f0
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xbfdc
xorl %edi, %edi
callq 0x3330
nop