// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x8(%rsp), %r15
xorl %r13d, %r13d
movl $0x90, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x2180
movq $0x1, -0x8(%r15)
movq %r15, %rdi
movl $0x2, %esi
callq 0x23a0
movq %rsp, %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x20a0
xorl %eax, %eax
callq 0x4b71
leaq 0x159(%rip), %rax       # 0x3c48
movq 0x74ba(%rip), %rcx      # 0xafb0
movq %rax, (%rcx)
movq 0x74e0(%rip), %rax      # 0xafe0
movl $0x0, (%rax)
leaq 0x39a0(%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 0x3b13
cmpl $-0x1, %eax
je 0x3b7b
cmpl $0x73, %eax
jne 0x3b39
movb $0x1, %r13b
jmp 0x3b10
cmpl $0x63, %eax
jne 0x3baa
movq 0x7463(%rip), %rax      # 0xafa8
movslq (%rax), %rax
subl %eax, %ebx
leaq (%r14,%rax,8), %rdx
movq -0x8(%rdx), %rsi
movl %ebx, %edi
callq 0x52d7
movq 0x7460(%rip), %rax      # 0xafc0
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x2100
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3468
jmp 0x3c05
movq 0x7426(%rip), %rax      # 0xafa8
movslq (%rax), %r15
callq 0x47a8
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x288d
subl %r15d, %ebx
leaq (%r14,%r15,8), %r14
sete %al
orb %r13b, %al
testb $0x1, %al
je 0x3bc4
movq -0x8(%r14), %rsi
jmp 0x3bdf
leaq 0x3901(%rip), %rdi      # 0x74b2
xorl %eax, %eax
callq 0x23e0
movl $0x2, 0x765e(%rip)      # 0xb220
jmp 0x3c05
movq (%r14), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x22c0
testl %eax, %eax
js 0x3c2b
movl %eax, %ebp
decl %ebx
movq (%r14), %rsi
addq $0x8, %r14
movl %ebx, %edi
movq %r14, %rdx
callq 0x52d7
movl %ebp, %edi
callq 0x2090
testl %eax, %eax
setne %al
orb %r12b, %al
movzbl %al, %esi
andl $0x1, %esi
movl %ebp, %edi
callq 0x3595
xorl %eax, %eax
callq 0x534e
xorl %eax, %eax
callq 0x4c17
movl 0x7607(%rip), %eax      # 0xb220
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rsi
leaq 0x386a(%rip), %rdi      # 0x749f
xorl %eax, %eax
callq 0x249f
movl $0xffffffff, 0x75da(%rip) # imm = 0xFFFFFFFF
jmp 0x3c05