// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r15
movl $0x30, %edi
callq 0x6754
movq %rax, %r14
movl 0x8(%r15), %eax
movl %eax, 0x18(%r14)
testq %rbp, %rbp
je 0x646d
testb $0x48, 0x10(%rbp)
je 0x6501
testb $0x2, (%r15)
jne 0x647c
xorl %ebx, %ebx
cmpb $0x0, (%r13)
jne 0x64cf
movq %rsp, %rbp
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x63af
movl %eax, %ebx
testl %eax, %eax
sete %al
movq (%rbp), %r12
testq %r12, %r12
setne %cl
testb %cl, %al
je 0x64cf
testb $0x1, (%r15)
jne 0x6542
movq (%r12), %rax
movq %rax, 0x8(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl 0x4(%r15), %eax
movl %eax, 0x10(%r14)
movb $0x1, (%r14)
xorl %ebp, %ebp
jmp 0x658a
testb $0x1, (%r15)
leaq 0xd77(%rip), %rax       # 0x7251
leaq 0x1a19(%rip), %rsi      # 0x7efa
cmoveq %rax, %rsi
leaq 0x196d(%rip), %rdi      # 0x7e59
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x23e0
cmpl $0x1, %ebx
sbbl %ebp, %ebp
orl %ebx, %ebp
jmp 0x6592
movq (%rbp), %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x2250
testl %eax, %eax
js 0x646d
movq (%rsp), %rcx
cmpq (%rbp), %rcx
je 0x646d
cmpb $0x0, (%rcx)
jne 0x646d
movl %eax, 0x18(%r14)
movq %rbp, %rdi
callq 0x685c
jmp 0x646d
movq (%r12), %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x2250
testl %eax, %eax
js 0x6569
movq 0x10(%rsp), %rcx
cmpq (%r12), %rcx
je 0x6569
cmpb $0x0, (%rcx)
je 0x65d0
leaq 0x1917(%rip), %rdi      # 0x7e87
xorl %eax, %eax
callq 0x23e0
movl $0x3, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0x658a
cmpl $0x3, %eax
jne 0x65bf
movq %r12, %rdi
callq 0x6870
testl %ebp, %ebp
je 0x65a0
movq %r14, %rdi
callq 0x2050
jmp 0x65bf
movq %r14, %rax
addq $0x20, %rax
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rax, 0x8(%rdx)
movq %rdx, 0x20(%r14)
movq %rcx, 0x28(%r14)
movq %rax, (%rcx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x8(%r14)
movb $0x0, (%r14)
xorl %ebp, %ebp
xorl %eax, %eax
jmp 0x6581
nop