// File: /workspace/github_c_makefile_star2_O3/ebiggers[P]mysh/mysh_main.c
// Function: read_loop
int read_loop(int in_fd, bool interactive)
{
	char *input_buf;
	size_t input_data_begin;
	size_t input_data_end;
	size_t input_buf_len;
	int ret;
	struct list_head cur_tok_list;
	int orig_alias_expansion_disabled = mysh_alias_expansion_disabled;

	mysh_alias_expansion_disabled = !interactive;

	input_buf_len = DEFAULT_INPUT_BUFSIZE;
	input_buf = xmalloc(input_buf_len);
	input_data_begin = 0;
	input_data_end = 0;
	INIT_LIST_HEAD(&cur_tok_list);
	for (;;) {
		ssize_t bytes_read;
		size_t bytes_remaining;
		size_t bytes_to_read;

		/* Check for background pipelines that have terminated */
		check_for_finished_background_pipelines();

		if (interactive) {
		#ifdef WITH_READLINE
			/* Interactive shell, linked with libreadline */
			char *p;

			/* Call readline() to get the next line of input,
			 * allowing it to be interrupted. */
			set_up_sigint_handler();
			p = readline(get_prompt(&cur_tok_list));
			remove_sigint_handler();

			if (sigint_occurred) {
				/* SIGINT received; discard the line of input
				 * along with all previous lines that are part
				 * of the same shell statement. */
				sigint_occurred = false;
				input_data_begin = 0;
				input_data_end = 0;
				free_tok_list(&cur_tok_list);
				puts("^C");
				free(p);
				continue;
			} else {
				/* No SIGINT received.  Add the line to the
				 * readline history if it's non-empty; then
				 * transfer it to the input buffer for parsing.
				 * */
				if (!p)
					goto out_break_read_loop;
				if (*p)
					add_history(p);
				bytes_read = strlen(p) + 1;
				if (bytes_read > input_buf_len - input_data_end) {
					/* Out of space; resize the buffer */
					input_buf_len *= 2;
					if (bytes_read > input_buf_len - input_data_end)
						input_buf_len += bytes_read -
							(input_buf_len - input_data_end);
					input_buf = xrealloc(input_buf, input_buf_len);
				}
				memcpy(&input_buf[input_data_end], p, bytes_read);
				input_buf[input_data_end + bytes_read - 1] = '\n';
				free(p);
				goto skip_raw_read;
			}
		#else
			/* Interactive shell, not linked with libreadline */

			/* Print the prompt ourselves when not relying on
			 * readline, then fall through to the code below that
			 * checks the buffer size, then does a raw read(). */
			fputs(get_prompt(&cur_tok_list), stdout);
			fflush(stdout);
		#endif
		}

	read_again_check_buffer:
		/* Check whether less than half the distance to the end of the
		 * buffer is remaining.  This part is executed in noninteractive
		 * shells as well as interactive shells without readline
		 * support. */
		if (input_buf_len - input_data_end < input_buf_len / 2) {
			if (input_data_begin > input_buf_len / 10) {
				/* Move data to beginning of buffer to make more
				 * room */
				bytes_remaining = input_data_end - input_data_begin;
				memmove(input_buf, &input_buf[input_data_begin],
					bytes_remaining);
				input_data_begin = 0;
				input_data_end = bytes_remaining;
			} else if (input_data_end == input_buf_len
			#ifdef WITH_READLINE
				   && !interactive
			#endif
				   )
			{
				/* Buffer is full or almost full */
				input_buf_len *= 2;
				input_buf = xrealloc(input_buf, input_buf_len);
			}
		}

	read_again:
		/* Read data into the buffer with read(), allowing the read() to
		 * be interrupted.  This part is executed in noninteractive
		 * shells as well as interactive shells without readline
		 * support. */
	#ifndef WITH_READLINE
		if (interactive)
			set_up_sigint_handler();
	#endif
		bytes_to_read = input_buf_len - input_data_end;
		bytes_read = read(in_fd, &input_buf[input_data_end], bytes_to_read);
	#ifndef WITH_READLINE
		if (interactive)
			remove_sigint_handler();
	#endif
#ifdef WITH_READLINE
	skip_raw_read:
#endif
		if (bytes_read == 0) {
			/* EOF */
			if (input_data_end - input_data_begin != 0) {
				mysh_error("unexpected end of input");
				mysh_last_exit_status = -1;
			}
			goto out_break_read_loop;
		} else if (bytes_read < 0) {
			/* Read error */
			if (errno == EINTR) {
			#ifndef WITH_READLINE
				if (interactive) {
					/* SIGINT received; discard the line of
					 * input along with all previous lines
					 * that are part of the same shell
					 * statement. */
					input_data_begin = 0;
					input_data_end = 0;
					free_tok_list(&cur_tok_list);
					putchar('\n');
					fflush(stdout);
					continue;
				}
			#endif
				goto read_again;
			}
			mysh_error_with_errno("error reading input");
			mysh_last_exit_status = -1;
			goto out_break_read_loop;
		} else {
			/* Successful read */

			input_data_end += bytes_read;
			bytes_remaining = input_data_end - input_data_begin;

			/* Execute as many shell statements as possible */
			ret = execute_shell_input(&cur_tok_list,
						  &input_buf[input_data_begin],
						  &bytes_remaining);
			input_data_begin = input_data_end - bytes_remaining;
			switch (ret) {
			case LEX_ERROR:
				/* The input was invalid.  Break the loop. */
				mysh_last_exit_status = -1;
				goto out_break_read_loop;
			case LEX_NOT_ENOUGH_INPUT:
				/* The current input ends in the middle of a
				 * shell statement.  Jump back to the
				 * appropriate place to handle more input. */
			#ifdef WITH_READLINE
				if (interactive)
					continue;
			#endif
				goto read_again_check_buffer;
			default:
				/* The input ended on a shell statement boundary
				 * and was executed, but the exit status was not
				 * necessarily 0, and there may have been other
				 * errors.  mysh_exit_on_error indicates whether
				 * the 'set -e' shell option is set, and it
				 * requires exiting the shell early when a
				 * command is unsuccessful. */
				mysh_last_exit_status = ret;
				if (mysh_last_exit_status != 0 && mysh_exit_on_error)
					goto out_break_read_loop;
				break;
			}
		}
	}
out_break_read_loop:
	close(in_fd);
	free(input_buf);
	mysh_alias_expansion_disabled = orig_alias_expansion_disabled;
	return mysh_last_exit_status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %edi, 0x14(%rsp)
movl 0x7c74(%rip), %eax      # 0xb224
movl %eax, 0x34(%rsp)
movl %esi, 0x24(%rsp)
movl %esi, %eax
xorb $0x1, %al
movzbl %al, %eax
movl %eax, 0x7c5f(%rip)      # 0xb224
movl $0x1000, %eax           # imm = 0x1000
movq %rax, (%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x6540
movq %rax, 0x18(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, (%rax)
movq %rax, 0x8(%rax)
leaq 0x50(%rsp), %r12
xorl %ecx, %ecx
movq $0x0, 0x8(%rsp)
movq 0x7bf8(%rip), %rbp      # 0xb1f8
leaq 0x7bf1(%rip), %rax      # 0xb1f8
cmpq %rax, %rbp
movq %rcx, %r13
je 0x36b6
movq %rbp, %r14
movq (%rbp), %rbp
movl 0x14(%r14), %eax
xorl %ebx, %ebx
movl %eax, %r15d
movl %ebx, %ebx
movl 0x1c(%r14,%rbx,4), %edi
testl %edi, %edi
js 0x3654
movq %r12, %rsi
movl $0x1, %edx
callq 0x22b0
testl %eax, %eax
je 0x3665
cmpl $-0x1, %eax
jne 0x3659
leaq 0x419d(%rip), %rdi      # 0x77e8
xorl %eax, %eax
callq 0x249f
jmp 0x3665
decl %r15d
jmp 0x366c
decl %r15d
movl $0xffffffff, 0x1c(%r14,%rbx,4) # imm = 0xFFFFFFFF
movq %r13, %rcx
movl 0x14(%r14), %eax
incl %ebx
cmpl %eax, %ebx
jne 0x3623
testl %r15d, %r15d
jne 0x36a6
movl 0x10(%r14), %esi
movl 0x18(%r14), %edx
leaq 0x416d(%rip), %rdi      # 0x77f3
xorl %eax, %eax
callq 0x2140
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, 0x8(%rax)
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x2050
movq %r13, %rcx
leaq 0x7b4b(%rip), %rax      # 0xb1f8
cmpq %rax, %rbp
jne 0x3613
cmpb $0x0, 0x24(%rsp)
je 0x3720
movb $0x0, 0x7b64(%rip)      # 0xb228
movl $0x90, %edx
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2180
leaq 0xee0(%rip), %rax       # 0x45bf
movq %rax, 0x50(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
callq 0x23a0
movl $0x2, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x20a0
leaq 0x38(%rsp), %rax
cmpq %rax, 0x38(%rsp)
movl 0x14(%rsp), %ebp
je 0x3736
leaq 0x4109(%rip), %rdi      # 0x7820
leaq 0x4106(%rip), %rsi      # 0x7824
jmp 0x3744
movq %rcx, %rbx
movl 0x14(%rsp), %ebp
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rcx
jmp 0x3901
leaq 0x40d6(%rip), %rdi      # 0x7813
leaq 0x40d3(%rip), %rsi      # 0x7817
callq 0x45d4
movq 0x18(%rsp), %r15
leaq 0x7aeb(%rip), %rdi      # 0xb240
callq 0x21b0
movq %rax, %rbx
movl $0x90, %edx
leaq 0x58(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2180
movq $0x1, 0x50(%rsp)
movq %r14, %rdi
movl $0x2, %esi
callq 0x23a0
movl $0x2, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x20a0
cmpb $0x1, 0x7a8b(%rip)      # 0xb228
jne 0x37cd
movb $0x0, 0x7a82(%rip)      # 0xb228
leaq 0x38(%rsp), %rdi
callq 0x2fd0
leaq 0x3cd1(%rip), %rdi      # 0x7488
callq 0x2080
movq %rbx, %rdi
callq 0x2050
xorl %ebx, %ebx
xorl %ecx, %ecx
jmp 0x38ef
testq %rbx, %rbx
je 0x39c4
cmpb $0x0, (%rbx)
je 0x37e3
movq %rbx, %rdi
callq 0x20c0
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x2100
movq %rax, %r14
leaq 0x1(%rax), %rbx
movq (%rsp), %rsi
movq %rsi, %rax
movq %r13, %rcx
subq %r13, %rax
cmpq %rax, %rbx
jbe 0x3835
leaq (%rsi,%rsi), %rax
subq %rcx, %rax
movq %rbx, %rcx
subq %rax, %rcx
movl $0x0, %eax
cmovaeq %rcx, %rax
leaq (%rax,%rsi,2), %rsi
movq %r15, %rdi
movq %rsi, (%rsp)
callq 0x6552
movq %r13, %rcx
movq %rax, %r15
movq %rcx, 0x48(%rsp)
leaq (%r15,%rcx), %rdi
movq 0x18(%rsp), %rbp
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2260
addq 0x48(%rsp), %r14
movb $0xa, (%r15,%r14)
movq %rbp, %rdi
callq 0x2050
movq (%rsp), %r14
movl 0x14(%rsp), %ebp
testq %rbx, %rbx
je 0x3995
movq %r14, (%rsp)
js 0x38ce
addq %r13, %rbx
movq %rbx, %rax
movq 0x8(%rsp), %rsi
subq %rsi, %rax
movq %rax, 0x28(%rsp)
addq %r15, %rsi
leaq 0x38(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x34c7
movq %rbx, %rcx
subq 0x28(%rsp), %rcx
cmpl $0xfffff830, %eax       # imm = 0xFFFFF830
je 0x38e8
cmpl $0xfffffc18, %eax       # imm = 0xFFFFFC18
je 0x39ba
movl %eax, 0x7964(%rip)      # 0xb220
testl %eax, %eax
je 0x38ef
cmpl $0x0, 0x7965(%rip)      # 0xb22c
je 0x38ef
jmp 0x39c4
callq 0x2060
cmpl $0x4, (%rax)
jne 0x39ac
movq (%rsp), %r14
movq %r13, %rbx
jmp 0x3979
cmpb $0x0, 0x24(%rsp)
je 0x3901
movq %rcx, 0x8(%rsp)
movq %r15, 0x18(%rsp)
movq %rbx, %rcx
jmp 0x35f9
movq %rcx, 0x8(%rsp)
movq (%rsp), %r14
movq %r14, %rax
subq %rbx, %rax
movq %r14, %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x3979
movq %r14, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
shrq $0x3, %rdx
movq 0x8(%rsp), %rsi
cmpq %rdx, %rsi
jbe 0x395f
subq %rsi, %rbx
movq %rbx, 0x28(%rsp)
addq %r15, %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x22a0
movq 0x28(%rsp), %rbx
movq $0x0, 0x8(%rsp)
jmp 0x3979
cmpq %rbx, %r14
jne 0x3979
addq %r14, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x6552
movq %rax, %r15
movq (%rsp), %rbx
movq %r14, %rdx
subq %rbx, %rdx
movq %rbx, %r13
leaq (%r15,%rbx), %rsi
movl %ebp, %edi
callq 0x2210
movq %rax, %rbx
jmp 0x3868
cmpq 0x8(%rsp), %r13
je 0x39c4
leaq 0x3acd(%rip), %rdi      # 0x7470
xorl %eax, %eax
callq 0x23e0
jmp 0x39ba
leaq 0x3ad8(%rip), %rdi      # 0x748b
xorl %eax, %eax
callq 0x249f
movl $0xffffffff, 0x785c(%rip) # imm = 0xFFFFFFFF
movl %ebp, %edi
callq 0x21c0
movq %r15, %rdi
callq 0x2050
movl 0x34(%rsp), %eax
movl %eax, 0x7847(%rip)      # 0xb224
movl 0x783d(%rip), %eax      # 0xb220
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq