// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movl (%rdi), %edx
cmpl $0x1d, %edx
jne 0x1886
movq %rsi, %r15
movq %rdi, %rbx
movslq 0x70(%rdi), %rax
movq %rax, 0x68(%rsp)
movslq 0x6c(%rdi), %rax
movq %rax, 0x60(%rsp)
movslq 0x68(%rdi), %rax
movq %rax, 0x58(%rsp)
movslq 0x64(%rdi), %rax
movq %rax, 0x50(%rsp)
movslq 0x40(%rdi), %rax
movq %rax, 0x48(%rsp)
movslq 0x3c(%rdi), %rax
movq %rax, 0x30(%rsp)
movslq 0x38(%rdi), %rax
movq %rax, 0x18(%rsp)
movslq 0x34(%rdi), %rax
movq %rax, 0x28(%rsp)
movslq 0x20(%rdi), %rax
movq %rax, 0x38(%rsp)
movslq 0x1c(%rdi), %rax
movq %rax, 0x40(%rsp)
movslq 0x14(%rdi), %r14
movslq 0x10(%rdi), %rax
movq %rax, 0x10(%rsp)
movslq 0xc(%rdi), %rax
movq %rax, 0x20(%rsp)
movl $0x38, %edi
callq 0x1160
movq %rax, %r12
movq %rbx, 0x8(%rsp)
movslq (%rbx,%r14), %rbp
movl %ebp, 0x4(%rax)
leaq (,%rbp,8), %rdi
callq 0x1160
movq %rax, %rbx
movq %r12, 0x98(%rsp)
movq %rax, 0x8(%r12)
testq %rbp, %rbp
jle 0x1423
addq 0x8(%rsp), %r14
xorl %r12d, %r12d
leaq 0x70(%rsp), %r13
movslq 0x4(%r14,%r12,4), %rax
leaq (%r14,%rax), %rcx
movups (%r14,%rax), %xmm0
movups 0x10(%r14,%rax), %xmm1
movaps %xmm1, 0x80(%rsp)
movq 0x20(%r14,%rax), %rax
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x70(%rsp)
movl 0x88(%rsp), %edi
addq %rcx, %rdi
movl 0x80(%rsp), %esi
movl 0x84(%rsp), %edx
movq %r15, %rcx
movq %r13, %r8
callq 0x73c0
movq %rax, (%rbx,%r12,8)
incq %r12
cmpq %rbp, %r12
jl 0x13c6
movq %rbx, 0xa0(%rsp)
movq 0x8(%rsp), %rbp
movq 0x40(%rsp), %r12
addq %rbp, %r12
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq 0x98(%rsp), %r14
movq %rax, 0x10(%r14)
movq %rax, 0x40(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x20(%rsp), %r12
addq %rbp, %r12
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x20(%r14)
movq %rax, 0x38(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x28(%rsp), %r12
addq %rbp, %r12
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x1160
movq %rax, 0x18(%r14)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x10c0
movq 0x30(%rsp), %rbx
addq %rbp, %rbx
movq 0x50(%rsp), %r13
addq %rbp, %r13
movq 0x60(%rsp), %r12
addq %rbp, %r12
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
movq 0x48(%rsp), %rbp
movq %rbp, %rax
mulq %rcx
shrq $0x4, %rdx
movl %edx, 0x28(%r14)
movq %rdx, 0x10(%rsp)
movslq %edx, %r15
movq %r15, %rdi
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x30(%rsp)
movq %rax, 0x30(%r14)
movq %rbp, %rdi
callq 0x1160
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x10c0
movq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x10c0
movq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x1160
movq %rax, 0x20(%rsp)
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x10c0
testl %r15d, %r15d
jle 0x1831
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %rax, %r14
shlq $0x5, %r14
movq %rax, 0x48(%rsp)
leaq (%rax,%rax,4), %rbx
movq 0x18(%rsp), %r15
movswq 0x8(%r15,%rbx,4), %r12
movq 0x30(%rsp), %r13
movl %r12d, 0x10(%r13,%r14)
movq %r12, %rdi
shlq $0x5, %rdi
callq 0x1160
movq %rax, 0x18(%r13,%r14)
movswq 0xa(%r15,%rbx,4), %rax
leaq (%rax,%rax,4), %r15
movq 0x28(%rsp), %rax
movslq 0x20(%rax,%r15,8), %rax
movq 0xa0(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, 0x8(%r13,%r14)
movl $0x0, (%r13,%r14)
callq 0x7537
leaq 0x6a59(%rip), %rdi      # 0x804a
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x181e
addq 0x30(%rsp), %r14
movq 0x8(%r14), %rdi
callq 0x7537
leaq 0x6a3c(%rip), %rdi      # 0x8052
movq %rax, %rsi
callq 0x1170
testl %eax, %eax
je 0x181e
movq %r15, %rdx
testw %r12w, %r12w
movaps 0x69dc(%rip), %xmm2     # 0x8010
leaq 0x70(%rsp), %r15
movq %r12, %rsi
movq %rbp, %r12
movq 0x40(%rsp), %rbp
jle 0x17da
movq 0x18(%rsp), %rax
leaq (%rax,%rbx,4), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rdx,8), %rbx
movslq 0x4(%rax), %rcx
movswq (%rax), %rax
leaq 0x10(%rbx), %rdx
movq %rdx, 0x68(%rsp)
movl %esi, %esi
movq 0x20(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
movq %rcx, 0x58(%rsp)
leaq (%rax,%rax,4), %rax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x50(%rsp)
shlq $0x2, %rsi
movq %rsi, 0x60(%rsp)
xorl %r13d, %r13d
movq 0x58(%rsp), %rax
movslq (%rax,%r13), %rax
movl %eax, %ecx
negl %ecx
testq %rax, %rax
leaq (%r12,%rcx,4), %rdx
leaq 0x2(%r12,%rcx,4), %rcx
leaq (%r12,%rax,4), %rsi
cmovsq %rcx, %rsi
leaq 0x2(%r12,%rax,4), %rax
cmovsq %rdx, %rax
movzwl (%rsi), %ecx
leaq (%rcx,%rcx,2), %rcx
movss 0x8(%rbp,%rcx,4), %xmm0
movsd (%rbp,%rcx,4), %xmm1
movsd %xmm1, 0x70(%rsp)
movss %xmm0, 0x78(%rsp)
movzwl (%rax), %eax
leaq (%rax,%rax,2), %rax
movss 0x8(%rbp,%rax,4), %xmm0
movsd (%rbp,%rax,4), %xmm1
movsd %xmm1, 0x7c(%rsp)
movss %xmm0, 0x84(%rsp)
movq 0x18(%r14), %rax
movq 0x50(%rsp), %rdx
movl 0x8(%rdx), %ecx
movl %ecx, 0x1c(%rax,%r13,8)
movq (%rdx), %rcx
movq %rcx, 0x14(%rax,%r13,8)
movss 0x70(%rsp), %xmm0
movq 0x18(%r14), %rax
movss %xmm0, (%rax,%r13,8)
movss 0x78(%rsp), %xmm0
movss %xmm0, 0x4(%rax,%r13,8)
movss 0x74(%rsp), %xmm0
xorps %xmm2, %xmm0
movss %xmm0, 0x8(%rax,%r13,8)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x761c
addss 0xc(%rbx), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0x752f
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x8(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%r14), %rax
movss %xmm1, 0xc(%rax,%r13,8)
movq %r15, %rdi
movq 0x68(%rsp), %rsi
callq 0x761c
addss 0x1c(%rbx), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x8(%r14), %rdi
callq 0x7533
movaps 0x6861(%rip), %xmm2     # 0x8010
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x8(%rsp), %xmm1
divss %xmm0, %xmm1
movq 0x18(%r14), %rax
movss %xmm1, 0x10(%rax,%r13,8)
addq $0x4, %r13
cmpq %r13, 0x60(%rsp)
jne 0x169b
movl $0x1, %edi
movq %r14, %rsi
leaq 0xac87(%rip), %rax      # 0xc470
callq *(%rax)
movl (%r14), %esi
movl $0x8892, %edi           # imm = 0x8892
leaq 0xac46(%rip), %rax      # 0xc440
callq *(%rax)
movslq 0x10(%r14), %rsi
shlq $0x5, %rsi
movq 0x18(%r14), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x88e4, %ecx           # imm = 0x88E4
leaq 0xac2f(%rip), %rax      # 0xc448
callq *(%rax)
movq %r12, %rbp
movq 0x48(%rsp), %rax
incq %rax
cmpq 0x10(%rsp), %rax
jb 0x1581
movq 0x18(%rsp), %rdi
callq 0x1150
movq %rbp, %rdi
callq 0x1150
movq 0x20(%rsp), %rdi
callq 0x1150
leaq 0xb08c(%rip), %rax      # 0xc8e0
movl $0x1, %edi
movq 0x98(%rsp), %r14
movq %r14, %rsi
callq *(%rax)
leaq 0xafb3(%rip), %rax      # 0xc820
movl (%r14), %edi
callq *(%rax)
leaq 0xacaf(%rip), %rbx      # 0xc528
xorl %edi, %edi
callq *(%rbx)
movl $0x1, %edi
callq *(%rbx)
jmp 0x189c
leaq 0x6793(%rip), %rdi      # 0x8020
xorl %r14d, %r14d
movl $0x1d, %esi
xorl %eax, %eax
callq 0x1040
movq %r14, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq