// File: /workspace/github_cpp_makefile_star2_O3/sykeben[P]overos/os/kernel.cpp
// Function: main
int main(int argc, char** argv) {
	// This is the "kernel" for overOS.
	// It really isn't a kernel, but whatever.
	
	// Prepare kernel enviroment.
	cout << "Kernel started, getting ready..." << _TERM;
	#ifdef _WIN32
		if (fexists(".\\os\\kautorun.exe")) system(".\\os\\kautorun");
	#else
		if (fexists("./os/kautorun")) system("./os/kautorun");
	#endif
	settitle("OverOS Shell");
	
	// Let the user know the kernel & shell are ready.
	clear_screen();
	cout << "[ OverOS " << _VMAJOR << '.' << _VMINOR << '.' << _VREVISION << " Shell ]" << _TERM;
	cout << "Run \"help\" for assistance." << _TERM;
	
	while (!_EXIT) {
		
		// Get user command input.
		if (_CLEARED) _CLEARED = false; else cout << _TERM;
		cout << "~> ";
		cin.getline(_INPUT, _MAXIN, _TERM);
		
		// Internal commands & externel executor.
		if (!strcmp(_INPUT, "help")) {
			// Help //
			cout << "Internal shell commands: help exitnow clr sysver listcmds" << _TERM;
			cout << "The prompt may also run executables from the \\cmd directory." << _TERM;
		} else if (!strcmp(_INPUT, "exitnow")) {
			// ExitNow //
			cout << "Exiting OverOS now..." << _TERM;
			_EXIT = true; _EXITCODE = 0;
		} else if (!strcmp(_INPUT, "clr")) {
			// Clr //
			clear_screen(); _CLEARED = true;
		} else if (!strcmp(_INPUT, "sysver")) {
			// SysVer //
			cout << "OverOS System Version " << _VMAJOR << '.' << _VMINOR << '.' << _VREVISION << _TERM;
		} else if (!strcmp(_INPUT, "listcmds")) {
			// ListCmds //
			cout << "Files in the \\cmd directory:" << _TERM;
			system(_LISTCMDS.c_str());
		} else {
			// Externel Executor //
			_INPUTSTR = _INPUT;
			#ifdef _WIN32
				_CMDF = ".\\cmd\\" + _INPUTSTR.substr(0, _INPUTSTR.find(' '));
				_CMDF += ".exe";
			#else
				_CMDF = "./cmd/" + _INPUTSTR.substr(0, _INPUTSTR.find(' '));
			#endif
			_CMDFWIN = _CMDF + ".exe";
			if (fexists(_CMDF) || fexists(_CMDFWIN)) {
				#ifdef _WIN32
					system((".\\cmd\\" + _INPUTSTR).c_str());
				#else
					system(("./cmd/" + _INPUTSTR).c_str());
				#endif
			} else {
				// Invalid Error //
				cout << "Error: Invalid command, " << _INPUT << "." << _TERM;
			}
		}
	}
	
	return _EXITCODE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x2af3(%rip), %rbx      # 0x4fd0
leaq 0xb46(%rip), %rsi       # 0x302a
movl $0x20, %edx
movq %rbx, %rdi
callq 0x20e0
leaq -0x48(%rbp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x20e0
leaq -0x38(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0xb37(%rip), %rsi       # 0x304b
leaq 0xb3d(%rip), %rdx       # 0x3058
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x2c5c
movq %r14, %rdi
callq 0x2493
movl %eax, %ebx
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x2545
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20b0
testb %bl, %bl
je 0x2555
leaq 0xafb(%rip), %rdi       # 0x304b
callq 0x2080
leaq -0x78(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xaf5(%rip), %rsi       # 0x3059
leaq 0xafa(%rip), %rdx       # 0x3065
leaq -0x88(%rbp), %rbx
movq %rbx, %rdi
callq 0x2c5c
movq %rbx, %rdi
callq 0x23fd
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x259a
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x20b0
leaq 0xa63(%rip), %rdi       # 0x3004
callq 0x2080
movq 0x2a23(%rip), %rbx      # 0x4fd0
leaq 0xab2(%rip), %rsi       # 0x3066
movl $0x9, %edx
movq %rbx, %rdi
callq 0x20e0
movl 0x2b3d(%rip), %esi      # 0x5104
movq %rbx, %rdi
callq 0x2150
movb $0x2e, %r15b
leaq -0x48(%rbp), %r14
movb %r15b, (%r14)
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x20e0
movl 0x2af1(%rip), %esi      # 0x50e0
movq %rax, %rdi
callq 0x2150
movb %r15b, (%r14)
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x20e0
movl 0x2ad4(%rip), %esi      # 0x50e4
movq %rax, %rdi
callq 0x2150
movq %rax, %r15
leaq 0xa4e(%rip), %rsi       # 0x3070
movl $0x8, %edx
movq %rax, %rdi
callq 0x20e0
movb $0xa, %r12b
movb %r12b, (%r14)
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x20e0
leaq 0xa2d(%rip), %rsi       # 0x3079
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x20e0
movb %r12b, (%r14)
movb $0xa, %r14b
leaq -0x48(%rbp), %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x20e0
cmpb $0x0, 0x2a91(%rip)      # 0x5108
jne 0x2ac9
movq 0x294c(%rip), %rbx      # 0x4fd0
movq 0x2955(%rip), %r15      # 0x4fe0
leaq 0x2a8e(%rip), %r12      # 0x5120
leaq -0x48(%rbp), %r13
cmpb $0x1, 0x2a73(%rip)      # 0x5110
jne 0x26a8
movb $0x0, 0x2a6a(%rip)      # 0x5110
jmp 0x26bc
movb $0xa, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x9c9(%rip), %rsi       # 0x3094
callq 0x20e0
movl $0xff, %edx
movq %r15, %rdi
movq %r12, %rsi
movl $0xa, %ecx
callq 0x2190
movl 0x2a35(%rip), %eax      # 0x5120
movl $0x706c6568, %ecx       # imm = 0x706C6568
xorl %ecx, %eax
movzbl 0x2a2b(%rip), %ecx      # 0x5124
orl %eax, %ecx
je 0x2755
movq 0x2a1c(%rip), %rax      # 0x5120
movabsq $0x776f6e74697865, %rcx # imm = 0x776F6E74697865
cmpq %rcx, %rax
jne 0x27aa
movl $0x15, %edx
movq %rbx, %rdi
leaq 0x9ee(%rip), %rsi       # 0x3114
callq 0x20e0
movb $0xa, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
movb $0x1, 0x29c2(%rip)      # 0x5108
movl $0x0, 0x29bc(%rip)      # 0x510c
jmp 0x2abc
movl $0x39, %edx
movq %rbx, %rdi
leaq 0x939(%rip), %rsi       # 0x309d
callq 0x20e0
movb %r14b, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
movl $0x3c, %edx
movq %rbx, %rdi
leaq 0x94b(%rip), %rsi       # 0x30d7
callq 0x20e0
movb %r14b, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
jmp 0x2abc
cmpl $0x726c63, %eax         # imm = 0x726C63
jne 0x27c9
leaq 0x84c(%rip), %rdi       # 0x3004
callq 0x2080
movb $0x1, 0x294c(%rip)      # 0x5110
jmp 0x2abc
movl 0x2951(%rip), %eax      # 0x5120
movl $0x76737973, %ecx       # imm = 0x76737973
xorl %ecx, %eax
movl 0x2947(%rip), %ecx      # 0x5123
movl $0x726576, %edx         # imm = 0x726576
xorl %edx, %ecx
orl %eax, %ecx
je 0x28a2
movq 0x292e(%rip), %rax      # 0x5120
movabsq $0x73646d637473696c, %rcx # imm = 0x73646D637473696C
xorq %rcx, %rax
movzbl 0x2922(%rip), %ecx      # 0x5128
orq %rax, %rcx
je 0x291f
movq %r15, %r13
movq 0x2a0f(%rip), %r14      # 0x5228
movq %r12, %rdi
callq 0x2050
leaq 0x29f8(%rip), %r15      # 0x5220
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x2130
movq %r15, %rdi
movl $0x20, %esi
xorl %edx, %edx
callq 0x2110
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x20c0
movl $0x6, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x8f3(%rip), %rcx       # 0x3165
callq 0x20d0
leaq -0x38(%rbp), %r14
movq %r14, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2958
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x295f
movl $0x16, %edx
movq %rbx, %rdi
leaq 0x880(%rip), %rsi       # 0x3131
callq 0x20e0
movl 0x2848(%rip), %esi      # 0x5104
movq %rbx, %rdi
callq 0x2150
movb $0x2e, %r14b
movb %r14b, -0x48(%rbp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x20e0
movl 0x27ff(%rip), %esi      # 0x50e0
movq %rax, %rdi
callq 0x2150
movb %r14b, -0x48(%rbp)
movb $0xa, %r14b
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x20e0
movl 0x27de(%rip), %esi      # 0x50e4
movq %rax, %rdi
callq 0x2150
movb $0xa, -0x48(%rbp)
movl $0x1, %edx
movq %rax, %rdi
jmp 0x279d
movl $0x1c, %edx
movq %rbx, %rdi
leaq 0x81a(%rip), %rsi       # 0x3148
callq 0x20e0
movb $0xa, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
movq 0x2952(%rip), %rdi      # 0x52a0
callq 0x2080
jmp 0x2abc
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r13, %r15
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x28c0(%rip), %rdi      # 0x5240
leaq -0x48(%rbp), %r13
movq %r13, %rsi
callq 0x2100
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
leaq 0x2786(%rip), %r12      # 0x5120
je 0x29a8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20b0
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x29c1
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x20b0
movq %r14, -0x48(%rbp)
movq 0x2874(%rip), %rsi      # 0x5240
movq 0x2875(%rip), %rdx      # 0x5248
addq %rsi, %rdx
movq %r13, %rdi
callq 0x2bbe
movq %r13, %rdi
leaq 0x784(%rip), %rsi       # 0x316c
callq 0x2180
leaq 0x286c(%rip), %rdi      # 0x5260
movq %r13, %rsi
callq 0x2100
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x2a11
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20b0
leaq 0x2828(%rip), %rdi      # 0x5240
callq 0x2493
testb %al, %al
jne 0x2a31
leaq 0x2838(%rip), %rdi      # 0x5260
callq 0x2493
testb %al, %al
je 0x2a67
movq %r13, %rdi
leaq 0x72a(%rip), %rsi       # 0x3165
leaq 0x27de(%rip), %rdx      # 0x5220
callq 0x2b2b
movq -0x48(%rbp), %rdi
callq 0x2080
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ab9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x20b0
jmp 0x2ab9
movl $0x18, %edx
movq %rbx, %rdi
leaq 0x6fb(%rip), %rsi       # 0x3171
callq 0x20e0
movq %r12, %rdi
callq 0x2050
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x20e0
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x688(%rip), %rsi       # 0x3128
callq 0x20e0
movb $0xa, -0x48(%rbp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x20e0
movb $0xa, %r14b
cmpb $0x1, 0x2645(%rip)      # 0x5108
jne 0x2696
movl 0x263d(%rip), %eax      # 0x510c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ae0
movq %rax, %rbx
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x2b23
movq -0x38(%rbp), %rsi
jmp 0x2b1b
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x2b23
movq -0x58(%rbp), %rsi
jmp 0x2b1b
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x2b23
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x20b0
movq %rbx, %rdi
callq 0x2160