// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100, %rsp            # imm = 0x100
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %cl
movb %cl, -0x19(%rbp)
andb $0x1, %al
movb %al, -0x1a(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x250e0
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x25100
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x25160
movq %rax, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x25130
testb $0x1, %al
jne 0x24267
jmp 0x242a4
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x25190
movq %rax, %rdi
addq $0x8, %rdi
callq 0xdce0
movq -0xe0(%rbp), %rdi
movq %rax, %rdx
leaq 0x680b(%rip), %rsi      # 0x2aaa3
movb $0x0, %al
callq 0x3430
jmp 0x24451
leaq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x64(%rax), %edx
leaq 0x67f5(%rip), %rsi      # 0x2aaab
movb $0x0, %al
callq 0x30a0
movq -0x18(%rbp), %rax
movl 0x64(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x64(%rax)
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rdx
leaq 0x67d7(%rip), %rsi      # 0x2aab0
movb $0x0, %al
callq 0x3430
testb $0x1, -0x1a(%rbp)
je 0x242f8
movq -0x8(%rbp), %rdi
leaq 0x67d6(%rip), %rsi      # 0x2aac7
movb $0x0, %al
callq 0x3430
leaq 0x5c02(%rip), %rax      # 0x29f01
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, 0x74(%rax)
je 0x2431e
leaq 0x5be5(%rip), %rax      # 0x29efc
movq %rax, -0x88(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x243c4
leaq -0xa8(%rbp), %rdi
callq 0x3410
movq -0x10(%rbp), %rdi
callq 0xdce0
movq %rax, -0xe8(%rbp)
jmp 0x24346
movq -0xe8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x21db0
jmp 0x2435b
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3130
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
leaq 0x6762(%rip), %rsi      # 0x2aae5
movl $0x22, %r8d
movl %r8d, %edx
movb $0x0, %al
callq 0x3430
leaq -0xa8(%rbp), %rdi
callq 0x3180
jmp 0x24400
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3180
jmp 0x2445a
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x10(%rbp), %rdi
callq 0xdd00
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movq -0x88(%rbp), %r8
leaq 0x6703(%rip), %rsi      # 0x2aaf3
movl $0x22, %r9d
movl %r9d, %edx
movb $0x0, %al
callq 0x3430
movq -0x8(%rbp), %rdi
leaq 0x69ee(%rip), %rsi      # 0x2adf9
movb $0x0, %al
callq 0x3430
movq -0x18(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x10(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x25200
movq -0x100(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x251c0
movq %rax, -0xd8(%rbp)
movb %dl, -0xd0(%rbp)
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)