// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movl %edi, 0x14(%rsp)
movl 0x7f70(%rip), %eax      # 0xb224
movl %eax, 0x34(%rsp)
movl %esi, 0x10(%rsp)
movl %esi, %eax
xorb $0x1, %al
movzbl %al, %eax
movl %eax, 0x7f5b(%rip)      # 0xb224
movl $0x1000, %eax           # imm = 0x1000
movq %rax, 0x18(%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x6099
movq %rax, (%rsp)
leaq 0x38(%rsp), %rax
movq %rax, (%rax)
movq %rax, 0x8(%rax)
leaq 0x54(%rsp), %r15
pushq $0x1
popq %rbp
movq $0x0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x7eea(%rip), %r13      # 0xb1f8
leaq 0x7ee3(%rip), %rax      # 0xb1f8
cmpq %rax, %r13
je 0x33b0
movq %r13, %r12
movq (%r13), %r13
movl 0x14(%r12), %eax
xorl %r14d, %r14d
movl %eax, %ebx
movl %r14d, %r14d
movl 0x1c(%r12,%r14,4), %edi
testl %edi, %edi
js 0x335e
movq %r15, %rsi
movl %ebp, %edx
callq 0x22b0
testl %eax, %eax
je 0x336a
cmpl $-0x1, %eax
jne 0x3362
leaq 0x4493(%rip), %rdi      # 0x77e8
xorl %eax, %eax
callq 0x5fb7
jmp 0x336a
decl %ebx
jmp 0x336f
decl %ebx
orl $-0x1, 0x1c(%r12,%r14,4)
movl 0x14(%r12), %eax
incl %r14d
cmpl %eax, %r14d
jne 0x332f
testl %ebx, %ebx
jne 0x330e
movl 0x10(%r12), %esi
movl 0x18(%r12), %edx
leaq 0x4467(%rip), %rdi      # 0x77f3
xorl %eax, %eax
callq 0x2140
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq %rcx, 0x8(%rax)
movq %rax, (%rcx)
movq %r12, %rdi
callq 0x2050
jmp 0x330e
cmpb $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rbx
je 0x33eb
movb $0x0, 0x7e65(%rip)      # 0xb228
leaq 0xd0e(%rip), %rdi       # 0x40d8
callq 0x4083
leaq 0x38(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x33fa
leaq 0x443e(%rip), %rdi      # 0x7820
leaq 0x443b(%rip), %rsi      # 0x7824
jmp 0x3408
movq 0x8(%rsp), %r12
movq 0x28(%rsp), %rsi
jmp 0x3597
leaq 0x4412(%rip), %rdi      # 0x7813
leaq 0x440f(%rip), %rsi      # 0x7817
callq 0x40ea
leaq 0x7e2c(%rip), %rdi      # 0xb240
callq 0x21b0
movq %rax, %r14
callq 0x42a5
cmpb $0x1, 0x7e00(%rip)      # 0xb228
jne 0x3459
movb $0x0, 0x7df7(%rip)      # 0xb228
leaq 0x38(%rsp), %rdi
callq 0x2d08
leaq 0x4046(%rip), %rdi      # 0x7488
callq 0x2080
movq %r14, %rdi
callq 0x2050
xorl %r12d, %r12d
xorl %esi, %esi
jmp 0x3583
testq %r14, %r14
je 0x3667
cmpb $0x0, (%r14)
je 0x3470
movq %r14, %rdi
callq 0x20c0
movq %r14, 0x48(%rsp)
movq %r14, %rdi
callq 0x2100
movq %rax, %r13
leaq 0x1(%rax), %r12
movq %rbx, %rax
movq 0x8(%rsp), %r14
subq %r14, %rax
cmpq %rax, %r12
jbe 0x34c1
leaq (%rbx,%rbx), %rax
subq %r14, %rax
movq %r12, %rcx
subq %rax, %rcx
movl $0x0, %eax
cmovaeq %rcx, %rax
leaq (%rax,%rbx,2), %rbx
movq (%rsp), %rdi
movq %rbx, 0x18(%rsp)
movq %rbx, %rsi
callq 0x60bc
jmp 0x34c5
movq (%rsp), %rax
leaq (%rax,%r14), %rdi
movq %r14, 0x8(%rsp)
movq 0x48(%rsp), %r14
movq %r14, %rsi
movq %r12, %rdx
movq %rax, %rbx
callq 0x2260
addq 0x8(%rsp), %r13
movq %rbx, (%rsp)
movb $0xa, (%rbx,%r13)
movq %r14, %rdi
callq 0x2050
movq 0x18(%rsp), %rbx
movq 0x28(%rsp), %r14
testq %r12, %r12
je 0x363b
js 0x3564
addq 0x8(%rsp), %r12
movq %r12, %rax
subq %r14, %rax
movq %rax, 0x20(%rsp)
addq (%rsp), %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
leaq 0x20(%rsp), %rdx
callq 0x31dd
movq %r12, %rsi
subq 0x20(%rsp), %rsi
cmpl $0xfffff830, %eax       # imm = 0xFFFFF830
je 0x357c
cmpl $0xfffffc18, %eax       # imm = 0xFFFFFC18
je 0x3660
movl %eax, 0x7cce(%rip)      # 0xb220
testl %eax, %eax
je 0x3583
cmpl $0x0, 0x7ccf(%rip)      # 0xb22c
je 0x3583
jmp 0x3667
callq 0x2060
cmpl $0x4, (%rax)
jne 0x3652
movq %rbx, %r13
movq 0x8(%rsp), %rbx
jmp 0x35ee
cmpb $0x0, 0x10(%rsp)
je 0x3597
movq %rsi, 0x28(%rsp)
movq %rbx, 0x18(%rsp)
movq %r12, 0x8(%rsp)
jmp 0x3307
movq %rbx, %rax
subq %r12, %rax
movq %rbx, %rcx
shrq %rcx
cmpq %rcx, %rax
movq %rsi, %r14
jae 0x35e8
movq %rbx, %rax
xorl %edx, %edx
pushq $0xa
popq %rcx
divq %rcx
cmpq %rax, %rsi
jbe 0x3619
subq %rsi, %r12
movq %r12, 0x20(%rsp)
movq %rbx, %r13
movq (%rsp), %rbx
addq %rbx, %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x22a0
movq 0x20(%rsp), %rcx
movq %rbx, %rax
movq %rcx, %rbx
xorl %r14d, %r14d
jmp 0x35f2
movq %rbx, %r13
movq %r12, %rbx
movq (%rsp), %rax
movq %r13, %rdx
subq %rbx, %rdx
movq %rax, (%rsp)
movq %rbx, 0x8(%rsp)
leaq (%rax,%rbx), %rsi
movl 0x14(%rsp), %edi
callq 0x2210
movq %rax, %r12
movq %r13, %rbx
jmp 0x3501
cmpq %r12, %rbx
movq (%rsp), %rax
jne 0x3633
leaq (%rbx,%rbx), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x60bc
jmp 0x35f2
movq %rbx, %r13
movq %r12, %rbx
jmp 0x35f2
cmpq %r14, 0x8(%rsp)
je 0x3667
leaq 0x3e27(%rip), %rdi      # 0x7470
xorl %eax, %eax
callq 0x5ef8
jmp 0x3660
leaq 0x3e32(%rip), %rdi      # 0x748b
xorl %eax, %eax
callq 0x5fb7
orl $-0x1, 0x7bb9(%rip)     # 0xb220
movl 0x14(%rsp), %edi
callq 0x21c0
movq (%rsp), %rdi
callq 0x2050
movl 0x34(%rsp), %eax
movl %eax, 0x7ba1(%rip)      # 0xb224
movl 0x7b97(%rip), %eax      # 0xb220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq