// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x177158, %rsp         # imm = 0x177158
cmpl $0x3, %edi
jg 0x385c
movq 0x8797(%rip), %rdi      # 0xbfd8
leaq 0x58ef(%rip), %rsi      # 0x9137
movl $0x36, %edx
callq 0x22a0
movl $0x1, %eax
jmp 0x3b33
movq %rsi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
xorl %eax, %eax
movq %rax, 0x80(%rsp)
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0x150(%rsp), %rdi
movl $0x177000, %edx         # imm = 0x177000
xorl %esi, %esi
callq 0x2150
movq 0x8(%rbx), %rsi
leaq 0x118(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3cde
leaq 0x118(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x26c1
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38f1
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2270
movq 0x10(%rbx), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3cde
leaq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2ff8
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x393a
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2270
movq 0x18(%rbx), %rsi
leaq 0xd8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3cde
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3263
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3983
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2270
leaq -0x2b3(%rip), %rsi      # 0x36d7
leaq 0x8(%rsp), %rdi
leaq 0x150(%rsp), %rdx
callq 0x3dd2
movl $0x7dfc0, %edi          # imm = 0x7DFC0
callq 0x2260
movq %rax, %r14
movq %rax, %rdi
callq 0x4f30
leaq 0xa8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e4e
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0x5080
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x39f0
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3ece
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
callq 0x50ee
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3a2f
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
movq $-0x1, %rbp
xorl %r15d, %r15d
leaq 0x138(%rsp), %rbx
leaq 0xc0(%rsp), %r12
leaq 0x150(%rsp), %r13
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
incq %rbp
cmpq %rax, %rbp
je 0x3ad9
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3f4e
movq 0x50(%rsp), %rsi
addq %r15, %rsi
movq %r12, %rdi
callq 0x3fe8
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x5116
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3abd
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
addq $0x18, %r15
movq %rbx, %rdi
callq 0x4068
movq %r14, %rdi
movq %r13, %rsi
callq 0x4f34
jmp 0x3a51
leaq 0x8(%rsp), %rdi
callq 0x2370
cmpq $0x0, 0x8(%rsp)
jne 0x3c9a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3b06
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3b1d
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x50(%rsp), %rdi
callq 0x40bc
leaq 0x70(%rsp), %rdi
callq 0x4068
xorl %eax, %eax
addq $0x177158, %rsp         # imm = 0x177158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c45
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3c48
movq 0xa0(%rsp), %rsi
jmp 0x3b84
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3c48
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
jmp 0x3b94
movq %rax, %rbx
movl $0x7dfc0, %esi          # imm = 0x7DFC0
movq %r14, %rdi
callq 0x2270
jmp 0x3c48
jmp 0x3c0a
movq %rax, %rbx
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c50
movq 0xe8(%rsp), %rsi
jmp 0x3c00
jmp 0x3c0a
movq %rax, %rbx
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c50
movq 0x108(%rsp), %rsi
jmp 0x3c00
jmp 0x3c0a
movq %rax, %rbx
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c50
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2270
jmp 0x3c50
movq %rax, %rbx
jmp 0x3c50
jmp 0x3c45
movq %rax, %rbx
jmp 0x3c36
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3c36
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x138(%rsp), %rdi
callq 0x4068
jmp 0x3c48
movq %rax, %rbx
cmpq $0x0, 0x8(%rsp)
jne 0x3c9a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3c67
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3c7e
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x50(%rsp), %rdi
callq 0x40bc
leaq 0x70(%rsp), %rdi
callq 0x4068
movq %rbx, %rdi
callq 0x2390
callq 0x20d0
nop