// File: /workspace/github_c_makefile_star2_O2/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
movl %r8d, %r13d
movl %ecx, %r12d
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq %rdx, %rdi
callq 0xfbbc
leaq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0xebb6
movq 0x28(%rax), %rdx
leaq 0x2f0e(%rip), %rsi      # 0x11aac
movq %r15, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2330
movl 0x64(%rbx), %edx
leaq 0x2ef4(%rip), %rsi      # 0x11ab4
leaq -0x90(%rbp), %rdi
xorl %eax, %eax
callq 0x2080
incl 0x64(%rbx)
leaq 0x2ee1(%rip), %rsi      # 0x11ab9
movq %r15, %rdi
leaq -0x90(%rbp), %rdx
xorl %eax, %eax
callq 0x2330
testb %r13b, %r13b
je 0xec03
leaq 0x2edb(%rip), %rdi      # 0x11ad0
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2440
testb %r12b, %r12b
je 0xec3a
leaq 0x22cc(%rip), %rax      # 0x10edb
cmpb $0x0, 0x74(%rbx)
leaq 0x22c6(%rip), %r8       # 0x10ee0
cmovneq %rax, %r8
movq (%r14), %rcx
leaq 0x2ed4(%rip), %rsi      # 0x11afc
pushq $0x22
popq %rdx
movq %r15, %rdi
movl %edx, %r9d
xorl %eax, %eax
callq 0x2330
jmp 0xec7d
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%r14), %rdi
leaq -0x48(%rbp), %rsi
callq 0xd637
leaq -0x48(%rbp), %r12
movq (%r12), %rcx
leaq 0x2e89(%rip), %rsi      # 0x11aee
pushq $0x22
popq %rdx
movq %r15, %rdi
movl %edx, %r8d
xorl %eax, %eax
callq 0x2330
movq %r12, %rdi
callq 0x2120
leaq 0x317c(%rip), %rdi      # 0x11e00
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x2440
leaq -0x48(%rbp), %r15
leaq -0x90(%rbp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xf28e
movq %rbx, %rdi
movq %r15, %rsi
callq 0xfc18
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x23e0