// File: /workspace/github_c_makefile_star2_O1/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, 0x24(%rsp)
movl 0x7c3f(%rip), %eax      # 0xb224
movl %eax, 0x3c(%rsp)
movl %esi, 0xc(%rsp)
movl %esi, %eax
xorb $0x1, %al
movzbl %al, %eax
movl %eax, 0x7c2a(%rip)      # 0xb224
movl $0x1000, %eax           # imm = 0x1000
movq %rax, 0x18(%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x6754
movq %rax, (%rsp)
leaq 0x40(%rsp), %rax
movq %rax, (%rax)
movq %rax, 0x8(%rax)
leaq 0x50(%rsp), %r13
leaq 0x41be(%rip), %rbx      # 0x77e8
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbp, 0x30(%rsp)
movq %r12, 0x10(%rsp)
movq 0x7bb8(%rip), %r15      # 0xb1f8
leaq 0x7bb1(%rip), %rax      # 0xb1f8
cmpq %rax, %r15
je 0x36e2
movq %r15, %r12
movq (%r15), %r15
movl 0x14(%r12), %ebp
xorl %r14d, %r14d
movl %r14d, %r14d
cmpl $0x0, 0x1c(%r12,%r14,4)
js 0x3690
movl 0x1c(%r12,%r14,4), %edi
movq %r13, %rsi
movl $0x1, %edx
callq 0x22b0
testl %eax, %eax
je 0x369f
cmpl $-0x1, %eax
jne 0x3694
movq %rbx, %rdi
xorl %eax, %eax
callq 0x249f
jmp 0x369f
decl %ebp
jmp 0x369f
decl %ebp
movl $0xffffffff, 0x1c(%r12,%r14,4) # imm = 0xFFFFFFFF
incl %r14d
cmpl 0x14(%r12), %r14d
jne 0x365e
testl %ebp, %ebp
jne 0x3640
movl 0x10(%r12), %esi
movl 0x18(%r12), %edx
leaq 0x4135(%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 0x3640
cmpb $0x0, 0xc(%rsp)
je 0x374c
movb $0x0, 0x7b38(%rip)      # 0xb228
movl $0x98, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2180
leaq 0xf81(%rip), %rax       # 0x4687
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x23a0
movl $0x2, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x20a0
leaq 0x40(%rsp), %rax
cmpq %rax, 0x40(%rsp)
je 0x37dc
leaq 0x40e0(%rip), %rdi      # 0x7820
leaq 0x40dd(%rip), %rsi      # 0x7824
jmp 0x37ea
movq 0x10(%rsp), %r12
movq 0x30(%rsp), %rbp
movq 0x18(%rsp), %r14
movq %r14, %rax
subq %r12, %rax
movq %r14, %rcx
shrq %rcx
cmpq %rcx, %rax
movq (%rsp), %r15
jae 0x39f7
movq %r14, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
shrq $0x3, %rdx
cmpq %rdx, %rbp
jbe 0x37b2
subq %rbp, %r12
movq %r12, 0x50(%rsp)
addq %r15, %rbp
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x22a0
movq 0x50(%rsp), %r12
xorl %ebp, %ebp
jmp 0x39f7
cmpq %r12, %r14
jne 0x39f7
cmpb $0x0, 0xc(%rsp)
jne 0x39f7
addq %r14, %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x6766
movq %rax, %r15
jmp 0x39f7
leaq 0x4030(%rip), %rdi      # 0x7813
leaq 0x402d(%rip), %rsi      # 0x7817
callq 0x469c
leaq 0x7a4a(%rip), %rdi      # 0xb240
callq 0x21b0
movq %rax, %r12
movl $0x98, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2180
movq $0x1, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
movl $0x2, %esi
callq 0x23a0
movl $0x2, %edi
movq %r13, %rsi
xorl %edx, %edx
callq 0x20a0
movb 0x79ed(%rip), %bpl      # 0xb228
cmpb $0x1, %bpl
movq 0x28(%rsp), %r14
jne 0x3880
movb $0x0, 0x79db(%rip)      # 0xb228
leaq 0x40(%rsp), %rdi
callq 0x2fc0
leaq 0x3c2a(%rip), %rdi      # 0x7488
callq 0x2080
movl $0x3, %r15d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x392e
testq %r12, %r12
je 0x38ed
cmpb $0x0, (%r12)
je 0x3894
movq %r12, %rdi
callq 0x20c0
movq %r12, %rdi
callq 0x2100
movq %rax, %r15
leaq 0x1(%rax), %r14
movq 0x18(%rsp), %rsi
movq %rsi, %rax
movq 0x10(%rsp), %rcx
subq %rcx, %rax
cmpq %rax, %r14
jbe 0x38f7
leaq (%rsi,%rsi), %rax
subq %rcx, %rax
movq %r14, %rcx
subq %rax, %rcx
movl $0x0, %eax
cmovaeq %rcx, %rax
leaq (%rax,%rsi,2), %rsi
movq (%rsp), %rdi
movq %rsi, 0x18(%rsp)
callq 0x6766
movq 0x10(%rsp), %rcx
movq %r14, %rdx
movq %rax, %r14
jmp 0x38fe
movl $0x4, %r15d
xorl %ebp, %ebp
jmp 0x393a
movq %r14, %rdx
movq (%rsp), %r14
leaq (%r14,%rcx), %rdi
movq %r12, %rsi
movq %r12, 0x28(%rsp)
movq %rdx, %r12
callq 0x2260
addq 0x10(%rsp), %r15
movq %r14, (%rsp)
movb $0xa, (%r14,%r15)
movl $0x5, %r15d
movq %r12, %r14
movq 0x28(%rsp), %r12
xorb $0x1, %bpl
movq %r12, %rdi
callq 0x2050
testb %bpl, %bpl
movq 0x10(%rsp), %r12
movq 0x30(%rsp), %rbp
je 0x3a4c
testq %r14, %r14
je 0x39bc
js 0x39e4
addq %r14, %r12
movq %r12, %rax
subq %rbp, %rax
movq %rax, 0x50(%rsp)
addq (%rsp), %rbp
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x34d2
movq %r12, %rbp
subq 0x50(%rsp), %rbp
cmpl $0xfffff830, %eax       # imm = 0xFFFFF830
je 0x3a1b
cmpl $0xfffffc18, %eax       # imm = 0xFFFFFC18
je 0x3a3c
movl %eax, 0x7882(%rip)      # 0xb220
testl %eax, %eax
setne %al
cmpl $0x0, 0x7882(%rip)      # 0xb22c
setne %cl
andb %al, %cl
movzbl %cl, %r15d
shll $0x2, %r15d
jmp 0x3a4c
movl $0x4, %r15d
cmpq %rbp, %r12
je 0x39df
leaq 0x3aa2(%rip), %rdi      # 0x7470
xorl %eax, %eax
callq 0x23e0
movl $0xffffffff, 0x7841(%rip) # imm = 0xFFFFFFFF
xorl %r14d, %r14d
jmp 0x3a4c
callq 0x2060
cmpl $0x4, (%rax)
jne 0x3a2e
movq 0x18(%rsp), %r14
movq (%rsp), %r15
movq %r14, 0x18(%rsp)
subq %r12, %r14
movq %r15, (%rsp)
leaq (%r15,%r12), %rsi
movl 0x24(%rsp), %edi
movq %r14, %rdx
callq 0x2210
movq %rax, %r14
jmp 0x394d
movl $0x3, %r15d
cmpb $0x0, 0xc(%rsp)
je 0x3756
jmp 0x3a4c
leaq 0x3a56(%rip), %rdi      # 0x748b
xorl %eax, %eax
callq 0x249f
movl $0xffffffff, 0x77da(%rip) # imm = 0xFFFFFFFF
movl $0x4, %r15d
movq %r14, 0x28(%rsp)
testl %r15d, %r15d
je 0x362f
cmpl $0x3, %r15d
je 0x362f
cmpl $0x4, %r15d
jne 0x3a8e
movl 0x24(%rsp), %edi
callq 0x21c0
movq (%rsp), %rdi
callq 0x2050
movl 0x3c(%rsp), %eax
movl %eax, 0x779e(%rip)      # 0xb224
movl 0x7794(%rip), %eax      # 0xb220
jmp 0x3a8e
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq