// File: /workspace/github_c_makefile_star2_O1/vlenhart[P]q3bsp/q3bsp.cpp
// Function: Quake3BSP::Quake3BSP(StringRef const&, StringRef const&)
Quake3BSP::Quake3BSP(const StringRef &fname,
                     const StringRef &code)
{
  mMesh = 0;

  mOk = false;
  mName     = fname;
  mCodeName = code;

  mUsePng = true; // hg 

  String ifoo = fname;
  String str = ifoo+".bsp";

  // hg prefix for light map files 
  const char * del = strrchr(fname,'\\');
  if (del) mLmPrefix = (del+1); // use file name part only
  else mLmPrefix=fname.Get();

  Fload data(str);

  void *mem = data.GetData();
  int   len = data.GetLen();
  if ( mem )
  {

    mOk = mHeader.SetHeader(mem);

    if ( mOk )
    {
      ReadFaces(mem);
      ReadElements(mem);
      ReadVertices(mem);
      ReadLightmaps(mem);
      ReadShaders(mem);
      BuildVertexBuffers();

	  ReadPlanes(mem);
	  ReadLeaves(mem);
	  ReadLeafSurfaces(mem);

	  ReadNodes(mem);
	  // brushes 
	  ReadEntities(mem);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
leaq 0xa535(%rip), %r13      # 0x12bb2
movq %r13, 0x8(%rdi)
movq %r13, 0x10(%rdi)
addq $0x128, %rdi            # imm = 0x128
xorps %xmm0, %xmm0
movups %xmm0, 0xa8(%rbx)
movups %xmm0, 0xb8(%rbx)
movups %xmm0, 0xc8(%rbx)
movups %xmm0, 0xd8(%rbx)
movups %xmm0, 0xe8(%rbx)
movups %xmm0, 0xf8(%rbx)
movups %xmm0, 0x108(%rbx)
xorl %r14d, %r14d
movq %r14, 0x118(%rbx)
movl $0xc0, %edx
movq %rdi, -0x50(%rbp)
xorl %esi, %esi
callq 0x2150
movq %r13, 0x1f0(%rbx)
movq %r14, 0x120(%rbx)
movb $0x0, (%rbx)
movq (%r15), %rax
movq %rax, 0x8(%rbx)
movq (%r12), %rax
movq %rax, 0x10(%rbx)
movb $0x1, 0x1e8(%rbx)
movq (%r15), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x98(%rbp), %rdx
callq 0x69c6
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x6ca8
leaq 0xa4e1(%rip), %rsi      # 0x12c18
leaq -0x48(%rbp), %rdi
callq 0x2400
movq (%r15), %r15
movq %r15, %rdi
movl $0x5c, %esi
callq 0x2260
testq %rax, %rax
je 0x876d
movq %rax, %r12
callq 0x697e
incq %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x6a12
jmp 0x877d
callq 0x697e
movq %rax, %rdi
movq %r15, %rsi
callq 0x6a12
movq %rax, 0x1f0(%rbx)
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7b70
movq -0x90(%rbp), %r15
testq %r15, %r15
je 0x885f
cmpl $0x50534249, (%r15)     # imm = 0x50534249
jne 0x885c
cmpl $0x2e, 0x4(%r15)
jne 0x885c
movl $0x50534249, 0x18(%rbx) # imm = 0x50534249
movl 0x4(%r15), %eax
movl %eax, 0x1c(%rbx)
movl $0x4, %eax
movq -0x18(%r15,%rax,8), %rcx
movq %rcx, (%rbx,%rax,8)
incq %rax
cmpq $0x15, %rax
jne 0x87cf
movb $0x1, (%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8a76
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8b64
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8c6c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8e1a
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9062
movq %rbx, %rdi
callq 0x9172
movq %rbx, %rdi
movq %r15, %rsi
callq 0x925c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92ce
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9386
movq %rbx, %rdi
movq %r15, %rsi
callq 0x93f6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x946a
jmp 0x885f
movb $0x0, (%rbx)
leaq -0x98(%rbp), %rdi
callq 0x7c62
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x8880
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8899
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2230
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x88b8
jmp 0x88b8
jmp 0x88b8
movq %rax, %r15
jmp 0x88e1
movq %rax, %r15
jmp 0x88fa
movq %rax, %r15
jmp 0x88cc
movq %rax, %r15
leaq -0x98(%rbp), %rdi
callq 0x7c62
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x88e1
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x88fa
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2230
leaq 0x1d0(%rbx), %rdi
callq 0xa85c
movq 0x1b8(%rbx), %rdi
testq %rdi, %rdi
je 0x8921
movq 0x1c8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x1a0(%rbx), %rdi
testq %rdi, %rdi
je 0x893c
movq 0x1b0(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x188(%rbx), %rdi
testq %rdi, %rdi
je 0x8957
movq 0x198(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x170(%rbx), %rdi
testq %rdi, %rdi
je 0x8972
movq 0x180(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x158(%rbx), %rdi
testq %rdi, %rdi
je 0x898d
movq 0x168(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x140(%rbx), %rdi
testq %rdi, %rdi
je 0x89a8
movq 0x150(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x89c3
movq 0x138(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x89de
movq 0x100(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0xd8(%rbx), %rdi
testq %rdi, %rdi
je 0x89f9
movq 0xe8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
leaq 0xa8(%rbx), %r14
movq 0xc0(%rbx), %rdi
testq %rdi, %rdi
je 0x8a1b
movq 0xd0(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8a32
movq 0xb8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq %r15, %rdi
callq 0x23c0