// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/main.c
// Function: main
int main(int argc, char *argv[]) {

	error_clear();
	ferr = stdout; // ferr in Eclipse console not visible?

	tu58images_init();

	parse_commandline(argc, argv);
	// returns only if everything is OK
	// Std options already executed

	// some debug info
	if (opt_debug) {
		info(version);
		info(copyright);
	}

	// some warnings
	check_capabilities();

	// give some info
	info("Using serial port %s at %d baud with %d%c%d format.", opt_serial_port,
			opt_serial_speed, opt_serial_bitcount, opt_serial_parity, opt_serial_stopbits);

	if (drive_count == 0) {
		info("No simulated drives were specified, emulator not started.");
	} else {
		// emulation: must have opened at least one unit

		if (opt_mrspen)
			info("MRSP mode enabled (NOT fully tested - use with caution)");

		// setup serial and console ports
		serial_devinit(&tu58_serial, opt_serial_port, opt_serial_speed, opt_serial_bitcount,
				opt_serial_parity, opt_serial_stopbits);
		coninit(0); // normal without echo

		// start thread with tu58 emulator
		run_emulator();

		// restore serial and console ports
		conrestore();
		serial_devrestore(&tu58_serial);

		// write back unsaved files and close
		tu58images_closeall();
	}

	// boot loader?
	if (opt_boot_monitor == monitor_showcode) {
		bootloader_show_code(stdout, opt_boot_address);
	} else if (opt_boot_monitor != monitor_none) {
		int res;
		serial_device_t monitor_serial; // PDP-11 console
		serial_devinit(&monitor_serial, opt_serial_port, opt_serial_speed, opt_serial_bitcount,
				opt_serial_parity, opt_serial_stopbits);
		coninit(1); // host console, raw: no processing of PDP-11 I/O

		// download, and echo to console
		res = bootloader_download(&monitor_serial, opt_boot_monitor, opt_boot_address);
		if (!res)
			res = bootloader_go(&monitor_serial, opt_boot_monitor, opt_boot_address);
		// no error

		if (opt_boot_keep) {
			if (res) {
				run_teletype(&monitor_serial, opt_boot_monitor,
						"PDP-11 does not respond. Use this teletype session to verify console prompt.");
			} else
				// interactive tty terminal on PDP-11 monitor port
				run_teletype(&monitor_serial, opt_boot_monitor, NULL);
		}

		// restore serial and console ports
		conrestore();
		serial_devrestore(&monitor_serial);
	}
	return 0 ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0xcd60
movq 0x1f38b(%rip), %rax     # 0x22fd0
movq (%rax), %rcx
leaq 0x218e1(%rip), %rax     # 0x25530
movq %rcx, (%rax)
callq 0x79d0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3e50
cmpl $0x0, 0x2010a(%rip)     # 0x23d74
je 0x3c88
leaq 0x1f6ad(%rip), %rdi     # 0x23320
movb $0x0, %al
callq 0xcf60
leaq 0x1f6ff(%rip), %rdi     # 0x23380
movb $0x0, %al
callq 0xcf60
callq 0x5650
movl 0x200cd(%rip), %edx     # 0x23d60
movl 0x1f667(%rip), %ecx     # 0x23300
movsbl 0x1f663(%rip), %r8d     # 0x23304
movl 0x1f660(%rip), %r9d     # 0x23308
leaq 0x155af(%rip), %rdi     # 0x1925e
leaq 0x1ffaa(%rip), %rsi     # 0x23c60
movb $0x0, %al
callq 0xcf60
cmpl $0x0, 0x212a4(%rip)     # 0x24f68
jne 0x3cd6
leaq 0x155c5(%rip), %rdi     # 0x19292
movb $0x0, %al
callq 0xcf60
jmp 0x3d3f
cmpl $0x0, 0x2008f(%rip)     # 0x23d6c
je 0x3ced
leaq 0x155e6(%rip), %rdi     # 0x192cc
movb $0x0, %al
callq 0xcf60
movl 0x2006d(%rip), %edx     # 0x23d60
movl 0x1f607(%rip), %ecx     # 0x23300
movb 0x1f605(%rip), %al      # 0x23304
movl 0x1f602(%rip), %r9d     # 0x23308
leaq 0x214bb(%rip), %rdi     # 0x251c8
leaq 0x1ff4c(%rip), %rsi     # 0x23c60
movsbl %al, %r8d
callq 0xab70
xorl %edi, %edi
callq 0xaf60
callq 0x3920
callq 0xb050
leaq 0x21493(%rip), %rdi     # 0x251c8
callq 0xaf20
callq 0x7af0
cmpl $0x1, 0x20042(%rip)     # 0x23d88
jne 0x3d62
movq 0x1f281(%rip), %rax     # 0x22fd0
movq (%rax), %rdi
movl 0x1f5b8(%rip), %esi     # 0x23310
callq 0x180a0
jmp 0x3e3a
cmpl $0x0, 0x2001f(%rip)     # 0x23d88
je 0x3e38
movl 0x1ffeb(%rip), %edx     # 0x23d60
movl 0x1f585(%rip), %ecx     # 0x23300
movb 0x1f583(%rip), %al      # 0x23304
movl 0x1f580(%rip), %r9d     # 0x23308
leaq -0x290(%rbp), %rdi
leaq 0x1feca(%rip), %rsi     # 0x23c60
movsbl %al, %r8d
callq 0xab70
movl $0x1, %edi
callq 0xaf60
movl 0x1ffd9(%rip), %esi     # 0x23d88
movl 0x1f55b(%rip), %edx     # 0x23310
leaq -0x290(%rbp), %rdi
callq 0x18130
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x3de5
movl 0x1ffb8(%rip), %esi     # 0x23d88
movl 0x1f53a(%rip), %edx     # 0x23310
leaq -0x290(%rbp), %rdi
callq 0x18230
movl %eax, -0x14(%rbp)
cmpl $0x0, 0x1ffa0(%rip)     # 0x23d8c
je 0x3e27
cmpl $0x0, -0x14(%rbp)
je 0x3e0f
movl 0x1ff8e(%rip), %esi     # 0x23d88
leaq -0x290(%rbp), %rdi
leaq 0x154fc(%rip), %rdx     # 0x19304
callq 0x182f0
jmp 0x3e25
movl 0x1ff73(%rip), %esi     # 0x23d88
leaq -0x290(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
callq 0x182f0
jmp 0x3e27
callq 0xb050
leaq -0x290(%rbp), %rdi
callq 0xaf20
jmp 0x3e3a
xorl %eax, %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
nopw %cs:(%rax,%rax)