// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movb %sil, %al
movl %edi, -0x4(%rbp)
andb $0x1, %al
movb %al, -0x5(%rbp)
movl 0xa8a8(%rip), %eax      # 0xe624
movl %eax, -0x44(%rbp)
movb -0x5(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0xa895(%rip)      # 0xe624
movq $0x1000, -0x28(%rbp)    # imm = 0x1000
movq -0x28(%rbp), %rdi
callq 0x8e00
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x40e0
callq 0x54d0
testb $0x1, -0x5(%rbp)
je 0x3ee6
callq 0x5620
leaq -0x40(%rbp), %rdi
callq 0x4110
movq %rax, %rdi
callq 0x21b0
movq %rax, -0x68(%rbp)
callq 0x5990
testb $0x1, 0xa836(%rip)      # 0xe628
je 0x3e2b
movb $0x0, 0xa82d(%rip)      # 0xe628
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33b0
leaq 0x678d(%rip), %rdi      # 0xa5a8
callq 0x2080
movq -0x68(%rbp), %rdi
callq 0x2050
jmp 0x3dbd
cmpq $0x0, -0x68(%rbp)
jne 0x3e37
jmp 0x40b4
movq -0x68(%rbp), %rax
cmpb $0x0, (%rax)
je 0x3e49
movq -0x68(%rbp), %rdi
callq 0x20c0
movq -0x68(%rbp), %rdi
callq 0x2100
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
subq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x3eaf
movq -0x28(%rbp), %rax
shlq %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
subq -0x20(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x3e9e
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
subq -0x20(%rbp), %rcx
subq %rcx, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x8e50
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
addq -0x20(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x2260
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
addq -0x50(%rbp), %rcx
subq $0x1, %rcx
movb $0xa, (%rax,%rcx)
movq -0x68(%rbp), %rdi
callq 0x2050
jmp 0x3fab
jmp 0x3ee8
movq -0x28(%rbp), %rax
subq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shrq %rcx
cmpq %rcx, %rax
jae 0x3f85
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jbe 0x3f55
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x22a0
movq $0x0, -0x18(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x3f83
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x3f81
testb $0x1, -0x5(%rbp)
jne 0x3f81
movq -0x28(%rbp), %rax
shlq %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x8e50
movq %rax, -0x10(%rbp)
jmp 0x3f83
jmp 0x3f85
jmp 0x3f87
movq -0x28(%rbp), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
addq -0x20(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x2210
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x3fdd
movq -0x20(%rbp), %rax
subq -0x18(%rbp), %rax
cmpq $0x0, %rax
je 0x3fd8
leaq 0x65c9(%rip), %rdi      # 0xa590
movb $0x0, %al
callq 0x8c20
movl $0xffffffff, 0xa648(%rip) # imm = 0xFFFFFFFF
jmp 0x40b4
cmpq $0x0, -0x50(%rbp)
jge 0x400d
callq 0x2060
cmpl $0x4, (%rax)
jne 0x3ff0
jmp 0x3f87
leaq 0x65b4(%rip), %rdi      # 0xa5ab
movb $0x0, %al
callq 0x8cf0
movl $0xffffffff, 0xa618(%rip) # imm = 0xFFFFFFFF
jmp 0x40b4
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rax
addq %rax, %rsi
leaq -0x40(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x3c60
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0xfffff830, %eax       # imm = 0xFFFFF830
je 0x407c
jmp 0x4064
movl -0x74(%rbp), %eax
subl $0xfffffc18, %eax       # imm = 0xFFFFFC18
jne 0x408c
jmp 0x4070
movl $0xffffffff, 0xa5a6(%rip) # imm = 0xFFFFFFFF
jmp 0x40b4
testb $0x1, -0x5(%rbp)
je 0x4087
jmp 0x3dbd
jmp 0x3ee8
movl -0x2c(%rbp), %eax
movl %eax, 0xa58b(%rip)      # 0xe620
cmpl $0x0, 0xa584(%rip)      # 0xe620
je 0x40a9
cmpl $0x0, 0xa587(%rip)      # 0xe62c
je 0x40a9
jmp 0x40b4
jmp 0x40ab
jmp 0x40ad
jmp 0x40af
jmp 0x3dbd
movl -0x4(%rbp), %edi
callq 0x21c0
movq -0x10(%rbp), %rdi
callq 0x2050
movl -0x44(%rbp), %eax
movl %eax, 0xa556(%rip)      # 0xe624
movl 0xa54c(%rip), %eax      # 0xe620
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)