// File: mlugo2[P]SunshineGPU/src/main.cpp
// Function: main
int main(int argc, char const *argv[])
{

	// Check for arguments
	if ( argc < 4 )
	{
		std::cout << "Usage: program [obj file] [vertex shader] [constants]\n";
		return 1;
	}

	// For vertex and face data
	std::vector<std::vector<float> > v;
	std::vector<std::vector<int> > f;

	// Vertex shader binary
	std::vector<unsigned long long int > vs;

	// Constant matrix data
	std::vector<float> c;

	// frame buffer
	u8 FB[SCREEN_HEIGHT][SCREEN_WIDTH][3] = {{{0}}};

	// Get all the vertex and face data
	object_file_interface(argv[1], &v, &f);

	// Read vertex shader binary into vector
	vertex_shader_interface(argv[2], &vs);

	// Read constant matrix data
	constant_file_interface(argv[3], &c);

	// Initialize the screen
	std::thread t1 {thread_screen, FB};

	// Instanciate gpu and load things..
	gpu *myGPU = new gpu();
	myGPU->load_const_mem(c);
	myGPU->load_microcode(vs);

	// GPU execution begins here
	// Run the GPU for the number of faces available
	int i = 0;
	while (f.size() != i)
	{
		myGPU->load_vab(v, f[i]); i++;
		myGPU->execute(FB);
	}

	t1.join();

	return 0;
}

// Assembly:
subq $0x1771c8, %rsp         # imm = 0x1771C8
movl $0x0, 0x1771c4(%rsp)
movl %edi, 0x1771c0(%rsp)
movq %rsi, 0x1771b8(%rsp)
cmpl $0x4, 0x1771c0(%rsp)
jge 0x4bbe
movq 0x1741e(%rip), %rdi     # 0x1bfc0
leaq 0x1058e(%rip), %rsi     # 0x15137
callq 0x3300
movl $0x1, 0x1771c4(%rsp)
jmp 0x514a
leaq 0x1771a0(%rsp), %rdi
callq 0x5910
leaq 0x177188(%rsp), %rdi
callq 0x5920
leaq 0x177170(%rsp), %rdi
callq 0x5930
leaq 0x177158(%rsp), %rdi
callq 0x5480
leaq 0x150(%rsp), %rdi
xorl %esi, %esi
movl $0x177000, %edx         # imm = 0x177000
callq 0x3180
movq 0x1771b8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x12f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x34a0
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x130(%rsp), %rdi
callq 0x53c0
jmp 0x4c42
leaq 0x130(%rsp), %rdi
leaq 0x1771a0(%rsp), %rsi
leaq 0x177188(%rsp), %rdx
callq 0x37a0
jmp 0x4c61
leaq 0x130(%rsp), %rdi
callq 0x31e0
leaq 0x12f(%rsp), %rdi
callq 0x3360
movq 0x1771b8(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x30(%rsp)
leaq 0xf7(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x34a0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xf8(%rsp), %rdi
callq 0x53c0
jmp 0x4cb7
leaq 0xf8(%rsp), %rdi
leaq 0x177170(%rsp), %rsi
callq 0x4230
jmp 0x4cce
leaq 0xf8(%rsp), %rdi
callq 0x31e0
leaq 0xf7(%rsp), %rdi
callq 0x3360
movq 0x1771b8(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
leaq 0xcf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x34a0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0x53c0
jmp 0x4d24
leaq 0xd0(%rsp), %rdi
leaq 0x177158(%rsp), %rsi
callq 0x4490
jmp 0x4d3b
leaq 0xd0(%rsp), %rdi
callq 0x31e0
leaq 0xcf(%rsp), %rdi
callq 0x3360
leaq -0x38c(%rip), %rsi      # 0x49d0
leaq 0xc0(%rsp), %rdi
leaq 0x150(%rsp), %rdx
callq 0x5940
jmp 0x4d73
movl $0x7dfc0, %edi          # imm = 0x7DFC0
callq 0x3310
movq %rax, 0x18(%rsp)
jmp 0x4d84
movq 0x18(%rsp), %rdi
callq 0xcb80
jmp 0x4d90
movq 0x18(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x177158(%rsp), %rsi
callq 0x5a10
jmp 0x4dc1
movq 0x10(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xcf60
jmp 0x4dd5
leaq 0xa0(%rsp), %rdi
callq 0x5790
movq 0xb8(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x177170(%rsp), %rsi
callq 0x5b10
jmp 0x4e06
movq 0x8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xd0c0
jmp 0x4e1a
leaq 0x88(%rsp), %rdi
callq 0x5c10
movl $0x0, 0x84(%rsp)
leaq 0x177188(%rsp), %rdi
callq 0x5c70
movslq 0x84(%rsp), %rcx
cmpq %rcx, %rax
je 0x50aa
movq 0xb8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x1771a0(%rsp), %rsi
callq 0x5c90
jmp 0x4e70
movslq 0x84(%rsp), %rsi
leaq 0x177188(%rsp), %rdi
callq 0x5d90
movq %rax, %rsi
leaq 0x50(%rsp), %rdi
callq 0x5db0
jmp 0x4e94
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0xd160
jmp 0x4ea9
leaq 0x50(%rsp), %rdi
callq 0x5730
leaq 0x68(%rsp), %rdi
callq 0x5eb0
movl 0x84(%rsp), %eax
incl %eax
movl %eax, 0x84(%rsp)
movq 0xb8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0xcd10
jmp 0x4ee4
jmp 0x4e32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x4f20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x31e0
leaq 0x12f(%rsp), %rdi
callq 0x3360
jmp 0x5114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x4f69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x31e0
leaq 0xf7(%rsp), %rdi
callq 0x3360
jmp 0x5114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x4fb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x31e0
leaq 0xcf(%rsp), %rdi
callq 0x3360
jmp 0x5114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x5114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x5107
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
movl $0x7dfc0, %esi          # imm = 0x7DFC0
callq 0x3320
jmp 0x5107
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5790
jmp 0x5107
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x5c10
jmp 0x5107
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x509e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x5730
leaq 0x68(%rsp), %rdi
callq 0x5eb0
jmp 0x5107
leaq 0xc0(%rsp), %rdi
callq 0x3460
jmp 0x50b9
movl $0x0, 0x1771c4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x5f10
leaq 0x177158(%rsp), %rdi
callq 0x5790
leaq 0x177170(%rsp), %rdi
callq 0x5c10
leaq 0x177188(%rsp), %rdi
callq 0x5f30
leaq 0x1771a0(%rsp), %rdi
callq 0x5eb0
jmp 0x514a
leaq 0xc0(%rsp), %rdi
callq 0x5f10
leaq 0x177158(%rsp), %rdi
callq 0x5790
leaq 0x177170(%rsp), %rdi
callq 0x5c10
leaq 0x177188(%rsp), %rdi
callq 0x5f30
leaq 0x1771a0(%rsp), %rdi
callq 0x5eb0
jmp 0x5159
movl 0x1771c4(%rsp), %eax
addq $0x1771c8, %rsp         # imm = 0x1771C8
retq
movq 0x120(%rsp), %rdi
callq 0x3490
nopw %cs:(%rax,%rax)