// File: /workspace/github_c_makefile_star2_O0/vlenhart[P]q3bsp/vformat.cpp
// Function: CheckTexture(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void CheckTexture(const char *baseName, String &textureFileName)
{

	const char *ext = strrchr(baseName,'.');

	// check if jpg exists
	textureFileName=baseName;
	if (!ext) {
		textureFileName+=".jpg";

		if (ExistsFile(textureFileName.c_str()))
			return;
	}


	// check if png exists
	textureFileName=baseName;
	if (ext)  // erase ext 
		textureFileName.erase(textureFileName.size()-strlen(ext),strlen(ext));

	textureFileName+=".png";

	if (ExistsFile(textureFileName.c_str()))
		return;

	// check if tga exists
	textureFileName=baseName;
	if (ext)  // erase ext 
		textureFileName.erase(textureFileName.size()-strlen(ext),strlen(ext));

	textureFileName+=".tga";

	if (ExistsFile(textureFileName.c_str())) {
		// convert tga to png
		String outFileName=baseName;
		if (ext)  // erase ext 
			outFileName.erase(outFileName.size()-strlen(ext),strlen(ext));

		outFileName+=".png";

		// bmp.TGAToPNG(textureFileName.c_str(),outFileName.c_str());
		int width, height, comp;
		unsigned char *data = stbi_load(textureFileName.c_str(), &width, &height, &comp	, 0);
		stbi_write_png(outFileName.c_str(), width, height, comp, data, width*comp);
		stbi_image_free(data);

		textureFileName = outFileName;
		return;
	
	}

	// check if jpg exists
	textureFileName=baseName;
	if (ext)  // erase ext 
		textureFileName.erase(textureFileName.size()-strlen(ext),strlen(ext));

	textureFileName+=".jpg";

	if (ExistsFile(textureFileName.c_str()))
		return;

	printf("Texture file not found:'%s'\n",baseName);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2e, %esi
callq 0x3330
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x3400
cmpq $0x0, -0x18(%rbp)
jne 0x21e17
movq -0x10(%rbp), %rdi
leaq 0x89bb(%rip), %rsi      # 0x2a7af
callq 0x3270
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x21d60
testb $0x1, %al
jne 0x21e10
jmp 0x21e15
jmp 0x22139
jmp 0x21e17
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x3400
cmpq $0x0, -0x18(%rbp)
je 0x21e70
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31f0
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq %rax, %rcx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
callq 0x30d0
movq -0x10(%rbp), %rdi
leaq 0x8080(%rip), %rsi      # 0x29efb
callq 0x3270
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x21d60
testb $0x1, %al
jne 0x21e97
jmp 0x21e9c
jmp 0x22139
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x3400
cmpq $0x0, -0x18(%rbp)
je 0x21f01
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31f0
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq %rax, %rcx
movq -0x90(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq %rax, %rdx
callq 0x30d0
movq -0x10(%rbp), %rdi
leaq 0x88a8(%rip), %rsi      # 0x2a7b4
callq 0x3270
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x21d60
testb $0x1, %al
jne 0x21f2b
jmp 0x22093
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x3500
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x92b0
jmp 0x21f5f
leaq -0x39(%rbp), %rdi
callq 0x32e0
cmpq $0x0, -0x18(%rbp)
je 0x21ffe
leaq -0x38(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x31f0
movq %rax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq %rax, %rcx
movq -0xb8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
callq 0x30d0
jmp 0x21fc8
jmp 0x21ffe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x32e0
jmp 0x22142
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3180
jmp 0x22142
leaq 0x7ef6(%rip), %rsi      # 0x29efb
leaq -0x38(%rbp), %rdi
callq 0x3270
jmp 0x22010
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
leaq -0x50(%rbp), %rsi
leaq -0x54(%rbp), %rdx
leaq -0x58(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3900
movq %rax, -0xc0(%rbp)
jmp 0x22039
movq -0xc0(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
movl -0x50(%rbp), %esi
movl -0x54(%rbp), %edx
movl -0x58(%rbp), %ecx
movq -0x60(%rbp), %r8
movl %esi, %r9d
imull %ecx, %r9d
callq 0x6a00
jmp 0x2206b
movq -0x60(%rbp), %rdi
callq 0x38c0
jmp 0x22076
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3050
jmp 0x22085
leaq -0x38(%rbp), %rdi
callq 0x3180
jmp 0x22139
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x3400
cmpq $0x0, -0x18(%rbp)
je 0x220fe
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31f0
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq %rax, %rcx
movq -0xd8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3150
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq %rax, %rdx
callq 0x30d0
movq -0x10(%rbp), %rdi
leaq 0x86a6(%rip), %rsi      # 0x2a7af
callq 0x3270
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x21d60
testb $0x1, %al
jne 0x22125
jmp 0x22127
jmp 0x22139
movq -0x8(%rbp), %rsi
leaq 0x8687(%rip), %rdi      # 0x2a7b9
movb $0x0, %al
callq 0x3060
addq $0xe0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x34f0
nopl (%rax,%rax)