// File: /workspace/github_cpp_makefile_star2_O1/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 0x386e
movq 0x8785(%rip), %rdi      # 0xbfd8
leaq 0x58dd(%rip), %rsi      # 0x9137
movl $0x36, %edx
callq 0x22a0
movl $0x1, %eax
jmp 0x3b45
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 0x3cf0
leaq 0x118(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x26a1
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3903
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2270
movq 0x10(%rbx), %rsi
leaq 0xf8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3cf0
leaq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2ff7
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x394c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2270
movq 0x18(%rbx), %rsi
leaq 0xd8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3cf0
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3262
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3995
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2270
leaq -0x2b3(%rip), %rsi      # 0x36e9
leaq 0x8(%rsp), %rdi
leaq 0x150(%rsp), %rdx
callq 0x3de2
movl $0x7dfc0, %edi          # imm = 0x7DFC0
callq 0x2260
movq %rax, %r14
movq %rax, %rdi
callq 0x4f84
leaq 0xa8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e70
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0x50ea
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3a02
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x3ef0
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
callq 0x5158
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3a41
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 0x3aeb
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3f70
movq 0x50(%rsp), %rsi
addq %r15, %rsi
movq %r12, %rdi
callq 0x400a
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x5180
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3acf
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
addq $0x18, %r15
movq %rbx, %rdi
callq 0x408a
movq %r14, %rdi
movq %r13, %rsi
callq 0x4f88
jmp 0x3a63
leaq 0x8(%rsp), %rdi
callq 0x2370
cmpq $0x0, 0x8(%rsp)
jne 0x3cac
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3b18
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3b2f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x50(%rsp), %rdi
callq 0x40d8
leaq 0x70(%rsp), %rdi
callq 0x408a
xorl %eax, %eax
addq $0x177158, %rsp         # imm = 0x177158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c57
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3c5a
movq 0xa0(%rsp), %rsi
jmp 0x3b96
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x3c5a
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
jmp 0x3ba6
movq %rax, %rbx
movl $0x7dfc0, %esi          # imm = 0x7DFC0
movq %r14, %rdi
callq 0x2270
jmp 0x3c5a
jmp 0x3c1c
movq %rax, %rbx
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c62
movq 0xe8(%rsp), %rsi
jmp 0x3c12
jmp 0x3c1c
movq %rax, %rbx
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c62
movq 0x108(%rsp), %rsi
jmp 0x3c12
jmp 0x3c1c
movq %rax, %rbx
leaq 0x128(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c62
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2270
jmp 0x3c62
movq %rax, %rbx
jmp 0x3c62
jmp 0x3c57
movq %rax, %rbx
jmp 0x3c48
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3c48
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x138(%rsp), %rdi
callq 0x408a
jmp 0x3c5a
movq %rax, %rbx
cmpq $0x0, 0x8(%rsp)
jne 0x3cac
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3c79
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3c90
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2270
leaq 0x50(%rsp), %rdi
callq 0x40d8
leaq 0x70(%rsp), %rdi
callq 0x408a
movq %rbx, %rdi
callq 0x2390
callq 0x20d0
nop