// File: negativeview[P]Software-Business-Sim/main.cpp
// Function: main
int main(int argc, char *argv[]) {
	int row, col;

	srand(time(NULL));
	masterState = new MasterState();

	masterState->addMessage("Congratulations!");
	masterState->addMessage("You are the proud CEO of a brand new company!");
	masterState->addMessage("You must make the best software (and the most money) using what you have been given.");

	// Advance time by 10 days just so something interesting might happen.
	masterState->advanceTime(10);

	int moneyLeft = masterState->getPlayerCompany()->getMoney();

	initscr();

	int currentDay = -1;
	while(true) {
		erase();
		getmaxyx(stdscr, row, col);

		// TODO: Fix this so that it goes to the far right.
		attron(A_STANDOUT);
		mvprintw(0, 0, " Day: %d Money: %d", masterState->getTime(), moneyLeft);
		for (int i = 27; i < col; ++i) {
			printw(" ");
		}
		attroff(A_STANDOUT);

		vector<char *> *messages = masterState->getMessages();
		for (int i = 0; i < messages->size(); ++i) {
			int thisRow = row - messages->size() - 2 + i;
			mvprintw(thisRow, 1, (*messages)[i]);
		}

		// Three blank spaces between options.

		move(2, col - 20);
		attron(A_STANDOUT);
		printw("      COMMANDS      ");
		attroff(A_STANDOUT);

		move(3, col - 20);
		attron(A_STANDOUT);
		printw(" A ");
		attroff(A_STANDOUT);

		char message[20];

		printw(" Applicants");
		sprintf(message, "[%d]", masterState->getPlayerCompany()->getKnownPeople()->size());
		move(3, col - strlen(message));
		printw(message);

		move(4, col - 20);
		attron(A_STANDOUT);
		printw(" I ");
		attroff(A_STANDOUT);
		printw(" Interview");

		move(5, col - 20);
		attron(A_STANDOUT);
		printw(" H ");
		attroff(A_STANDOUT);
		printw(" Hire");

		move(6, col - 20);
		attron(A_STANDOUT);
		printw(" E ");
		attroff(A_STANDOUT);
		printw(" *Employees");

		sprintf(message, "[%d]", masterState->getPlayerCompany()->getEmployees()->size());
		move(6, col - strlen(message));
		printw(message);

		move(7, col - 20);
		attron(A_STANDOUT);
		printw(" S ");
		attroff(A_STANDOUT);
		printw(" Status");

		move(8, col - 20);
		attron(A_STANDOUT);
		printw(" T ");
		attroff(A_STANDOUT);
		printw(" *Teams");

		move(9, col - 20);
		attron(A_STANDOUT);
		printw(" P ");
		attroff(A_STANDOUT);
		printw(" *Projects");
		sprintf(message, "[%d]", masterState->getPlayerCompany()->getProjects()->size());
		move(9, col - strlen(message));
		printw(message);

		move(10, col - 20);
		attron(A_STANDOUT);
		printw(" W ");
		attroff(A_STANDOUT);
		printw(" *Wait");

		move(11, col - 20);
		attron(A_STANDOUT);
		printw(" Q ");
		attroff(A_STANDOUT);
		printw(" Quit");

		refresh();
		curs_set(0);
		noecho();
		int input = getch();

		if (masterState->getTime() != currentDay) {
			masterState->clearMessages();
			currentDay = masterState->getTime();
		}
		switch(input) {
			case 'a':
				masterState->clearMessages();
				masterState->executeCommand("applicants");
				break;
			case 'e':
				masterState->clearMessages();
				masterState->executeCommand("employees");
				break;
			case 'h':
				masterState->executeCommand("hire");
				break;
			case 'i':
				masterState->executeCommand("interview");
				break;
			case 'p':
				masterState->executeCommand("project");
				break;
			case 's':
				masterState->clearMessages();
				masterState->executeCommand("status");
				break;
			case 'q':
				endwin();
				return 0;
			default:
				break;
		}
	}
	endwin();
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x3330
movl %eax, %edi
callq 0x3360
movl $0x60, %edi
callq 0x3370
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0x11770
jmp 0x37c4
movq -0x70(%rbp), %rax
movq %rax, 0x20b71(%rip)     # 0x24340
movq 0x20b6a(%rip), %rdi     # 0x24340
leaq 0x14873(%rip), %rsi     # 0x18050
callq 0x12d60
movq 0x20b57(%rip), %rdi     # 0x24340
leaq 0x14871(%rip), %rsi     # 0x18061
callq 0x12d60
movq 0x20b44(%rip), %rdi     # 0x24340
leaq 0x1488c(%rip), %rsi     # 0x1808f
callq 0x12d60
movq 0x20b31(%rip), %rdi     # 0x24340
movl $0xa, %esi
callq 0x12e40
movq 0x20b20(%rip), %rdi     # 0x24340
callq 0x12e20
movq %rax, %rdi
callq 0xc270
movl %eax, -0x28(%rbp)
callq 0x3540
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
callq 0x33f0
xorl %eax, %eax
movq 0x20786(%rip), %rcx     # 0x23fd0
cmpq (%rcx), %rax
je 0x3865
movq 0x2077a(%rip), %rax     # 0x23fd0
movq (%rax), %rax
movswl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x386f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x74(%rbp)
jmp 0x386f
movl -0x74(%rbp), %eax
movl %eax, -0x14(%rbp)
xorl %eax, %eax
movq 0x20752(%rip), %rcx     # 0x23fd0
cmpq (%rcx), %rax
je 0x3899
movq 0x20746(%rip), %rax     # 0x23fd0
movq (%rax), %rax
movswl 0x6(%rax), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x38a3
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x78(%rbp)
jmp 0x38a3
movl -0x78(%rbp), %eax
movl %eax, -0x18(%rbp)
movq 0x20720(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
movq 0x20a78(%rip), %rdi     # 0x24340
callq 0x12dc0
movl %eax, %ecx
movl -0x28(%rbp), %r8d
xorl %esi, %esi
leaq 0x14808(%rip), %rdx     # 0x180e4
movl %esi, %edi
movb $0x0, %al
callq 0x34c0
movl $0x1b, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x392c
leaq 0x1480f(%rip), %rdi     # 0x1810a
movb $0x0, %al
callq 0x3380
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x38ec
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x60, %esi
callq 0x3390
jmp 0x4009
movq 0x2069d(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
movq 0x209f5(%rip), %rdi     # 0x24340
callq 0x12cc0
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4020
movq %rax, %rcx
movq -0x80(%rbp), %rax
cmpq %rcx, %rax
jae 0x39e0
movslq -0x14(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rdi
callq 0x4020
movq %rax, %rcx
movq -0x90(%rbp), %rax
subq %rcx, %rax
subq $0x2, %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x4040
movl -0x84(%rbp), %edi
movq (%rax), %rdx
movl $0x1, %esi
movb $0x0, %al
callq 0x34c0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x395b
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x2, %edi
callq 0x3260
movq 0x205d9(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x146e8(%rip), %rdi     # 0x180f7
movb $0x0, %al
callq 0x3380
movq 0x205b3(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x3, %edi
callq 0x3260
movq 0x2058b(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x146af(%rip), %rdi     # 0x1810c
movb $0x0, %al
callq 0x3380
movq 0x20565(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x1468d(%rip), %rdi     # 0x18110
movb $0x0, %al
callq 0x3380
leaq -0x60(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x208a4(%rip), %rdi     # 0x24340
callq 0x12e20
movq %rax, %rdi
callq 0xbfd0
movq %rax, %rdi
callq 0x4060
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
leaq 0x1465a(%rip), %rsi     # 0x1811c
movb $0x0, %al
callq 0x30a0
movslq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
subq %rcx, %rax
movl %eax, %esi
movl $0x3, %edi
callq 0x3260
leaq -0x60(%rbp), %rdi
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x4, %edi
callq 0x3260
movq 0x204b8(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x145f1(%rip), %rdi     # 0x18121
movb $0x0, %al
callq 0x3380
movq 0x20492(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x145cf(%rip), %rdi     # 0x18125
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x5, %edi
callq 0x3260
movq 0x2045c(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x145a4(%rip), %rdi     # 0x18130
movb $0x0, %al
callq 0x3380
movq 0x20436(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x14582(%rip), %rdi     # 0x18134
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x6, %edi
callq 0x3260
movq 0x20400(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x14552(%rip), %rdi     # 0x1813a
movb $0x0, %al
callq 0x3380
movq 0x203da(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x14530(%rip), %rdi     # 0x1813e
movb $0x0, %al
callq 0x3380
leaq -0x60(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq 0x20719(%rip), %rdi     # 0x24340
callq 0x12e20
movq %rax, %rdi
callq 0xc250
movq %rax, %rdi
callq 0x4060
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0x144cf(%rip), %rsi     # 0x1811c
movb $0x0, %al
callq 0x30a0
movslq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
subq %rcx, %rax
movl %eax, %esi
movl $0x6, %edi
callq 0x3260
leaq -0x60(%rbp), %rdi
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x7, %edi
callq 0x3260
movq 0x2032d(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x1448f(%rip), %rdi     # 0x1814a
movb $0x0, %al
callq 0x3380
movq 0x20307(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x1446d(%rip), %rdi     # 0x1814e
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x8, %edi
callq 0x3260
movq 0x202d1(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x1443f(%rip), %rdi     # 0x18156
movb $0x0, %al
callq 0x3380
movq 0x202ab(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x1441d(%rip), %rdi     # 0x1815a
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0x9, %edi
callq 0x3260
movq 0x20275(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x143ef(%rip), %rdi     # 0x18162
movb $0x0, %al
callq 0x3380
movq 0x2024f(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x143cd(%rip), %rdi     # 0x18166
movb $0x0, %al
callq 0x3380
leaq -0x60(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x2058e(%rip), %rdi     # 0x24340
callq 0x12e20
movq %rax, %rdi
callq 0xb620
movq %rax, %rdi
callq 0x4080
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
leaq 0x14344(%rip), %rsi     # 0x1811c
movb $0x0, %al
callq 0x30a0
movslq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x98(%rbp), %rax
subq %rcx, %rax
movl %eax, %esi
movl $0x9, %edi
callq 0x3260
leaq -0x60(%rbp), %rdi
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0xa, %edi
callq 0x3260
movq 0x201a2(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x1432b(%rip), %rdi     # 0x18171
movb $0x0, %al
callq 0x3380
movq 0x2017c(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x14309(%rip), %rdi     # 0x18175
movb $0x0, %al
callq 0x3380
movl -0x18(%rbp), %esi
subl $0x14, %esi
movl $0xb, %edi
callq 0x3260
movq 0x20146(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x31c0
leaq 0x142da(%rip), %rdi     # 0x1817c
movb $0x0, %al
callq 0x3380
movq 0x20120(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
movl $0x10000, %esi          # imm = 0x10000
xorl %eax, %eax
movl %eax, %edx
callq 0x34b0
leaq 0x142b8(%rip), %rdi     # 0x18180
movb $0x0, %al
callq 0x3380
callq 0x35b0
xorl %edi, %edi
callq 0x32f0
callq 0x3440
movq 0x200e9(%rip), %rax     # 0x23fd0
movq (%rax), %rdi
callq 0x3130
movl %eax, -0x64(%rbp)
movq 0x20447(%rip), %rdi     # 0x24340
callq 0x12dc0
cmpl -0x2c(%rbp), %eax
je 0x3f1e
movq 0x20436(%rip), %rdi     # 0x24340
callq 0x12ce0
movq 0x2042a(%rip), %rdi     # 0x24340
callq 0x12dc0
movl %eax, -0x2c(%rbp)
movl -0x64(%rbp), %eax
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0xc8(%rbp)
subl $0x12, %eax
ja 0x4002
movq -0xc8(%rbp), %rax
leaq 0x140c0(%rip), %rcx     # 0x18004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x203ec(%rip), %rdi     # 0x24340
callq 0x12ce0
movq 0x203e0(%rip), %rdi     # 0x24340
leaq 0x1421f(%rip), %rsi     # 0x18186
callq 0x13490
jmp 0x4004
movq 0x203c8(%rip), %rdi     # 0x24340
callq 0x12ce0
movq 0x203bc(%rip), %rdi     # 0x24340
leaq 0x146f3(%rip), %rsi     # 0x1867e
callq 0x13490
jmp 0x4004
movq 0x203a7(%rip), %rdi     # 0x24340
leaq 0x141f1(%rip), %rsi     # 0x18191
callq 0x13490
jmp 0x4004
movq 0x20392(%rip), %rdi     # 0x24340
leaq 0x141e1(%rip), %rsi     # 0x18196
callq 0x13490
jmp 0x4004
movq 0x2037d(%rip), %rdi     # 0x24340
leaq 0x141d6(%rip), %rsi     # 0x181a0
callq 0x13490
jmp 0x4004
movq 0x20368(%rip), %rdi     # 0x24340
callq 0x12ce0
movq 0x2035c(%rip), %rdi     # 0x24340
leaq 0x141bd(%rip), %rsi     # 0x181a8
callq 0x13490
jmp 0x4004
callq 0x3450
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbp
retq
jmp 0x4004
jmp 0x383c
movq -0x20(%rbp), %rdi
callq 0x35d0
nopw %cs:(%rax,%rax)
nopl (%rax)