// File: /workspace/github_c_makefile_star2_O1/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
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x10(%rdx), %rdx
leaq 0x8(%rbx), %rax
movq %rax, %r8
testq %rdx, %rdx
je 0x102e2
movq (%r15), %rsi
movq %rax, %r8
xorl %edi, %edi
cmpq 0x20(%rdx), %rsi
setb %dil
cmovaeq %rdx, %r8
movq 0x10(%rdx,%rdi,8), %rdx
testq %rdx, %rdx
jne 0x102ca
movq %rax, %rdx
cmpq %rax, %r8
je 0x102f8
movq 0x20(%r8), %rdx
cmpq (%r15), %rdx
cmovbq %rax, %r8
movq %r8, %rdx
cmpq %rax, %rdx
je 0x10320
movq 0x28(%rdx), %rdx
leaq 0x37b4(%rip), %rsi      # 0x13abc
movq %r14, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2300
movl %ecx, -0x2c(%rbp)
movl 0x64(%rbx), %edx
leaq 0x3797(%rip), %rsi      # 0x13ac4
leaq -0x90(%rbp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x2080
incl 0x64(%rbx)
leaq 0x3781(%rip), %rsi      # 0x13ac9
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
testb %r13b, %r13b
je 0x10373
leaq 0x377f(%rip), %rdi      # 0x13ae0
movl $0x1d, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2410
cmpb $0x0, -0x2c(%rbp)
je 0x103b0
leaq 0x2b6b(%rip), %rax      # 0x12eeb
cmpb $0x0, 0x74(%rbx)
leaq 0x2b65(%rip), %r8       # 0x12ef0
cmovneq %rax, %r8
movq (%r15), %rcx
leaq 0x3773(%rip), %rsi      # 0x13b0c
movq %r14, %rdi
movl $0x22, %edx
movl $0x22, %r9d
xorl %eax, %eax
callq 0x2300
jmp 0x10408
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movq (%r15), %rdi
leaq -0x50(%rbp), %rsi
callq 0xe9e7
movq -0x50(%rbp), %rcx
leaq 0x3720(%rip), %rsi      # 0x13afe
movq %r14, %rdi
movl $0x22, %edx
movl $0x22, %r8d
xorl %eax, %eax
callq 0x2300
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x10408
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
leaq 0x3a01(%rip), %rdi      # 0x13e10
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2410
movq (%r15), %rax
leaq -0x50(%rbp), %r14
movq %rax, (%r14)
callq 0x697e
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x6a12
movq %rax, 0x8(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x11278
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x10475
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0
nop