// File: /workspace/github_c_makefile_star2_O1/ebiggers[P]mysh/mysh_main.c
// Function: main
int main(int argc, char **argv)
{
	int c;
	int in_fd;
	bool from_stdin = false;
	bool interactive = false;

	remove_sigint_handler();
	init_param_map();

#ifdef WITH_READLINE
	/* getc() will return EOF on interrupt, instead of retrying like the
	 * default rl_getc().  This makes readline() return when an interrupt
	 * occurs, which allows the shell to handle SIGINT better.  Similarly,
	 * rl_catch_signals is set to 0 to prevent readline from catching the
	 * SIGINT signal before the shell does.  This is not the only solution:
	 * another would be to have readline handle SIGINT, then pass it onto
	 * the shell, which then does a longjmp() back to the main loop.  I
	 * didn't do it this way because using longjmp() correctly is very
	 * tricky. */
	rl_getc_function = mysh_getc;
	rl_catch_signals = 0;
#endif

	while ((c = getopt(argc, argv, "c:is")) != -1) {
		switch (c) {
		case 'c':
			/* execute string provided on the command line */
			set_positional_params(argc - optind, argv[optind - 1],
					      (const char * const *)&argv[optind]);
			execute_full_shell_input(optarg, strlen(optarg));
			goto out;
		case 's':
			/* read from stdin */
			from_stdin = true;
			break;
		case 'i':
			interactive = true;
			break;
		default:
			mysh_error("invalid option");
			mysh_last_exit_status = 2;
			goto out;
		}
	}
	argc -= optind;
	argv += optind;

	source_myshrc();
	(void)set_pwd();

	if (argc && !from_stdin) {
		in_fd = open(argv[0], O_RDONLY);
		if (in_fd < 0) {
			mysh_error_with_errno("can't open %s", argv[0]);
			mysh_last_exit_status = -1;
			goto out;
		}
		set_positional_params(argc - 1, argv[0], (const char * const *)(argv + 1));
	} else {
		set_positional_params(argc, argv[-1], (const char * const *)argv);
		in_fd = STDIN_FILENO;
	}
	if (isatty(in_fd))
		interactive = true;

	read_loop(in_fd, interactive);
out:
	destroy_positional_params();
	destroy_param_map();
	return mysh_last_exit_status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %r14
movl %edi, %ebx
movq %rsp, %r15
xorl %r13d, %r13d
movl $0x98, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2180
movq $0x1, (%r15)
leaq 0x8(%rsp), %rdi
movl $0x2, %esi
callq 0x23a0
movl $0x2, %edi
movq %r15, %rsi
xorl %edx, %edx
callq 0x20a0
xorl %eax, %eax
callq 0x4c72
leaq 0x159(%rip), %rax       # 0x3cf2
movq 0x7410(%rip), %rcx      # 0xafb0
movq %rax, (%rcx)
movq 0x7436(%rip), %rax      # 0xafe0
movl $0x0, (%rax)
leaq 0x38f6(%rip), %r15      # 0x74ad
xorl %r12d, %r12d
movl %r12d, %ecx
movl %ecx, %r12d
movl %ebx, %edi
movq %r14, %rsi
movq %r15, %rdx
callq 0x22d0
movb $0x1, %cl
cmpl $0x69, %eax
je 0x3bbd
cmpl $-0x1, %eax
je 0x3c25
cmpl $0x73, %eax
jne 0x3be3
movb $0x1, %r13b
jmp 0x3bba
cmpl $0x63, %eax
jne 0x3c54
movq 0x73b9(%rip), %rax      # 0xafa8
movslq (%rax), %rax
subl %eax, %ebx
leaq (%r14,%rax,8), %rdx
movq -0x8(%rdx), %rsi
movl %ebx, %edi
callq 0x53c0
movq 0x73b6(%rip), %rax      # 0xafc0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x2100
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3470
jmp 0x3caf
movq 0x737c(%rip), %rax      # 0xafa8
movslq (%rax), %r15
callq 0x48a2
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x288a
subl %r15d, %ebx
leaq (%r14,%r15,8), %r14
sete %al
orb %r13b, %al
testb $0x1, %al
je 0x3c6e
movq -0x8(%r14), %rsi
jmp 0x3c89
leaq 0x3857(%rip), %rdi      # 0x74b2
xorl %eax, %eax
callq 0x23e0
movl $0x2, 0x75b4(%rip)      # 0xb220
jmp 0x3caf
movq (%r14), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22c0
testl %eax, %eax
js 0x3cd5
movl %eax, %ebp
decl %ebx
movq (%r14), %rsi
addq $0x8, %r14
movl %ebx, %edi
movq %r14, %rdx
callq 0x53c0
movl %ebp, %edi
callq 0x2090
testl %eax, %eax
setne %al
orb %r12b, %al
movzbl %al, %esi
andl $0x1, %esi
movl %ebp, %edi
callq 0x35ca
xorl %eax, %eax
callq 0x5437
xorl %eax, %eax
callq 0x4d18
movl 0x755d(%rip), %eax      # 0xb220
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rsi
leaq 0x37c0(%rip), %rdi      # 0x749f
xorl %eax, %eax
callq 0x249f
movl $0xffffffff, 0x7530(%rip) # imm = 0xFFFFFFFF
jmp 0x3caf