// File: /workspace/github_c_makefile_star2_O1/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 0x1846
movq %rsi, %rbp
movq %rdi, %r14
movslq 0x70(%rdi), %rax
movq %rax, 0x18(%rsp)
movslq 0x6c(%rdi), %rax
movq %rax, 0x38(%rsp)
movslq 0x68(%rdi), %rax
movq %rax, 0x30(%rsp)
movslq 0x64(%rdi), %rax
movq %rax, 0x10(%rsp)
movslq 0x40(%rdi), %rax
movq %rax, 0x28(%rsp)
movslq 0x3c(%rdi), %rax
movq %rax, 0x8(%rsp)
movslq 0x38(%rdi), %rax
movq %rax, 0x20(%rsp)
movslq 0x34(%rdi), %rax
movq %rax, 0x90(%rsp)
movslq 0x20(%rdi), %rax
movq %rax, 0x78(%rsp)
movslq 0x1c(%rdi), %rax
movq %rax, 0x70(%rsp)
movslq 0x14(%rdi), %rbx
movslq 0x10(%rdi), %rax
movq %rax, 0x88(%rsp)
movslq 0xc(%rdi), %rax
movq %rax, 0x80(%rsp)
movl $0x38, %edi
callq 0x1160
movq %rax, %r13
movslq (%r14,%rbx), %r15
movl %r15d, 0x4(%rax)
leaq (,%r15,8), %rdi
callq 0x1160
movq %rax, 0x8(%r13)
testq %r15, %r15
jle 0x1421
addq %r14, %rbx
xorl %r15d, %r15d
leaq 0x40(%rsp), %r12
movslq 0x4(%rbx,%r15,4), %rax
leaq (%rbx,%rax), %rcx
movups (%rbx,%rax), %xmm0
movups 0x10(%rbx,%rax), %xmm1
movaps %xmm1, 0x50(%rsp)
movq 0x20(%rbx,%rax), %rax
movq %rax, 0x60(%rsp)
movaps %xmm0, 0x40(%rsp)
movl 0x58(%rsp), %edi
addq %rcx, %rdi
movl 0x50(%rsp), %esi
movl 0x54(%rsp), %edx
movq %rbp, %rcx
movq %r12, %r8
callq 0x5038
movq 0x8(%r13), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movslq 0x4(%r13), %rax
cmpq %rax, %r15
jl 0x13cd
movq 0x70(%rsp), %r15
addq %r14, %r15
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x10(%r13)
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x80(%rsp), %r15
addq %r14, %r15
movq 0x88(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x20(%r13)
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x90(%rsp), %r15
addq %r14, %r15
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x18(%r13)
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x8(%rsp), %rbp
addq %r14, %rbp
movq 0x10(%rsp), %r12
addq %r14, %r12
movq 0x38(%rsp), %r15
addq %r14, %r15
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
movq 0x28(%rsp), %r14
movq %r14, %rax
mulq %rcx
shrq $0x4, %rdx
movl %edx, 0x28(%r13)
movslq %edx, %rbx
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x30(%r13)
movq %r14, %rdi
callq 0x1160
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x10c0
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x10c0
movq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x10c0
testl %ebx, %ebx
jle 0x17f6
xorl %ecx, %ecx
movq %r13, 0x68(%rsp)
movq 0x30(%r13), %r12
movq %rcx, %rbp
shlq $0x5, %rbp
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rcx,4), %r14
movq 0x8(%rsp), %r15
movswq 0x8(%r15,%r14,4), %rbx
movl %ebx, 0x10(%r12,%rbp)
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x18(%r12,%rbp)
movswq 0xa(%r15,%r14,4), %rax
movq 0x8(%r13), %rcx
movq 0x18(%r13), %r15
leaq (%rax,%rax,4), %r13
movslq 0x20(%r15,%r13,8), %rax
movq (%rcx,%rax,8), %rdi
movq %rdi, 0x8(%r12,%rbp)
movl $0x0, (%r12,%rbp)
callq 0x51a2
leaq 0x4a90(%rip), %rdi      # 0x604a
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x17dc
addq %rbp, %r12
movq 0x8(%r12), %rdi
callq 0x51a2
leaq 0x4a74(%rip), %rdi      # 0x6052
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x17dc
testw %bx, %bx
jle 0x1798
movq 0x8(%rsp), %rax
leaq (%rax,%r14,4), %rax
leaq (%r15,%r13,8), %r13
movslq 0x4(%rax), %rcx
movswq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x10(%r13), %rax
movq %rax, 0x30(%rsp)
movl %ebx, %ebx
movq 0x20(%rsp), %rax
leaq (%rax,%rcx,4), %r15
shlq $0x2, %rbx
xorl %ebp, %ebp
movslq (%r15,%rbp), %rcx
testq %rcx, %rcx
movq 0x68(%rsp), %rsi
js 0x166b
movq 0x10(%rsp), %rdi
movzwl (%rdi,%rcx,4), %edx
movq 0x10(%rsi), %rax
leaq (%rdx,%rdx,2), %rdx
movsd (%rax,%rdx,4), %xmm0
movss 0x8(%rax,%rdx,4), %xmm1
movsd %xmm0, 0x40(%rsp)
movss %xmm1, 0x48(%rsp)
leaq (%rdi,%rcx,4), %rdx
addq $0x2, %rdx
jmp 0x169a
negl %ecx
movq 0x10(%rsp), %rax
leaq (%rax,%rcx,4), %rdx
movzwl 0x2(%rax,%rcx,4), %ecx
movq 0x10(%rsi), %rax
leaq (%rcx,%rcx,2), %rcx
movsd (%rax,%rcx,4), %xmm0
movss 0x8(%rax,%rcx,4), %xmm1
movsd %xmm0, 0x40(%rsp)
movss %xmm1, 0x48(%rsp)
movzwl (%rdx), %ecx
leaq (%rcx,%rcx,2), %rcx
movss 0x8(%rax,%rcx,4), %xmm0
movsd (%rax,%rcx,4), %xmm1
movsd %xmm1, 0x4c(%rsp)
movss %xmm0, 0x54(%rsp)
movq 0x18(%r12), %rax
movq 0x20(%rsi), %rcx
movq 0x38(%rsp), %rdx
leaq (%rdx,%rdx,4), %rdx
movl 0x8(%rcx,%rdx,4), %esi
movl %esi, 0x1c(%rax,%rbp,8)
movq (%rcx,%rdx,4), %rcx
movq %rcx, 0x14(%rax,%rbp,8)
movss 0x40(%rsp), %xmm0
movq 0x18(%r12), %rax
movss %xmm0, (%rax,%rbp,8)
movss 0x48(%rsp), %xmm0
movss %xmm0, 0x4(%rax,%rbp,8)
movss 0x44(%rsp), %xmm0
xorps 0x490c(%rip), %xmm0     # 0x6010
movss %xmm0, 0x8(%rax,%rbp,8)
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x5288
addss 0xc(%r13), %xmm0
movss %xmm0, 0x18(%rsp)
movq 0x8(%r12), %rdi
callq 0x519a
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x18(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%r12), %rax
movss %xmm1, 0xc(%rax,%rbp,8)
movq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x5288
addss 0x1c(%r13), %xmm0
movss %xmm0, 0x18(%rsp)
movq 0x8(%r12), %rdi
callq 0x519e
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x18(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%r12), %rax
movss %xmm1, 0x10(%rax,%rbp,8)
addq $0x4, %rbp
cmpq %rbp, %rbx
jne 0x162b
movl $0x1, %edi
movq %r12, %rsi
leaq 0x8cc9(%rip), %rax      # 0xa470
callq *(%rax)
movl (%r12), %esi
movl $0x8892, %edi           # imm = 0x8892
leaq 0x8c87(%rip), %rax      # 0xa440
callq *(%rax)
movslq 0x10(%r12), %rsi
shlq $0x5, %rsi
movq 0x18(%r12), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
leaq 0x8c6e(%rip), %rax      # 0xa448
callq *(%rax)
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x68(%rsp), %r13
movslq 0x28(%r13), %rax
cmpq %rax, %rcx
jl 0x1551
movq 0x8(%rsp), %rdi
callq 0x1150
movq 0x10(%rsp), %rdi
callq 0x1150
movq 0x20(%rsp), %rdi
callq 0x1150
leaq 0x90c5(%rip), %rax      # 0xa8e0
movl $0x1, %edi
movq %r13, %rsi
callq *(%rax)
leaq 0x8ff4(%rip), %rax      # 0xa820
movl (%r13), %edi
callq *(%rax)
leaq 0x8cef(%rip), %rbx      # 0xa528
xorl %edi, %edi
callq *(%rbx)
movl $0x1, %edi
callq *(%rbx)
jmp 0x185c
leaq 0x47d3(%rip), %rdi      # 0x6020
xorl %r13d, %r13d
movl $0x1d, %esi
xorl %eax, %eax
callq 0x1040
movq %r13, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq