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

	tok = next_token(toks);
	if (tok->preceded_by_whitespace)
		prev_string = NULL;
	tok2 = tok3 = tok4 = NULL;
	switch (tok->type) {
	case TOK_GREATER_THAN:
		/* > */
		tok2 = next_token(toks);
		if (!tok2)
			goto out_syntax_error;
		if (tok2->type & TOK_GREATER_THAN && !tok2->preceded_by_whitespace) {
			tok3 = next_token(toks);
			if (tok3 && tok3->type & TOK_CLASS_STRING) {
				/* [N]>>WORD (output redirection, append) */
				ret = add_redirection(&redir_specs[APPEND_OUTPUT_NUM],
						      prev_string, tok3,
						      next_token_nodel(toks),
						      redirs);
				break;
			}
		} else if (tok2->type & TOK_CLASS_STRING) {
			/* [N]>WORD  (output redirection) */
			ret = add_redirection(&redir_specs[REDIRECT_OUTPUT_NUM],
					      prev_string, tok2,
					      next_token_nodel(toks),
					      redirs);
			break;
		} else if (tok2->type & TOK_AMPERSAND &&
			   !tok2->preceded_by_whitespace)
		{
			/* [N]>&WORD (duplicate output file descriptor) */
			tok3 = next_token(toks);
			if (tok3 && tok3->type & TOK_CLASS_STRING) {
				ret = add_redirection(&redir_specs[DUP_OUTPUT_FD_NUM],
						      prev_string, tok3,
						      next_token_nodel(toks),
						      redirs);
				break;
			}
		}
		goto out_syntax_error;
	case TOK_LESS_THAN:
		/* < */
		tok2 = next_token(toks);
		if (!tok2)
			goto out_syntax_error;
		if (tok2->type & TOK_CLASS_STRING) {
			/* [N]<WORD */
			ret = add_redirection(&redir_specs[REDIRECT_INPUT_NUM],
					      prev_string, tok2,
					      next_token_nodel(toks),
					      redirs);
			break;
		} else if (tok2->type & TOK_LESS_THAN && !tok2->preceded_by_whitespace) {
			/* << */
			tok3 = next_token(toks);
			if (!tok3)
				goto out_syntax_error;
			if (tok3->type & TOK_LESS_THAN && !tok3->preceded_by_whitespace) {
				tok4 = next_token(toks);
				if (tok4 && tok4->type & TOK_CLASS_STRING) {
					/* <<<WORD (here string) */
					mysh_error("here strings not implemented");
					goto out_error;
				}
			} else if (tok3->type & TOK_CLASS_STRING) {
				/* <<WORD (here document) */
				mysh_error("here documents not implemented");
				goto out_error;
			}
		} else if (tok2->type & TOK_AMPERSAND && !tok2->preceded_by_whitespace) {
			tok3 = next_token(toks);
			/* [N]<&WORD  (duplicate input file descriptor) */
			if (tok3 && tok3->type & TOK_CLASS_STRING) {
				ret = add_redirection(&redir_specs[DUP_INPUT_FD_NUM],
						      prev_string, tok3,
						      next_token_nodel(toks),
						      redirs);
				break;
			}
		}
		goto out_syntax_error;
	case TOK_AMPERSAND:
		tok2 = next_token(toks);
		if (!tok2 && async_ret) {
			/* & */
			*async_ret = true;
			break;
		} else if (tok2 && tok2->type & TOK_GREATER_THAN) {
			/* &> */
			tok3 = next_token(toks);
			if (!tok3)
				goto out_syntax_error;
			if (tok3->type & TOK_CLASS_STRING) {
				/* &>WORD */
				/* Rewrite as
				 * >WORD 2>&1 */
				ret = add_redirection(&redir_specs[REDIRECT_OUTPUT_NUM],
						      NULL, tok3,
						      next_token_nodel(toks), redirs);
				if (ret)
					break;
				add_stderr_to_stdout_redirection(redirs);
				break;
			} else if (tok3->type & TOK_GREATER_THAN) {
				/* &>> */
				tok4 = next_token(toks);
				if (tok4 && tok4->type & TOK_CLASS_STRING) {
					/* &>>WORD */
					/* Rewrite as
					 * >>WORD 2>&1 */
					ret = add_redirection(&redir_specs[APPEND_OUTPUT_NUM],
							      NULL, tok4,
							      next_token_nodel(toks), redirs);
					if (ret)
						break;
					add_stderr_to_stdout_redirection(redirs);
					break;
				}

			}
		}
	default:
		goto out_syntax_error;
	}
out:
	free_token(tok);
	free_token(tok2);
	free_token(tok3);
	free_token(tok4);
	return ret;
out_error:
	ret = -1;
	goto out;
out_syntax_error:
	mysh_error("syntax error while parsing redirections");
	goto out_error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
testb $0x1, (%rax)
je 0x8070
movq $0x0, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x48(%rbp)
subl $0x40, %eax
je 0x80bc
jmp 0x8099
movl -0x48(%rbp), %eax
subl $0x80, %eax
je 0x8228
jmp 0x80a9
movl -0x48(%rbp), %eax
subl $0x200, %eax            # imm = 0x200
je 0x83e0
jmp 0x8523
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x80d5
jmp 0x8560
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x8155
movq -0x30(%rbp), %rax
testb $0x1, (%rax)
jne 0x8155
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x8150
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x8150
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x2c91(%rip), %rdi      # 0xadd0
addq $0xc, %rdi
callq 0x86a0
movl %eax, -0x44(%rbp)
jmp 0x8525
jmp 0x8223
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x81a0
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x2c3d(%rip), %rdi      # 0xadd0
callq 0x86a0
movl %eax, -0x44(%rbp)
jmp 0x8525
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x821f
movq -0x30(%rbp), %rax
testb $0x1, (%rax)
jne 0x821f
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x821d
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x821d
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x2bc4(%rip), %rdi      # 0xadd0
addq $0x18, %rdi
callq 0x86a0
movl %eax, -0x44(%rbp)
jmp 0x8525
jmp 0x821f
jmp 0x8221
jmp 0x8223
jmp 0x8560
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8241
jmp 0x8560
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x8296
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x2b4b(%rip), %rdi      # 0xadd0
addq $0x24, %rdi
callq 0x86a0
movl %eax, -0x44(%rbp)
jmp 0x8525
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x834c
movq -0x30(%rbp), %rax
testb $0x1, (%rax)
jne 0x834c
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x82d1
jmp 0x8560
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x8323
movq -0x38(%rbp), %rax
testb $0x1, (%rax)
jne 0x8323
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x8321
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x8321
leaq 0x2ca0(%rip), %rdi      # 0xafb5
movb $0x0, %al
callq 0x8c20
jmp 0x8557
jmp 0x8347
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x8345
leaq 0x2c99(%rip), %rdi      # 0xafd2
movb $0x0, %al
callq 0x8c20
jmp 0x8557
jmp 0x8347
jmp 0x83d9
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x83d7
movq -0x30(%rbp), %rax
testb $0x1, (%rax)
jne 0x83d7
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x83d5
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x83d5
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x2a0c(%rip), %rdi      # 0xadd0
addq $0x30, %rdi
callq 0x86a0
movl %eax, -0x44(%rbp)
jmp 0x8525
jmp 0x83d7
jmp 0x83d9
jmp 0x83db
jmp 0x8560
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x8407
cmpq $0x0, -0x20(%rbp)
je 0x8407
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0x8525
cmpq $0x0, -0x30(%rbp)
je 0x851f
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x851f
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x843e
jmp 0x8560
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x849b
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0xa0(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x295a(%rip), %rdi      # 0xadd0
xorl %eax, %eax
movl %eax, %esi
callq 0x86a0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x848d
jmp 0x8525
movq -0x18(%rbp), %rdi
callq 0x8910
jmp 0x8525
movq -0x38(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x851b
movq -0x8(%rbp), %rdi
callq 0x8660
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x8519
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x8519
movq -0x40(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88c0
movq -0xa8(%rbp), %rdx
movq %rax, %rcx
movq -0x18(%rbp), %r8
leaq 0x28da(%rip), %rdi      # 0xadd0
addq $0xc, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86a0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x850e
jmp 0x8525
movq -0x18(%rbp), %rdi
callq 0x8910
jmp 0x8525
jmp 0x851b
jmp 0x851d
jmp 0x851f
jmp 0x8521
jmp 0x8523
jmp 0x8560
jmp 0x8527
movq -0x28(%rbp), %rdi
callq 0x3380
movq -0x30(%rbp), %rdi
callq 0x3380
movq -0x38(%rbp), %rdi
callq 0x3380
movq -0x40(%rbp), %rdi
callq 0x3380
movl -0x44(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0x8527
leaq 0x2a8a(%rip), %rdi      # 0xaff1
movb $0x0, %al
callq 0x8c20
jmp 0x8557