// File: /workspace/github_c_makefile_star2_O3/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 0xa605(%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 0x69f2
leaq -0x38(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x6cba
leaq 0xa5a1(%rip), %rsi      # 0x12c08
leaq -0x48(%rbp), %rdi
callq 0x2400
movq (%r15), %r15
movq %r15, %rdi
movl $0x5c, %esi
callq 0x2260
testq %rax, %rax
je 0x869d
movq %rax, %r12
callq 0x69ac
incq %r12
movq %rax, %rdi
movq %r12, %rsi
callq 0x6a3e
jmp 0x86ad
callq 0x69ac
movq %rax, %rdi
movq %r15, %rsi
callq 0x6a3e
movq %rax, 0x1f0(%rbx)
leaq -0x98(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7b2c
movq -0x90(%rbp), %r15
testq %r15, %r15
je 0x878f
cmpl $0x50534249, (%r15)     # imm = 0x50534249
jne 0x878c
cmpl $0x2e, 0x4(%r15)
jne 0x878c
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 0x86ff
movb $0x1, (%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x89a6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8a94
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8b9c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8d3c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8f9e
movq %rbx, %rdi
callq 0x90ae
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9196
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9208
movq %rbx, %rdi
movq %r15, %rsi
callq 0x92c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9330
movq %rbx, %rdi
movq %r15, %rsi
callq 0x93a4
jmp 0x878f
movb $0x0, (%rbx)
leaq -0x98(%rbp), %rdi
callq 0x7c1e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x87b0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x87c9
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 0x87e8
jmp 0x87e8
jmp 0x87e8
movq %rax, %r15
jmp 0x8811
movq %rax, %r15
jmp 0x882a
movq %rax, %r15
jmp 0x87fc
movq %rax, %r15
leaq -0x98(%rbp), %rdi
callq 0x7c1e
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x8811
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2230
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x882a
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2230
leaq 0x1d0(%rbx), %rdi
callq 0xa772
movq 0x1b8(%rbx), %rdi
testq %rdi, %rdi
je 0x8851
movq 0x1c8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x1a0(%rbx), %rdi
testq %rdi, %rdi
je 0x886c
movq 0x1b0(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x188(%rbx), %rdi
testq %rdi, %rdi
je 0x8887
movq 0x198(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x170(%rbx), %rdi
testq %rdi, %rdi
je 0x88a2
movq 0x180(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x158(%rbx), %rdi
testq %rdi, %rdi
je 0x88bd
movq 0x168(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x140(%rbx), %rdi
testq %rdi, %rdi
je 0x88d8
movq 0x150(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x88f3
movq 0x138(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0xf0(%rbx), %rdi
testq %rdi, %rdi
je 0x890e
movq 0x100(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0xd8(%rbx), %rdi
testq %rdi, %rdi
je 0x8929
movq 0xe8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
leaq 0xa8(%rbx), %r14
movq 0xc0(%rbx), %rdi
testq %rdi, %rdi
je 0x894b
movq 0xd0(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq (%r14), %rdi
testq %rdi, %rdi
je 0x8962
movq 0xb8(%rbx), %rsi
subq %rdi, %rsi
callq 0x2230
movq %r15, %rdi
callq 0x23c0