// File: /workspace/github_c_makefile_star2_O0/vlenhart[P]q3bsp/q3bsp.cpp
// Function: QuakeFace::Build(std::vector<unsigned short, std::allocator<unsigned short>> const&, std::vector<QuakeVertex, std::allocator<QuakeVertex>> const&, std::vector<ShaderReference, std::allocator<ShaderReference>>&, StringRef const&, StringRef const&, StringRef const&, VertexMesh&)
void QuakeFace::Build(const UShortVector &elements,
                      const QuakeVertexVector &vertices,
                      ShaderReferenceVector &shaders,
                      const StringRef &lmPrefix,
                      const StringRef &sourcename,
                      const StringRef &code,
                      VertexMesh &mesh)
{
  assert( mVcount < 1024 );
  assert( mShader >= 0 && mShader < shaders.size() );
  StringRef mat;


  static StringRef oname = StringDict::gStringDict().Get("outside");
  static StringRef inside  = StringDict::gStringDict().Get("inside");

  StringRef name = inside;


  int type = 0;

  LightMapVertex verts[1024];

  for (int i=0; i<mVcount; i++)
  {
    vertices[ i+mFirstVertice ].Get(verts[i]);
  }

  char scratch[256];
  char texname[256];

  //shaders[ mShader ].GetTextureName(texname);
  shaders[ mShader ].GetTextureFullName(texname); // get full name with path

/* hg why ?
  if ( strcmp("toxicskytim_ctf1",texname) == 0 ) 
	  return;
*/

#if 0
  if ( mLightmap < 0 ) 
	  return;
#endif

  StringRef basetexture = StringDict::gStringDict().Get(texname);

  QuakeShader *shader = QuakeShaderFactory::gQuakeShaderFactory().Locate(basetexture);

  if ( shader )
  {
    //shader->GetBaseTexture(basetexture);
    //printf("Shader uses texture: %s\n",basetexture);
  }
  else {

	  if ( strcmp("textures/liquids/lavahell_1000",basetexture) == 0 )  {
	  }
	  if ( strstr(basetexture,"lavahell") )  {
	    printf("shader for : %s\n",basetexture.Get());
	  }

	// try to load a matching shader from disk 
    shaders[mShader].GetShaderFileName(scratch); 
	strcat(scratch,".shader");
    mat = StringDict::gStringDict().Get(scratch);

	if (!QuakeShaderFactory::gQuakeShaderFactory().ShaderFileLoaded(mat)
		&& 	QuakeShaderFactory::gQuakeShaderFactory().AddShader(mat)) 
	{
	     shader = QuakeShaderFactory::gQuakeShaderFactory().Locate(basetexture);
	}

	if (!shader) {
	    printf("No shader for : '%s'\n",basetexture.Get());

	}
  }	
  
  // geometry sorted by shader  string

  if ( mLightmap < 0 ) // no lightmap
	  sprintf(scratch,"%s+",basetexture.Get());
  else	
	sprintf(scratch,"%s+%slm%s%02d",basetexture.Get(),lmPrefix.Get(),
          code.Get(),
          mLightmap);

  mat = StringDict::gStringDict().Get(scratch);

  char lmapspace[256];
  sprintf(lmapspace,"lm%s%02d",code.Get(),mLightmap);
  StringRef lmap = SGET(lmapspace);

  switch ( mType )
  {
    case FACETYPE_NORMAL:
    case FACETYPE_TRISURF:
          if ( 1 )
          {
            assert( (mEcount%3) == 0 );
            const unsigned short *idx = &elements[mFirstElement];
            int tcount = mEcount/3;
            for (int j=0; j<tcount; j++)
            {
              int i1 = idx[0];
              int i2 = idx[1];
              int i3 = idx[2];

              mesh.AddTri(mat,verts[i1], verts[i2], verts[i3] );

              idx+=3;
            }
          }
          break;
    case FACETYPE_MESH:
        if ( 1 )
        {
          PatchSurface surface(verts,mVcount,mControlX,mControlY);
          const LightMapVertex *vlist = surface.GetVerts();
          const unsigned short *indices = surface.GetIndices();
          int tcount = surface.GetIndiceCount()/3;

          for (int j=0; j<tcount; j++)
          {

            int i1 = *indices++;
            int i2 = *indices++;
            int i3 = *indices++;

            mesh.AddTri(mat,vlist[i1], vlist[i2], vlist[i3] );

          }
        }
        break;
    case FACETYPE_FLARE:
      break;
    default:
//      assert( 0 );
      break;
  }
  if (mesh.mLastSection && shader) 
	  mesh.mLastSection->SetShader(shader);


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa490, %rsp           # imm = 0xA490
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa400(%rbp)
cmpl $0x400, 0x14(%rax)      # imm = 0x400
jge 0x107f1
jmp 0x10810
leaq 0x1974d(%rip), %rdi     # 0x29f45
leaq 0x19433(%rip), %rsi     # 0x29c32
movl $0x207, %edx            # imm = 0x207
leaq 0x19749(%rip), %rcx     # 0x29f54
callq 0x31c0
movq -0xa400(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x4(%rcx)
movb %al, -0xa401(%rbp)
jb 0x10855
movq -0xa400(%rbp), %rax
movl 0x4(%rax), %eax
movq %rax, -0xa410(%rbp)
movq -0x20(%rbp), %rdi
callq 0x12d10
movq %rax, %rcx
movq -0xa410(%rbp), %rax
cmpq %rcx, %rax
setb %al
movb %al, -0xa401(%rbp)
movb -0xa401(%rbp), %al
testb $0x1, %al
jne 0x10861
jmp 0x10863
jmp 0x10882
leaq 0x19791(%rip), %rdi     # 0x29ffb
leaq 0x193c1(%rip), %rsi     # 0x29c32
movl $0x208, %edx            # imm = 0x208
leaq 0x196d7(%rip), %rcx     # 0x29f54
callq 0x31c0
leaq -0x38(%rbp), %rdi
callq 0x9750
cmpb $0x0, 0x2cfb6(%rip)     # 0x3d848
jne 0x108db
leaq 0x2cfad(%rip), %rdi     # 0x3d848
callq 0x3530
cmpl $0x0, %eax
je 0x108db
callq 0x91c0
movq %rax, -0xa418(%rbp)
jmp 0x108b3
movq -0xa418(%rbp), %rsi
leaq 0x2cf7f(%rip), %rdi     # 0x3d840
leaq 0x1975c(%rip), %rdx     # 0x2a024
callq 0x9240
jmp 0x108cf
leaq 0x2cf72(%rip), %rdi     # 0x3d848
callq 0x31b0
cmpb $0x0, 0x2cf76(%rip)     # 0x3d858
jne 0x1092b
leaq 0x2cf6d(%rip), %rdi     # 0x3d858
callq 0x3530
cmpl $0x0, %eax
je 0x1092b
callq 0x91c0
movq %rax, -0xa420(%rbp)
jmp 0x10903
movq -0xa420(%rbp), %rsi
leaq 0x2cf3f(%rip), %rdi     # 0x3d850
leaq 0x19714(%rip), %rdx     # 0x2a02c
callq 0x9240
jmp 0x1091f
leaq 0x2cf32(%rip), %rdi     # 0x3d858
callq 0x31b0
leaq -0x50(%rbp), %rdi
leaq 0x2cf1a(%rip), %rsi     # 0x3d850
callq 0x12d40
movl $0x0, -0x54(%rbp)
leaq -0xa060(%rbp), %rax
movq %rax, %rcx
addq $0xa000, %rcx           # imm = 0xA000
movq %rcx, -0xa430(%rbp)
movq %rax, -0xa428(%rbp)
movq -0xa428(%rbp), %rdi
movq %rdi, -0xa438(%rbp)
callq 0xe730
movq -0xa438(%rbp), %rax
movq -0xa430(%rbp), %rcx
addq $0x28, %rax
cmpq %rcx, %rax
movq %rax, -0xa428(%rbp)
jne 0x10961
movl $0x0, -0xa064(%rbp)
movq -0xa400(%rbp), %rcx
movl -0xa064(%rbp), %eax
cmpl 0x14(%rcx), %eax
jge 0x10a36
movq -0xa400(%rbp), %rcx
movq -0x18(%rbp), %rdi
movl -0xa064(%rbp), %eax
addl 0x10(%rcx), %eax
movslq %eax, %rsi
callq 0x12d80
movq %rax, %rdi
movslq -0xa064(%rbp), %rax
leaq -0xa060(%rbp), %rsi
imulq $0x28, %rax, %rax
addq %rax, %rsi
callq 0x106e0
movl -0xa064(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa064(%rbp)
jmp 0x1099c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq 0x2ce39(%rip), %rdi     # 0x3d848
callq 0x31a0
jmp 0x11028
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq 0x2ce2c(%rip), %rdi     # 0x3d858
callq 0x31a0
jmp 0x11028
movq -0xa400(%rbp), %rax
movq -0x20(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x12da0
movq %rax, %rdi
leaq -0xa270(%rbp), %rsi
callq 0x12dc0
callq 0x91c0
movq %rax, %rsi
leaq -0xa270(%rbp), %rdx
leaq -0xa278(%rbp), %rdi
callq 0x9240
callq 0x12df0
movq %rax, %rdi
leaq -0xa278(%rbp), %rsi
callq 0x1b490
movq %rax, -0xa280(%rbp)
cmpq $0x0, -0xa280(%rbp)
je 0x10a9f
jmp 0x10bd1
leaq -0xa278(%rbp), %rdi
callq 0xdce0
movq %rax, %rsi
leaq 0x1957e(%rip), %rdi     # 0x2a033
callq 0x3420
cmpl $0x0, %eax
jne 0x10ac1
jmp 0x10ac1
leaq -0xa278(%rbp), %rdi
callq 0xdce0
movq %rax, %rdi
leaq 0x1957b(%rip), %rsi     # 0x2a052
callq 0x30c0
cmpq $0x0, %rax
je 0x10aff
leaq -0xa278(%rbp), %rdi
callq 0xdd00
movq %rax, %rsi
leaq 0x19563(%rip), %rdi     # 0x2a05b
movb $0x0, %al
callq 0x3060
movq -0xa400(%rbp), %rax
movq -0x20(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, %esi
callq 0x12da0
movq %rax, %rdi
leaq -0xa170(%rbp), %rsi
callq 0x11040
leaq -0xa170(%rbp), %rdi
leaq 0x19a5d(%rip), %rsi     # 0x2a58e
callq 0x3510
callq 0x91c0
movq %rax, %rsi
leaq -0xa170(%rbp), %rdx
leaq -0xa288(%rbp), %rdi
callq 0x9240
leaq -0x38(%rbp), %rdi
leaq -0xa288(%rbp), %rsi
callq 0xdca0
callq 0x12df0
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1b520
testb $0x1, %al
jne 0x10ba8
callq 0x12df0
movq %rax, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1b0b0
testb $0x1, %al
jne 0x10b8d
jmp 0x10ba8
callq 0x12df0
movq %rax, %rdi
leaq -0xa278(%rbp), %rsi
callq 0x1b490
movq %rax, -0xa280(%rbp)
cmpq $0x0, -0xa280(%rbp)
jne 0x10bcf
leaq -0xa278(%rbp), %rdi
callq 0xdd00
movq %rax, %rsi
leaq 0x194a4(%rip), %rdi     # 0x2a06c
movb $0x0, %al
callq 0x3060
jmp 0x10bd1
movq -0xa400(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jge 0x10c12
leaq -0xa170(%rbp), %rax
movq %rax, -0xa440(%rbp)
leaq -0xa278(%rbp), %rdi
callq 0xdd00
movq -0xa440(%rbp), %rdi
movq %rax, %rdx
leaq 0x19479(%rip), %rsi     # 0x2a082
movb $0x0, %al
callq 0x30a0
jmp 0x10c7d
leaq -0xa170(%rbp), %rax
movq %rax, -0xa458(%rbp)
leaq -0xa278(%rbp), %rdi
callq 0xdd00
movq %rax, -0xa450(%rbp)
movq -0x28(%rbp), %rdi
callq 0xdd00
movq %rax, -0xa448(%rbp)
movq 0x10(%rbp), %rdi
callq 0xdd00
movq -0xa458(%rbp), %rdi
movq -0xa450(%rbp), %rdx
movq -0xa448(%rbp), %rcx
movq %rax, %r8
movq -0xa400(%rbp), %rax
movl 0x20(%rax), %r9d
leaq 0x19410(%rip), %rsi     # 0x2a086
movb $0x0, %al
callq 0x30a0
callq 0x91c0
movq %rax, %rsi
leaq -0xa290(%rbp), %rdi
movq %rdi, -0xa470(%rbp)
leaq -0xa170(%rbp), %rdx
callq 0x9240
movq -0xa470(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0xdca0
movq 0x10(%rbp), %rdi
callq 0xdd00
movq %rax, %rdx
movq -0xa400(%rbp), %rax
movl 0x20(%rax), %ecx
leaq 0x193bf(%rip), %rsi     # 0x2a08b
xorl %eax, %eax
leaq -0xa390(%rbp), %rdi
movq %rdi, -0xa468(%rbp)
callq 0x30a0
callq 0x91c0
movq -0xa468(%rbp), %rdx
movq %rax, %rsi
leaq -0xa398(%rbp), %rdi
callq 0x9240
movq -0xa400(%rbp), %rax
movl 0xc(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xa460(%rbp)
subl $0x3, %eax
ja 0x10ff6
movq -0xa460(%rbp), %rax
leaq 0x18eec(%rip), %rcx     # 0x29c14
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0xa400(%rbp), %rax
movl 0x1c(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x10d4a
jmp 0x10d69
leaq 0x19343(%rip), %rdi     # 0x2a094
leaq 0x18eda(%rip), %rsi     # 0x29c32
movl $0x262, %edx            # imm = 0x262
leaq 0x191f0(%rip), %rcx     # 0x29f54
callq 0x31c0
movq -0xa400(%rbp), %rax
movq -0x10(%rbp), %rdi
movslq 0x18(%rax), %rsi
callq 0x12e70
movq %rax, %rcx
movq -0xa400(%rbp), %rax
movq %rcx, -0xa3a0(%rbp)
movl 0x1c(%rax), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0xa3a4(%rbp)
movl $0x0, -0xa3a8(%rbp)
movl -0xa3a8(%rbp), %eax
cmpl -0xa3a4(%rbp), %eax
jge 0x10e5f
movq -0xa3a0(%rbp), %rax
movzwl (%rax), %eax
movl %eax, -0xa3ac(%rbp)
movq -0xa3a0(%rbp), %rax
movzwl 0x2(%rax), %eax
movl %eax, -0xa3b0(%rbp)
movq -0xa3a0(%rbp), %rax
movzwl 0x4(%rax), %eax
movl %eax, -0xa3b4(%rbp)
movq 0x18(%rbp), %rdi
movslq -0xa3ac(%rbp), %rax
leaq -0xa060(%rbp), %rdx
imulq $0x28, %rax, %rax
addq %rax, %rdx
movslq -0xa3b0(%rbp), %rax
leaq -0xa060(%rbp), %rcx
imulq $0x28, %rax, %rax
addq %rax, %rcx
movslq -0xa3b4(%rbp), %rax
leaq -0xa060(%rbp), %r8
imulq $0x28, %rax, %rax
addq %rax, %r8
leaq -0x38(%rbp), %rsi
callq 0x22430
movq -0xa3a0(%rbp), %rax
addq $0x6, %rax
movq %rax, -0xa3a0(%rbp)
movl -0xa3a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa3a8(%rbp)
jmp 0x10da9
jmp 0x10ff8
movq -0xa400(%rbp), %rax
movl 0x14(%rax), %edx
movl 0x64(%rax), %ecx
movl 0x68(%rax), %r8d
leaq -0xa3d0(%rbp), %rdi
movq %rdi, -0xa480(%rbp)
leaq -0xa060(%rbp), %rsi
callq 0xdd20
movq -0xa480(%rbp), %rdi
callq 0x12e90
movq %rax, -0xa478(%rbp)
jmp 0x10ea4
movq -0xa478(%rbp), %rax
movq %rax, -0xa3d8(%rbp)
leaq -0xa3d0(%rbp), %rdi
callq 0x12eb0
movq %rax, -0xa488(%rbp)
jmp 0x10ec7
movq -0xa488(%rbp), %rax
movq %rax, -0xa3e0(%rbp)
leaq -0xa3d0(%rbp), %rdi
callq 0x12ed0
movl %eax, -0xa48c(%rbp)
jmp 0x10ee9
movl -0xa48c(%rbp), %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0xa3e4(%rbp)
movl $0x0, -0xa3e8(%rbp)
movl -0xa3e8(%rbp), %eax
cmpl -0xa3e4(%rbp), %eax
jge 0x10fe6
movq -0xa3e0(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0xa3e0(%rbp)
movzwl (%rax), %eax
movl %eax, -0xa3ec(%rbp)
movq -0xa3e0(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0xa3e0(%rbp)
movzwl (%rax), %eax
movl %eax, -0xa3f0(%rbp)
movq -0xa3e0(%rbp), %rax
movq %rax, %rcx
addq $0x2, %rcx
movq %rcx, -0xa3e0(%rbp)
movzwl (%rax), %eax
movl %eax, -0xa3f4(%rbp)
movq 0x18(%rbp), %rdi
movq -0xa3d8(%rbp), %rax
movslq -0xa3ec(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdx
movslq -0xa3f0(%rbp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rcx
movslq -0xa3f4(%rbp), %rsi
leaq (%rsi,%rsi,4), %rsi
leaq (%rax,%rsi,8), %r8
leaq -0x38(%rbp), %rsi
callq 0x22430
jmp 0x10fb6
jmp 0x10fb8
movl -0xa3e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa3e8(%rbp)
jmp 0x10f07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa3d0(%rbp), %rdi
callq 0xe3f0
jmp 0x11028
leaq -0xa3d0(%rbp), %rdi
callq 0xe3f0
jmp 0x10ff8
jmp 0x10ff8
jmp 0x10ff8
movq 0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1101f
cmpq $0x0, -0xa280(%rbp)
je 0x1101f
movq 0x18(%rbp), %rax
movq (%rax), %rdi
movq -0xa280(%rbp), %rsi
callq 0x12ee0
addq $0xa490, %rsp           # imm = 0xA490
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)