// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0xf9f9(%rip), %rax      # 0x1fb58
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x103ab
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
subl $0xc, %eax
je 0x1032b
jmp 0x10188
movl -0x24(%rbp), %eax
subl $0x14, %eax
je 0x1019e
jmp 0x10192
leaq 0x9d46(%rip), %rdi      # 0x19edf
callq 0x11c80
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpl $0x4, 0x8(%rax)
jne 0x10270
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
callq 0x8af0
movq %rax, %rdi
callq 0x87c0
movq %rax, -0x8(%rbp)
leaq -0x14(%rbp), %rdi
callq 0x3180
cmpl $0x0, %eax
jge 0x101ee
leaq 0x9e5a(%rip), %rdi      # 0x1a03a
callq 0x11c10
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
callq 0x127b0
cmpl $0x0, %eax
jne 0x10241
xorl %edi, %edi
callq 0x5ab0
movl -0x14(%rbp), %edi
callq 0x3170
cmpq $0x0, -0x8(%rbp)
je 0x1023a
movl -0x10(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x30f0
movl -0x34(%rbp), %edi
movq -0x30(%rbp), %rsi
movq %rax, %rdx
callq 0x10dc0
xorl %edi, %edi
callq 0x3320
movl -0x10(%rbp), %edi
callq 0x3170
movl -0x14(%rbp), %edi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %esi
callq 0x11e10
cmpl $0x0, %eax
jge 0x10269
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
jmp 0x1026b
jmp 0x10329
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
callq 0x8af0
movq %rax, %rdi
callq 0x7a10
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x1029f
leaq 0x9c61(%rip), %rdi      # 0x19efb
callq 0x50d0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x102b6
leaq 0x9c67(%rip), %rdi      # 0x19f18
callq 0x50d0
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %eax
subl $0x3, %eax
jb 0x102d3
jmp 0x102c7
leaq 0x9c11(%rip), %rdi      # 0x19edf
callq 0x11c80
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x8(%rax), %esi
callq 0xd900
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jge 0x10307
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x11c10
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %esi
callq 0x11e10
cmpl $0x0, %eax
jge 0x10327
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
jmp 0x10329
jmp 0x10398
movq -0x20(%rbp), %rax
movq (%rax), %rax
cmpl $-0x1, 0x18(%rax)
jne 0x10349
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %edi
callq 0x3170
jmp 0x10396
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
je 0x10394
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %edi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x10(%rax), %esi
callq 0x3110
cmpl $0x0, %eax
jge 0x10392
leaq 0x9bb7(%rip), %rdi      # 0x19f3b
callq 0x11c10
xorl %eax, %eax
movl %eax, %edi
callq 0x50d0
jmp 0x10394
jmp 0x10396
jmp 0x10398
jmp 0x1039a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x10166
leaq 0xf7a6(%rip), %rax      # 0x1fb58
movq $0x0, (%rax)
addq $0x40, %rsp
popq %rbp
retq
nop