// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r14
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r15
movl $0x30, %edi
callq 0x6540
movq %rax, %rbx
movl 0x8(%r15), %eax
movl %eax, 0x18(%rbx)
testq %rbp, %rbp
je 0x624c
testb $0x48, 0x10(%rbp)
je 0x631b
movb (%r15), %al
testb $0x2, %al
jne 0x6260
xorl %ebp, %ebp
cmpb $0x0, (%r13)
jne 0x62e8
movq %rbx, (%rsp)
movq %r14, %rbx
leaq 0x8(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x6191
movl %eax, %ebp
testl %eax, %eax
sete %cl
movq (%r14), %r12
testq %r12, %r12
setne %dl
movb (%r15), %al
testb %dl, %cl
je 0x62e4
testb $0x1, %al
movq %rbx, %r14
jne 0x635e
movq (%r12), %rax
movq (%rsp), %rbx
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl 0x4(%r15), %eax
movl %eax, 0x10(%rbx)
movb $0x1, (%rbx)
movq %r12, %rdi
callq 0x665c
movq %rbx, %rax
addq $0x20, %rax
movq 0x8(%r14), %rcx
movq %rax, 0x8(%r14)
movq %r14, 0x20(%rbx)
movq %rcx, 0x28(%rbx)
movq %rax, (%rcx)
xorl %r14d, %r14d
jmp 0x63ad
movq (%rsp), %rbx
testb $0x1, %al
leaq 0xf60(%rip), %rax       # 0x7251
leaq 0x1c02(%rip), %rsi      # 0x7efa
cmoveq %rax, %rsi
leaq 0x1b56(%rip), %rdi      # 0x7e59
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x23e0
cmpl $0x1, %ebp
sbbl %r14d, %r14d
orl %ebp, %r14d
jmp 0x63a5
movq (%rbp), %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x2250
testl %eax, %eax
js 0x624c
movq 0x8(%rsp), %rcx
cmpq (%rbp), %rcx
je 0x624c
cmpb $0x0, (%rcx)
jne 0x624c
movl %eax, 0x18(%rbx)
movq %rbp, %rdi
callq 0x6648
jmp 0x624c
movq (%r12), %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x2250
testl %eax, %eax
movq (%rsp), %rbx
js 0x6389
movq 0x10(%rsp), %rcx
cmpq (%r12), %rcx
je 0x6389
cmpb $0x0, (%rcx)
je 0x63bf
leaq 0x1af7(%rip), %rdi      # 0x7e87
xorl %eax, %eax
callq 0x23e0
movq %r12, %rdi
callq 0x665c
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x2050
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x8(%rbx)
movb $0x0, (%rbx)
jmp 0x62ba
nop