// File: /workspace/github_c_makefile_star2_O2/Hazematman[P]BSP-Renderer/bsp.c
// Function: readBsp
Bsp *readBsp(void *bspData, Palette *plt){
	BspHeader header;
	
	memcpy(&header, bspData, sizeof(BspHeader));
	if(header.version != BSP_VERSION){
		printf("Invalid BSP version expected %d found %d\n",
				BSP_VERSION, header.version);
		return NULL;
	}

	Bsp *bsp = malloc(sizeof(Bsp));
	// Start by loading texture data from BSP
	loadBspTextures(bsp, bspData + header.miptex.offset, plt);

	// Next we load the vertex data, plane data, and texture mapping data
	loadBspVerts(bsp, bspData + header.vertices.offset, header.vertices.size);
	loadBspPlanes(bsp, bspData + header.planes.offset, header.planes.size);
	loadBspTexInfo(bsp, bspData + header.texinfo.offset, header.texinfo.size);

	// Next we can load the rest of geometry from the BSP
	loadBspGeometry(bsp, bspData+header.faces.offset, header.faces.size,
			bspData+header.edges.offset, header.edges.size,
			bspData+header.ledges.offset, header.ledges.size);

	// Create vao for face data
	glGenVertexArrays(1, &bsp->vaoId);
	glBindVertexArray(bsp->vaoId);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	return bsp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl (%rdi), %edx
cmpl $0x1d, %edx
jne 0x6a60
movq %rsi, %r15
movq %rdi, %rbp
movslq 0x70(%rdi), %rax
movq %rax, 0x10(%rsp)
movslq 0x6c(%rdi), %rax
movq %rax, 0x8(%rsp)
movslq 0x68(%rdi), %rax
movq %rax, 0x58(%rsp)
movslq 0x64(%rdi), %rax
movq %rax, 0x50(%rsp)
movslq 0x40(%rdi), %rax
movq %rax, 0x28(%rsp)
movslq 0x3c(%rdi), %rax
movq %rax, 0x38(%rsp)
movslq 0x38(%rdi), %rax
movq %rax, 0x20(%rsp)
movslq 0x34(%rdi), %rax
movq %rax, (%rsp)
movslq 0x20(%rdi), %rax
movq %rax, 0x30(%rsp)
movslq 0x1c(%rdi), %rax
movq %rax, 0x48(%rsp)
movslq 0x14(%rdi), %r14
movslq 0x10(%rdi), %rax
movq %rax, 0x18(%rsp)
movslq 0xc(%rdi), %rax
movq %rax, 0x40(%rsp)
pushq $0x38
popq %rdi
callq 0x1160
movq %rax, %r12
leaq (%r14,%rbp), %rbx
movslq (%rbp,%r14), %r14
movl %r14d, 0x4(%rax)
leaq (,%r14,8), %rdi
callq 0x1160
movq %r12, 0x88(%rsp)
movq %rax, 0x90(%rsp)
movq %rax, 0x8(%r12)
xorl %r13d, %r13d
leaq 0x60(%rsp), %r12
cmpq %r14, %r13
jge 0x6a79
movslq 0x4(%rbx,%r13,4), %rax
leaq (%rbx,%rax), %rcx
movups (%rbx,%rax), %xmm0
movups 0x10(%rbx,%rax), %xmm1
movaps %xmm1, 0x70(%rsp)
movq 0x20(%rbx,%rax), %rax
movq %rax, 0x80(%rsp)
movaps %xmm0, 0x60(%rsp)
movl 0x78(%rsp), %edi
addq %rcx, %rdi
movl 0x70(%rsp), %esi
movl 0x74(%rsp), %edx
movq %r15, %rcx
movq %r12, %r8
callq 0x65ac
movq 0x90(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
jmp 0x6a07
leaq 0x2ec5(%rip), %rdi      # 0x992c
xorl %r15d, %r15d
pushq $0x1d
popq %rsi
xorl %eax, %eax
callq 0x1040
jmp 0x6e7c
movq 0x48(%rsp), %r15
addq %rbp, %r15
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq 0x88(%rsp), %rbx
movq %rax, 0x10(%rbx)
movq %rax, 0x48(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10c0
movq 0x40(%rsp), %r15
addq %rbp, %r15
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, 0x20(%rbx)
movq %rax, 0x40(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10c0
movq (%rsp), %r15
addq %rbp, %r15
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, 0x18(%rbx)
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10c0
movq 0x38(%rsp), %r15
addq %rbp, %r15
movq 0x50(%rsp), %r12
addq %rbp, %r12
movq 0x8(%rsp), %rax
addq %rbp, %rax
movq %rax, %rbp
xorl %r14d, %r14d
pushq $0x14
popq %rcx
movq 0x28(%rsp), %r13
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movl %eax, 0x28(%rbx)
movslq %eax, %rdi
movq %rdi, 0x30(%rsp)
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x20(%rsp)
movq %rax, 0x30(%rbx)
movq %r13, %rdi
callq 0x1160
movq %rax, (%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x10c0
movq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x10c0
cmpq 0x30(%rsp), %r14
jge 0x6e2b
movq %r14, %rbp
shlq $0x5, %rbp
movq %r14, 0x38(%rsp)
imulq $0x14, %r14, %r12
movq (%rsp), %r14
movswq 0x8(%r14,%r12), %rbx
movq 0x20(%rsp), %r15
movl %ebx, 0x10(%r15,%rbp)
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x18(%r15,%rbp)
movq %r12, 0x8(%rsp)
movswq 0xa(%r14,%r12), %rax
imulq $0x28, %rax, %r14
movq 0x18(%rsp), %rax
movslq 0x20(%rax,%r14), %rax
movq 0x90(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, 0x8(%r15,%rbp)
andl $0x0, (%r15,%rbp)
callq 0x6722
leaq 0x2d34(%rip), %rdi      # 0x9956
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x6e1e
addq 0x20(%rsp), %rbp
movq 0x8(%rbp), %rdi
callq 0x6722
leaq 0x2d17(%rip), %rdi      # 0x995e
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x6e1e
movq 0x8(%rsp), %rax
addq (%rsp), %rax
movq %rax, 0x8(%rsp)
addq 0x18(%rsp), %r14
leaq 0x10(%r14), %rax
movq %rax, 0x50(%rsp)
testl %ebx, %ebx
movl $0x0, %eax
cmovgl %ebx, %eax
movq %rax, 0x58(%rsp)
pushq $0xc
popq %rbx
xorl %r15d, %r15d
cmpq %r15, 0x58(%rsp)
je 0x6ddf
movq 0x8(%rsp), %rdi
movslq 0x4(%rdi), %rax
addq %r15, %rax
movq 0x28(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
movl %eax, %ecx
negl %ecx
testq %rax, %rax
leaq (%r13,%rcx,4), %rdx
leaq 0x2(%r13,%rcx,4), %rcx
leaq (%r13,%rax,4), %rsi
leaq 0x2(%r13,%rax,4), %rax
cmovsq %rcx, %rsi
cmovsq %rdx, %rax
movzwl (%rsi), %ecx
imulq $0xc, %rcx, %rcx
movq 0x48(%rsp), %rdx
movss 0x8(%rdx,%rcx), %xmm0
movsd (%rdx,%rcx), %xmm1
movsd %xmm1, 0x60(%rsp)
movss %xmm0, 0x68(%rsp)
movzwl (%rax), %eax
imulq $0xc, %rax, %rax
movss 0x8(%rdx,%rax), %xmm0
movsd (%rdx,%rax), %xmm1
movsd %xmm1, 0x6c(%rsp)
movss %xmm0, 0x74(%rsp)
movq 0x18(%rbp), %rax
movswq (%rdi), %rcx
imulq $0x14, %rcx, %rcx
movq 0x40(%rsp), %rsi
movl 0x8(%rsi,%rcx), %edx
movl %edx, 0x10(%rax,%rbx)
movq (%rsi,%rcx), %rcx
movq %rcx, 0x8(%rax,%rbx)
movss 0x60(%rsp), %xmm0
movq 0x18(%rbp), %rax
movss %xmm0, -0xc(%rax,%rbx)
movss 0x68(%rsp), %xmm0
movss %xmm0, -0x8(%rax,%rbx)
movss 0x64(%rsp), %xmm0
xorps 0x2b69(%rip), %xmm0     # 0x98c0
movss %xmm0, -0x4(%rax,%rbx)
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x6808
addss 0xc(%r14), %xmm0
movss %xmm0, 0x10(%rsp)
movq 0x8(%rbp), %rdi
callq 0x671a
cvtsi2ss %eax, %xmm0
movss 0x10(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%rbp), %rax
movss %xmm1, (%rax,%rbx)
movq %r12, %rdi
movq 0x50(%rsp), %rsi
callq 0x6808
addss 0x1c(%r14), %xmm0
movss %xmm0, 0x10(%rsp)
movq 0x8(%rbp), %rdi
callq 0x671e
cvtsi2ss %eax, %xmm0
movss 0x10(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%rbp), %rax
movss %xmm1, 0x4(%rax,%rbx)
incq %r15
addq $0x20, %rbx
jmp 0x6c88
pushq $0x1
popq %rdi
movq %rbp, %rsi
leaq 0x563c(%rip), %rax      # 0xc428
callq *(%rax)
movl (%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
leaq 0x55fb(%rip), %rax      # 0xc3f8
callq *(%rax)
movslq 0x10(%rbp), %rsi
shlq $0x5, %rsi
movq 0x18(%rbp), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
leaq 0x55e4(%rip), %rax      # 0xc400
callq *(%rax)
movq 0x38(%rsp), %r14
incq %r14
jmp 0x6ba7
movq (%rsp), %rdi
callq 0x1150
movq %r13, %rdi
callq 0x1150
movq 0x28(%rsp), %rdi
callq 0x1150
leaq 0x5a4b(%rip), %rax      # 0xc898
pushq $0x1
popq %rbx
movl %ebx, %edi
movq 0x88(%rsp), %r15
movq %r15, %rsi
callq *(%rax)
leaq 0x5972(%rip), %rax      # 0xc7d8
movl (%r15), %edi
callq *(%rax)
leaq 0x566e(%rip), %r14      # 0xc4e0
xorl %edi, %edi
callq *(%r14)
movl %ebx, %edi
callq *(%r14)
movq %r15, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq