// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/vformat.cpp
// Function: WriteImageTexture(_IO_FILE*, StringRef const&, VFormatOptions&, bool, bool)
void WriteImageTexture(FILE *fph,const StringRef &name,
					   VFormatOptions &options,bool lightmap, bool clamp= false)
{

  // texture node already defined ?
	  TextureDefMap::iterator found;
	  found = options.textureDefMap.find(name);
	  if ( found != options.textureDefMap.end()) { // simply use it 
		  fprintf(fph,"USE %s\n",(const char *)(*found).second );
	  } 
	  else 
	  { // need to define new imageTexture node 

		  char buf[60];
		  sprintf(buf,"_T%d",options.textureCount);
		  options.textureCount++;

		  fprintf(fph,"DEF %s ImageTexture {\n",(const char *)buf);

		  if (clamp) fprintf(fph,"\trepeatS FALSE repeatT FALSE\n");		  
		  const char *ext="bmp";
		  
		  if (options.usePng) 
			  ext = "png";
		  
		  if (!lightmap) {
				String textureFileName;
				// check and return jpg, png ..
				CheckTexture(name, textureFileName);
				fprintf(fph,"  url %c%s%c\n",0x22,textureFileName.c_str(),0x22);
		  } else
			  fprintf(fph,"  url %c%s.%s%c\n",0x22,name.Get(),ext,0x22);
		  
		  fprintf(fph,"}\n");
		  
		  // insert new node into map 
		  options.textureDefMap.insert(TextureDefMap::value_type(name,buf));
		  
	  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rdi, %r14
movq 0x10(%rdx), %r10
testq %r10, %r10
je 0x10226
leaq 0x8(%rbx), %r9
movq (%rsi), %rdx
movq %r9, %rax
xorl %edi, %edi
cmpq 0x20(%r10), %rdx
setb %dil
cmovaeq %r10, %rax
movq 0x10(%r10,%rdi,8), %r10
testq %r10, %r10
jne 0x101ff
cmpq %r9, %rax
je 0x10226
cmpq %rdx, 0x20(%rax)
jae 0x10371
movq %rsi, -0x30(%rbp)
movl %ecx, %r15d
movl 0x64(%rbx), %edx
leaq 0x3869(%rip), %rsi      # 0x13aa0
leaq -0x90(%rbp), %r12
movq %r12, %rdi
xorl %eax, %eax
movl %r8d, %r13d
callq 0x2080
incl 0x64(%rbx)
leaq 0x3850(%rip), %rsi      # 0x13aa5
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
testb %r13b, %r13b
je 0x10280
leaq 0x384e(%rip), %rdi      # 0x13abc
movl $0x1d, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2410
testb %r15b, %r15b
je 0x102c0
leaq 0x2c4f(%rip), %rax      # 0x12edb
cmpb $0x0, 0x74(%rbx)
leaq 0x2c49(%rip), %r8       # 0x12ee0
cmovneq %rax, %r8
movq -0x30(%rbp), %r15
movq (%r15), %rcx
leaq 0x383f(%rip), %rsi      # 0x13ae8
movq %r14, %rdi
movl $0x22, %edx
movl $0x22, %r9d
xorl %eax, %eax
callq 0x2300
jmp 0x1031c
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movq -0x30(%rbp), %r15
movq (%r15), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe8f7
movq -0x50(%rbp), %rcx
leaq 0x37e8(%rip), %rsi      # 0x13ada
movq %r14, %rdi
movl $0x22, %edx
movl $0x22, %r8d
xorl %eax, %eax
callq 0x2300
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x1031c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
leaq 0x3ac9(%rip), %rdi      # 0x13dec
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2410
movq (%r15), %rax
leaq -0x50(%rbp), %r14
movq %rax, (%r14)
callq 0x69ac
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x6a3e
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x111ba
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rax), %rdx
leaq 0x371c(%rip), %rsi      # 0x13a98
movq %r14, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2300
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x103ac
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0