// File: /workspace/github_cpp_makefile_star2_O2/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 0x30a2
movq 0x8f32(%rip), %rdi      # 0xbfc0
leaq 0x50a2(%rip), %rsi      # 0x8137
callq 0x2270
pushq $0x1
popq %rax
jmp 0x32dd
movq %rsi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x150(%rsp), %rdi
movl $0x177000, %edx         # imm = 0x177000
xorl %esi, %esi
callq 0x2170
movq 0x8(%rbx), %rsi
leaq 0x100(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3404
leaq 0x100(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x25b1
leaq 0x100(%rsp), %rdi
callq 0x2120
movq 0x10(%rbx), %rsi
leaq 0xe0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3404
leaq 0xe0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2acc
leaq 0xe0(%rsp), %rdi
callq 0x2120
movq 0x18(%rbx), %rsi
leaq 0xc0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3404
leaq 0xc0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2c2a
leaq 0xc0(%rsp), %rdi
callq 0x2120
leaq -0x26a(%rip), %rsi      # 0x2f2c
leaq 0x8(%rsp), %rdi
leaq 0x150(%rsp), %rdx
callq 0x3512
movl $0x7dfc0, %edi          # imm = 0x7DFC0
callq 0x2280
movq %rax, %rbx
movq %rax, %rdi
callq 0x48e8
leaq 0xa8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x358a
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0x4a38
leaq 0xa8(%rsp), %rdi
callq 0x3dac
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x35d8
leaq 0x90(%rsp), %rsi
movq %rbx, %rdi
callq 0x4a90
leaq 0x90(%rsp), %rdi
callq 0x47a0
pushq $-0x1
popq %rbp
xorl %r15d, %r15d
leaq 0x138(%rsp), %r14
leaq 0x120(%rsp), %r12
leaq 0x150(%rsp), %r13
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
incq %rbp
cmpq %rax, %rbp
je 0x329f
movq %r14, %rdi
leaq 0x70(%rsp), %rsi
callq 0x3626
movq 0x10(%rsp), %rsi
addq %r15, %rsi
movq %r12, %rdi
callq 0x3680
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4ab4
addq $0x18, %r15
movq %r12, %rdi
callq 0x41d4
movq %r14, %rdi
callq 0x36ce
movq %rbx, %rdi
movq %r13, %rsi
callq 0x48ec
jmp 0x3239
leaq 0x8(%rsp), %rdi
callq 0x2360
leaq 0x8(%rsp), %rdi
callq 0x36f0
leaq 0x30(%rsp), %rdi
callq 0x3dac
leaq 0x50(%rsp), %rdi
callq 0x47a0
leaq 0x10(%rsp), %rdi
callq 0x36fe
leaq 0x70(%rsp), %rdi
callq 0x36ce
xorl %eax, %eax
addq $0x177158, %rsp         # imm = 0x177158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x338a
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x47a0
jmp 0x338d
movq %rax, %r14
leaq 0xa8(%rsp), %rdi
callq 0x3dac
jmp 0x338d
movq %rax, %r14
movl $0x7dfc0, %esi          # imm = 0x7DFC0
movq %rbx, %rdi
callq 0x2290
jmp 0x338d
jmp 0x335f
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
jmp 0x3358
jmp 0x335f
movq %rax, %r14
leaq 0xe0(%rsp), %rdi
jmp 0x3358
jmp 0x335f
movq %rax, %r14
leaq 0x100(%rsp), %rdi
callq 0x2120
jmp 0x3397
movq %rax, %r14
jmp 0x3397
jmp 0x338a
movq %rax, %r14
jmp 0x337b
movq %rax, %r14
leaq 0x120(%rsp), %rdi
callq 0x41d4
leaq 0x138(%rsp), %rdi
callq 0x36ce
jmp 0x338d
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x36f0
leaq 0x30(%rsp), %rdi
callq 0x3dac
leaq 0x50(%rsp), %rdi
callq 0x47a0
leaq 0x10(%rsp), %rdi
callq 0x36fe
leaq 0x70(%rsp), %rdi
callq 0x36ce
movq %r14, %rdi
callq 0x2380
nop