// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x30
popq %rdi
callq 0x6099
movq %rax, %rbx
movl 0x8(%r15), %eax
movl %eax, 0x18(%rbx)
testq %rbp, %rbp
je 0x5bda
testb $0x48, 0x10(%rbp)
je 0x5ca9
movb (%r15), %al
testb $0x2, %al
jne 0x5bee
xorl %ebp, %ebp
cmpb $0x0, (%r13)
jne 0x5c76
movq %rbx, (%rsp)
movq %r14, %rbx
leaq 0x8(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b24
movl %eax, %ebp
testl %eax, %eax
sete %cl
movq (%r14), %r12
testq %r12, %r12
setne %dl
movb (%r15), %al
testb %dl, %cl
je 0x5c72
testb $0x1, %al
movq %rbx, %r14
jne 0x5cea
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 0x6193
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 0x5d35
movq (%rsp), %rbx
testb $0x1, %al
leaq 0x15d2(%rip), %rax      # 0x7251
leaq 0x2274(%rip), %rsi      # 0x7efa
cmoveq %rax, %rsi
leaq 0x21c8(%rip), %rdi      # 0x7e59
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x5ef8
cmpl $0x1, %ebp
sbbl %r14d, %r14d
orl %ebp, %r14d
jmp 0x5d2d
movq (%rbp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2250
testl %eax, %eax
js 0x5bda
movq 0x8(%rsp), %rcx
cmpq (%rbp), %rcx
je 0x5bda
cmpb $0x0, (%rcx)
jne 0x5bda
movl %eax, 0x18(%rbx)
movq %rbp, %rdi
callq 0x617f
jmp 0x5bda
movq (%r12), %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2250
testl %eax, %eax
movq (%rsp), %rbx
js 0x5d13
movq 0x10(%rsp), %rcx
cmpq (%r12), %rcx
je 0x5d13
cmpb $0x0, (%rcx)
je 0x5d47
leaq 0x216d(%rip), %rdi      # 0x7e87
xorl %eax, %eax
callq 0x5ef8
movq %r12, %rdi
callq 0x6193
pushq $-0x1
popq %r14
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 0x5c48