// File: /workspace/github_c_makefile_star2_O0/ebiggers[P]mysh/mysh_parse.c
// Function: add_redirection
static int add_redirection(const struct redir_spec *spec,
			   struct string *left_adjacent_string,
			   struct token *next,
			   struct token *next_next,
			   struct list_head *redirs)
{
	struct redirection *redir = xmalloc(sizeof(struct redirection));
	int ret = 0;
	struct string *right_string;

	redir->dest_fd = spec->default_left_fd;
	if (left_adjacent_string &&
	    !(left_adjacent_string->flags & (STRING_FLAG_FILENAME_EXPANDED |
					     STRING_FLAG_PARAM_EXPANDED)))
	{
		char *tmp;
		int left_fd = strtol(left_adjacent_string->chars, &tmp, 10);
		if (left_fd >= 0 && left_fd <= INT_MAX &&
		    tmp != left_adjacent_string->chars && !*tmp) {
			redir->dest_fd = left_fd;
			clear_string(left_adjacent_string);
		}
	}

	if (!next ||
	    (!spec->accepts_whitespace_before_right_string &&
	     next->preceded_by_whitespace)
	    || (ret = expand_single_string(next, next_next, &right_string)) || !right_string)
	{
		mysh_error("expected single %s after redirection operator",
			   spec->requires_right_string_is_fd ? "file descriptor" : "filename");
		if (ret == 0)
			ret = -1;
		goto out;
	}

	if (spec->requires_right_string_is_fd) {
		char *tmp;
		int right_fd = strtol(right_string->chars, &tmp, 10);
		if (right_fd >= 0 && right_fd <= INT_MAX &&
		    tmp != right_string->chars && !*tmp) {
			redir->src_fd = right_fd;
		} else {
			mysh_error("expected valid file descriptor "
				   "after redirection operator");
			ret = -1;
			goto out_free_string;
		}
		redir->is_file = false;
	} else {
		redir->src_filename = right_string->chars;
		right_string->chars = NULL;
		right_string->len = 0;
		redir->open_flags = spec->open_flags;
		redir->is_file = true;
	}
out_free_string:
	free_string(right_string);
out:
	if (ret == 0)
		list_add_tail(&redir->list, redirs);
	else
		free(redir);
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x30, %edi
callq 0x8e00
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x8747
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x48, %eax
cmpl $0x0, %eax
jne 0x8747
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x2250
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0x8745
cmpl $0x7fffffff, -0x4c(%rbp) # imm = 0x7FFFFFFF
jg 0x8745
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x8745
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x8745
movl -0x4c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rdi
callq 0x8fe0
jmp 0x8747
cmpq $0x0, -0x18(%rbp)
je 0x8789
movq -0x8(%rbp), %rax
movb (%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x8769
movq -0x18(%rbp), %rax
testb $0x1, (%rax)
jne 0x8789
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x8570
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jne 0x8789
cmpq $0x0, -0x40(%rbp)
jne 0x87c9
movq -0x8(%rbp), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %ecx
leaq 0x1ab6(%rip), %rsi      # 0xa251
leaq 0x2918(%rip), %rax      # 0xb0ba
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x2869(%rip), %rdi      # 0xb019
movb $0x0, %al
callq 0x8c20
cmpl $0x0, -0x34(%rbp)
jne 0x87c4
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
jmp 0x8888
movq -0x8(%rbp), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x8842
movq -0x40(%rbp), %rax
movq (%rax), %rdi
leaq -0x58(%rbp), %rsi
movl $0xa, %edx
callq 0x2250
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x8822
cmpl $0x7fffffff, -0x5c(%rbp) # imm = 0x7FFFFFFF
jg 0x8822
movq -0x58(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
je 0x8822
movq -0x58(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x8822
movl -0x5c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x8839
leaq 0x281e(%rip), %rdi      # 0xb047
movb $0x0, %al
callq 0x8c20
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
jmp 0x887f
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
jmp 0x887d
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rax
movb $0x1, (%rax)
jmp 0x887f
movq -0x40(%rbp), %rdi
callq 0x9020
cmpl $0x0, -0x34(%rbp)
jne 0x88a1
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rsi
callq 0x7d30
jmp 0x88aa
movq -0x30(%rbp), %rdi
callq 0x2050
movl -0x34(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)