// File: /workspace/github_cpp_makefile_star2_O3/ticky[P]ps2iconsys/src/obj_to_ps2icon.cpp
// Function: WriteOutputFile(OBJ_FileLoader const*, GhulbusUtil::gbImageLoader*)
void WriteOutputFile(OBJ_FileLoader const* obj_file, GhulbusUtil::gbImageLoader* img_loader)
{
	PS2Icon ps2_icon;
	if(img_loader) {
		if(verbose_output)
			std::cout << " * Copying texture data from \"" << texture_input_file << "\"...";
		unsigned int* tmp = new unsigned int[img_loader->GetWidth() * img_loader->GetHeight()];
		img_loader->FlipV();
		img_loader->GetImageData32(tmp);
		ps2_icon.SetTextureData(tmp);
		delete[] tmp;
		if(verbose_output)
			std::cout << "done." << std::endl;
	}
	OBJ_Mesh const* tmp = obj_file->GetMesh(obj_mesh_index);
	if(verbose_output)
		std::cout << " * Copying geometry data from \"" << obj_input_file << "\": Mesh #" << obj_mesh_index
			<< " - " << tmp->GetName() << "...";
	if(obj_scale_factor != 0.0f) {
		if(verbose_output)
			std::cout << "\n    Scale factor is " << obj_scale_factor << " ...";
		if(obj_scale_factor < 0.0f) {
			std::cout << "\n!WARNING! Scale factor is negative.\n    ";
		}
		ps2_icon.SetGeometry(*tmp, obj_scale_factor);
	} else {
		ps2_icon.SetGeometry(*tmp);
	}
	if(verbose_output)
		std::cout << "done." << std::endl;
	
	if(verbose_output)
		std::cout << " * Writing output to \"" << ps2_output_file << "\"...";
	try {
		ps2_icon.WriteFile(ps2_output_file);
	} catch(Ghulbus::gbException e) {
		std::cout << "\nError while writing to \"" << ps2_output_file << "\"" << std::endl;
		exit(1);
	}
	if(verbose_output)
		std::cout << "done." << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10080, %rsp          # imm = 0x10080
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %rdi
callq 0x5faa
testq %r14, %r14
je 0x95eb
cmpb $0x1, 0x5db3(%rip)      # 0xf280
jne 0x9542
movq 0x5b02(%rip), %r15      # 0xefd8
leaq 0x1809(%rip), %rsi      # 0xace6
movl $0x1e, %edx
movq %r15, %rdi
callq 0x21f0
movq 0x5d87(%rip), %r12      # 0xf278
testq %r12, %r12
je 0x9512
movq %r12, %rdi
callq 0x20c0
movq 0x5ad3(%rip), %rdi      # 0xefd8
movq %r12, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x952a
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x5aa7(%rip), %rdi      # 0xefd8
leaq 0x168e(%rip), %rsi      # 0xabc6
movl $0x4, %edx
callq 0x21f0
movq %r14, %rdi
callq 0x749e
movl %eax, %ebp
movq %r14, %rdi
callq 0x74a2
imull %ebp, %eax
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, %r15
movq %r14, %rdi
callq 0x78e8
movq %r14, %rdi
movq %r15, %rsi
callq 0x7562
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x6536
movq %r15, %rdi
callq 0x2250
cmpb $0x1, 0x5cdd(%rip)      # 0xf280
jne 0x95eb
movq 0x5a2c(%rip), %r14      # 0xefd8
leaq 0x16cd(%rip), %rsi      # 0xac80
movl $0x5, %edx
movq %r14, %rdi
callq 0x21f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x59fa(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movl 0x5c77(%rip), %esi      # 0xf268
movq %rbx, %rdi
callq 0x2dc6
movq %rax, %rbx
cmpb $0x1, 0x5c7d(%rip)      # 0xf280
jne 0x96fb
movq 0x59c8(%rip), %r14      # 0xefd8
leaq 0x16ee(%rip), %rsi      # 0xad05
movl $0x1f, %edx
movq %r14, %rdi
callq 0x21f0
movq 0x5c35(%rip), %r15      # 0xf260
testq %r15, %r15
je 0x964c
movq %r15, %rdi
callq 0x20c0
movq 0x5999(%rip), %rdi      # 0xefd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x9664
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x596d(%rip), %rdi      # 0xefd8
leaq 0x16b3(%rip), %rsi      # 0xad25
movl $0x9, %edx
callq 0x21f0
movl 0x5be6(%rip), %esi      # 0xf268
movq 0x594f(%rip), %rdi      # 0xefd8
callq 0x2330
movq %rax, %r14
leaq 0x15c8(%rip), %rsi      # 0xac60
movl $0x3, %edx
movq %rax, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x3a00
movq %rax, %r15
testq %rax, %rax
je 0x96cd
movq %r15, %rdi
callq 0x20c0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x96e7
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2310
leaq 0x1658(%rip), %rsi      # 0xad46
movl $0x3, %edx
movq %r14, %rdi
callq 0x21f0
movss 0x5b81(%rip), %xmm0     # 0xf284
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x9711
jnp 0x979c
cmpb $0x1, 0x5b68(%rip)      # 0xf280
jne 0x9765
movq 0x58b7(%rip), %rdi      # 0xefd8
leaq 0x1607(%rip), %rsi      # 0xad2f
movl $0x15, %edx
callq 0x21f0
xorps %xmm0, %xmm0
cvtss2sd 0x5b47(%rip), %xmm0     # 0xf284
movq 0x5894(%rip), %rdi      # 0xefd8
callq 0x22e0
leaq 0x15f5(%rip), %rsi      # 0xad45
movl $0x4, %edx
movq %rax, %rdi
callq 0x21f0
movss 0x5b1f(%rip), %xmm0     # 0xf284
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x978d
movq 0x5864(%rip), %rdi      # 0xefd8
leaq 0x15cf(%rip), %rsi      # 0xad4a
movl $0x29, %edx
callq 0x21f0
movss 0x5af7(%rip), %xmm0     # 0xf284
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x60d6
jmp 0x97a9
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x60c8
movb 0x5ad1(%rip), %al       # 0xf280
cmpb $0x1, %al
jne 0x97ff
movq 0x581e(%rip), %rbx      # 0xefd8
leaq 0x14bf(%rip), %rsi      # 0xac80
movl $0x5, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x57ec(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movb 0x5a81(%rip), %al       # 0xf280
testb $0x1, %al
je 0x9875
movq 0x57ce(%rip), %rbx      # 0xefd8
leaq 0x1563(%rip), %rsi      # 0xad74
movl $0x16, %edx
movq %rbx, %rdi
callq 0x21f0
movq 0x5a4b(%rip), %r14      # 0xf270
testq %r14, %r14
je 0x9846
movq %r14, %rdi
callq 0x20c0
movq 0x579f(%rip), %rdi      # 0xefd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x985d
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x5774(%rip), %rdi      # 0xefd8
leaq 0x135b(%rip), %rsi      # 0xabc6
movl $0x4, %edx
callq 0x21f0
movq 0x59f4(%rip), %rsi      # 0xf270
leaq 0x18(%rsp), %rdi
callq 0x6cb6
cmpb $0x1, 0x59f3(%rip)      # 0xf280
jne 0x98d5
movq 0x5742(%rip), %rbx      # 0xefd8
leaq 0x13e3(%rip), %rsi      # 0xac80
movl $0x5, %edx
movq %rbx, %rdi
callq 0x21f0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x5710(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x18(%rsp), %rdi
callq 0x6824
addq $0x10080, %rsp          # imm = 0x10080
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x998b
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x998e
movq %rbx, %rdi
callq 0x2230
movq %rsp, %rdi
movq %rax, %rsi
callq 0x8342
movq %rbx, %rdi
callq 0x20b0
movq 0x56b6(%rip), %rdi      # 0xefd8
leaq 0x1462(%rip), %rsi      # 0xad8b
movl $0x19, %edx
callq 0x21f0
movq 0x5936(%rip), %rsi      # 0xf270
movq 0x5697(%rip), %rdi      # 0xefd8
callq 0x21b0
movq %rax, %rbx
leaq 0x138d(%rip), %rsi      # 0xacdd
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x20d0
movl $0x1, %edi
callq 0x2210
movq %rax, %rbx
movq %rsp, %rdi
callq 0x835c
callq 0x2300
jmp 0x998e
movq %rax, %rdi
callq 0x7088
jmp 0x998b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6824
movq %rbx, %rdi
callq 0x2350