// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]mysh/mysh_parse.c
// Function: parse_redirections
static int parse_redirections(struct list_head *toks,
			      struct list_head *cmd_args,
			      struct list_head *redirs,
			      bool *async_ret)
{
	struct string *prev_string;
	int ret = 0;

	/* Set prev_string by borrowing a string from the cmd_args list. */
	bool prev_string_is_borrowed = true;
	if (!list_empty(cmd_args))
		prev_string = list_entry(cmd_args->prev, struct string, list);
	else
		prev_string = NULL;

	/* While there are additional tokens remaining, try parsing the next
	 * redirection. */
	while (!list_empty(toks)) {
		ret = parse_next_redirection(toks, prev_string, redirs,
					     async_ret);
		if (ret) /* Parse error */
			break;

		if (prev_string) {
			char *chars = prev_string->chars;

			/* Redirection consumed borrowed string.  Delete it from
			 * the cmd_args list. */
			if (chars == NULL && prev_string_is_borrowed)
				list_del(&prev_string->list);

			/* If the redirection consumed the previous string, or
			 * it was not borrowed,free it */
			if (chars == NULL || !prev_string_is_borrowed)
				free_string(prev_string);

			/* If the previous string was not borrowed and it was
			 * not consumed by the redirection, it's a syntax error. */
			if (chars != NULL && !prev_string_is_borrowed) {
				mysh_error("unexpected string token");
				return -1;
			}
			prev_string = NULL;
		}

		/* If the next token is a string, try to set prev_string from
		 * it. */
		while (!list_empty(toks)) { /* while loop to take into account
					       strings that expand to nothing */
			struct token *tok = list_entry(toks->next, struct token, list);
			if (tok->type & TOK_CLASS_STRING) {
				struct token *next;
				if (tok->list.next == toks)
					next = NULL;
				else
					next = list_entry(tok->list.next, struct token, list);
				ret = expand_single_string(tok, next, &prev_string);
				if (ret)
					return ret;
				list_del(&tok->list);
				if (prev_string) {
					prev_string_is_borrowed = false;
					break;
				}
			} else {
				break;
			}
		}
	}
	return ret;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movb $0x1, -0x35(%rbp)
movq -0x18(%rbp), %rdi
callq 0x7310
cmpl $0x0, %eax
jne 0x7946
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x794e
movq $0x0, -0x30(%rbp)
jmp 0x7950
movq -0x10(%rbp), %rdi
callq 0x7310
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x796a
jmp 0x7aca
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x8030
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x798d
jmp 0x7aca
cmpq $0x0, -0x30(%rbp)
je 0x79fe
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x79b9
testb $0x1, -0x35(%rbp)
je 0x79b9
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x7580
cmpq $0x0, -0x50(%rbp)
je 0x79c6
testb $0x1, -0x35(%rbp)
jne 0x79cf
movq -0x30(%rbp), %rdi
callq 0x9020
cmpq $0x0, -0x50(%rbp)
je 0x79f6
testb $0x1, -0x35(%rbp)
jne 0x79f6
leaq 0x35ba(%rip), %rdi      # 0xaf9d
movb $0x0, %al
callq 0x8c20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x7ad0
movq $0x0, -0x30(%rbp)
jmp 0x7a00
movq -0x10(%rbp), %rdi
callq 0x7310
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7a1a
jmp 0x7ac5
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $-0x10, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x7abe
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x7a60
movq $0x0, -0x70(%rbp)
jmp 0x7a80
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
addq $-0x10, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x8570
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x7aa2
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7ad0
movq -0x58(%rbp), %rdi
addq $0x10, %rdi
callq 0x7580
cmpq $0x0, -0x30(%rbp)
je 0x7abc
movb $0x0, -0x35(%rbp)
jmp 0x7ac5
jmp 0x7ac0
jmp 0x7ac5
jmp 0x7a00
jmp 0x7950
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)