// File: mlugo2[P]SunshineGPU/src/gpu.cpp
// Function: gpu::load_vab(std::vector<std::vector<float, std::allocator<float>>, std::allocator<std::vector<float, std::allocator<float>>>>, std::vector<int, std::allocator<int>>)
void gpu::load_vab( vector<vector<float> > v, vector<int> f)
{
	// Load face data into VAB
	// Get x, y, z for first vertex
	main_mem[VERT_REG][0].x = v[f[1]][0]; 
	main_mem[VERT_REG][0].y = v[f[1]][1]; 
	main_mem[VERT_REG][0].z = v[f[1]][2];
	main_mem[VERT_REG][0].w = 1.0;

	// Get position for second vertex
	main_mem[VERT_REG][1].x = v[f[2]][0]; 
	main_mem[VERT_REG][1].y = v[f[2]][1]; 
	main_mem[VERT_REG][1].z = v[f[2]][2];
	main_mem[VERT_REG][1].w = 1.0;

	// Get position for thrid vertex
	main_mem[VERT_REG][2].x = v[f[3]][0]; 
	main_mem[VERT_REG][2].y = v[f[3]][1]; 
	main_mem[VERT_REG][2].z = v[f[3]][2];
	main_mem[VERT_REG][2].w = 1.0;

	// Calculate initial normal
	float V[] { main_mem[VERT_REG][1].x - main_mem[VERT_REG][0].x, main_mem[VERT_REG][1].y - main_mem[VERT_REG][0].y, main_mem[VERT_REG][1].z - main_mem[VERT_REG][0].z};
	float W[] { main_mem[VERT_REG][2].x - main_mem[VERT_REG][0].x, main_mem[VERT_REG][2].y - main_mem[VERT_REG][0].y, main_mem[VERT_REG][2].z - main_mem[VERT_REG][0].z};
	main_mem[VERT_REG][3].x = (V[1] * W[2]) - (V[2] * W[1]);
	main_mem[VERT_REG][3].y = (V[2] * W[0]) - (V[0] * W[2]);
	main_mem[VERT_REG][3].z = (V[0] * W[1]) - (V[1] * W[0]);
	main_mem[VERT_REG][3].w = 1.0;

	// Set default color
	main_mem[VERT_REG][4].x = 255;
	main_mem[VERT_REG][4].y = 255;
	main_mem[VERT_REG][4].z = 255;
	main_mem[VERT_REG][4].w = 1.0;

}

// Assembly:
subq $0x58, %rsp
movq %rdx, 0x8(%rsp)
movq %rdi, %rax
movq 0x8(%rsp), %rdi
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %rax, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7cc(%rax)
movl $0x1, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x1, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7c8(%rax)
movl $0x1, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x2, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7c4(%rax)
movss 0x80b6(%rip), %xmm0     # 0x15308
movss %xmm0, 0x7d7c0(%rax)
movl $0x2, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7dc(%rax)
movl $0x2, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x1, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7d8(%rax)
movl $0x2, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x2, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7d4(%rax)
movss 0x7ff0(%rip), %xmm0     # 0x15308
movss %xmm0, 0x7d7d0(%rax)
movl $0x3, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7ec(%rax)
movl $0x3, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x1, %esi
callq 0x14ad0
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7e8(%rax)
movl $0x3, %esi
callq 0x14b70
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x14b50
movq %rax, %rdi
movl $0x2, %esi
callq 0x14ad0
movq %rax, %rcx
movq 0x20(%rsp), %rax
movss (%rcx), %xmm0
movss %xmm0, 0x7d7e4(%rax)
movss 0x7f2f(%rip), %xmm0     # 0x15308
movss %xmm0, 0x7d7e0(%rax)
movss 0x7d7dc(%rax), %xmm0
subss 0x7d7cc(%rax), %xmm0
movss %xmm0, 0x34(%rsp)
movss 0x7d7d8(%rax), %xmm0
subss 0x7d7c8(%rax), %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x7d7d4(%rax), %xmm0
subss 0x7d7c4(%rax), %xmm0
movss %xmm0, 0x3c(%rsp)
movss 0x7d7ec(%rax), %xmm0
subss 0x7d7cc(%rax), %xmm0
movss %xmm0, 0x28(%rsp)
movss 0x7d7e8(%rax), %xmm0
subss 0x7d7c8(%rax), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x7d7e4(%rax), %xmm0
subss 0x7d7c4(%rax), %xmm0
movss %xmm0, 0x30(%rsp)
movss 0x38(%rsp), %xmm0
movss 0x30(%rsp), %xmm2
movss 0x3c(%rsp), %xmm1
mulss 0x2c(%rsp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x7d7fc(%rax)
movss 0x3c(%rsp), %xmm0
movss 0x28(%rsp), %xmm2
movss 0x34(%rsp), %xmm1
mulss 0x30(%rsp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x7d7f8(%rax)
movss 0x34(%rsp), %xmm0
movss 0x2c(%rsp), %xmm2
movss 0x38(%rsp), %xmm1
mulss 0x28(%rsp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x7d7f4(%rax)
movss 0x7df9(%rip), %xmm0     # 0x15308
movss %xmm0, 0x7d7f0(%rax)
movss 0x7ded(%rip), %xmm0     # 0x1530c
movss %xmm0, 0x7d80c(%rax)
movss 0x7ddd(%rip), %xmm0     # 0x1530c
movss %xmm0, 0x7d808(%rax)
movss 0x7dcd(%rip), %xmm0     # 0x1530c
movss %xmm0, 0x7d804(%rax)
movss 0x7db9(%rip), %xmm0     # 0x15308
movss %xmm0, 0x7d800(%rax)
addq $0x58, %rsp
retq
nopl (%rax)