// File: /workspace/github_c_makefile_star2_O1/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 0xe20e(%rip), %rax      # 0x19ac8
movq (%rax), %r12
testq %r12, %r12
je 0xba15
movq %rsp, %r14
leaq 0x832a(%rip), %r13      # 0x13bfa
leaq 0x835c(%rip), %rbp      # 0x13c33
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0xc, %ecx
je 0xb953
cmpl $0x14, %ecx
je 0xb8ef
movq %r13, %rdi
callq 0xc83e
movq (%r12), %rax
movl 0x8(%rax), %ebx
movq 0x18(%rax), %rdi
callq 0x6c67
movq %rax, %rdi
cmpl $0x4, %ebx
jne 0xb985
callq 0x6a31
movq %rax, %rbx
movq %r14, %rdi
callq 0x3180
testl %eax, %eax
jns 0xb92e
leaq 0x8433(%rip), %rdi      # 0x13d55
callq 0xc7ed
xorl %edi, %edi
callq 0x47be
callq 0xcfb8
testl %eax, %eax
je 0xba32
movl 0x4(%rsp), %edi
callq 0x3170
movl (%rsp), %edi
movq (%r12), %rax
movl 0x10(%rax), %esi
jmp 0xb9ee
movl 0x10(%rax), %esi
movl 0x18(%rax), %edi
cmpl $-0x1, %edi
je 0xba00
cmpl %esi, %edi
je 0xba07
callq 0x3110
testl %eax, %eax
jns 0xba07
leaq 0x82d8(%rip), %rdi      # 0x13c56
callq 0xc7ed
jmp 0xb9f7
callq 0x60fc
movq %rax, %rbx
testq %rax, %rax
jne 0xb99e
leaq 0x827d(%rip), %rdi      # 0x13c16
callq 0x47be
cmpq $0x0, 0x10(%rbx)
je 0xb9ad
movq %rbp, %rdi
callq 0x47be
movq (%r12), %rax
cmpl $0x3, 0x8(%rax)
jb 0xb9bf
movq %r13, %rdi
callq 0xc83e
movq (%rbx), %rdi
movq (%r12), %rax
movl 0x8(%rax), %esi
callq 0xa148
movl %eax, %r15d
testl %eax, %eax
jns 0xb9e4
movq (%rbx), %rdi
callq 0xc7ed
xorl %edi, %edi
callq 0x47be
movq (%r12), %rax
movl 0x10(%rax), %esi
movl %r15d, %edi
callq 0xc8f5
testl %eax, %eax
jns 0xba07
xorl %edi, %edi
callq 0x47be
jmp 0xba07
movl %esi, %edi
callq 0x3170
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0xb8d7
leaq 0xe0ac(%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 0x4eba
movl (%rsp), %edi
callq 0x3170
testq %rbx, %rbx
je 0xba62
movl 0x4(%rsp), %ebp
movq (%rbx), %rbx
movq %rbx, %rdi
callq 0x30f0
movl %ebp, %edi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc0f8
xorl %edi, %edi
callq 0x3330
nopl (%rax)