// File: /workspace/github_cpp_makefile_star2_O1/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 0x614e
testq %r14, %r14
je 0x97fe
cmpb $0x1, 0x5ba2(%rip)      # 0xf280
jne 0x9753
movq 0x58f1(%rip), %r15      # 0xefd8
leaq 0x15bd(%rip), %rsi      # 0xacab
movl $0x1e, %edx
movq %r15, %rdi
callq 0x21f0
movq 0x5b76(%rip), %r12      # 0xf278
testq %r12, %r12
je 0x9723
movq %r12, %rdi
callq 0x20c0
movq 0x58c2(%rip), %rdi      # 0xefd8
movq %r12, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x973b
movq (%r15), %rax
movq -0x18(%rax), %rax
leaq (%r15,%rax), %rdi
movl 0x20(%r15,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x5896(%rip), %rdi      # 0xefd8
leaq 0x1442(%rip), %rsi      # 0xab8b
movl $0x4, %edx
callq 0x21f0
movq %r14, %rdi
callq 0x779a
movl %eax, %ebp
movq %r14, %rdi
callq 0x779e
imull %ebp, %eax
cltq
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, %r15
movq %r14, %rdi
callq 0x7bee
movq %r14, %rdi
movq %r15, %rsi
callq 0x785e
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x672c
movq %r15, %rdi
callq 0x2250
cmpb $0x1, 0x5aca(%rip)      # 0xf280
jne 0x97fe
movq 0x5819(%rip), %r14      # 0xefd8
leaq 0x147f(%rip), %rsi      # 0xac45
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 0x57e7(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
movl 0x5a64(%rip), %esi      # 0xf268
movq %rbx, %rdi
callq 0x2d48
movq %rax, %rbx
cmpb $0x1, 0x5a6a(%rip)      # 0xf280
jne 0x990e
movq 0x57b5(%rip), %r14      # 0xefd8
leaq 0x14a0(%rip), %rsi      # 0xacca
movl $0x1f, %edx
movq %r14, %rdi
callq 0x21f0
movq 0x5a22(%rip), %r15      # 0xf260
testq %r15, %r15
je 0x985f
movq %r15, %rdi
callq 0x20c0
movq 0x5786(%rip), %rdi      # 0xefd8
movq %r15, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x9877
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x575a(%rip), %rdi      # 0xefd8
leaq 0x1465(%rip), %rsi      # 0xacea
movl $0x9, %edx
callq 0x21f0
movl 0x59d3(%rip), %esi      # 0xf268
movq 0x573c(%rip), %rdi      # 0xefd8
callq 0x2330
movq %rax, %r14
leaq 0x137a(%rip), %rsi      # 0xac25
movl $0x3, %edx
movq %rax, %rdi
callq 0x21f0
movq %rbx, %rdi
callq 0x3982
movq %rax, %r15
testq %rax, %rax
je 0x98e0
movq %r15, %rdi
callq 0x20c0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x98fa
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2310
leaq 0x140a(%rip), %rsi      # 0xad0b
movl $0x3, %edx
movq %r14, %rdi
callq 0x21f0
movss 0x596e(%rip), %xmm0     # 0xf284
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x9924
jnp 0x99ab
cmpb $0x1, 0x5955(%rip)      # 0xf280
jne 0x9970
movq 0x56a4(%rip), %rdi      # 0xefd8
leaq 0x13b9(%rip), %rsi      # 0xacf4
movl $0x15, %edx
callq 0x21f0
xorps %xmm0, %xmm0
cvtss2sd 0x5934(%rip), %xmm0     # 0xf284
movq 0x5681(%rip), %rdi      # 0xefd8
callq 0x22e0
leaq 0x13a7(%rip), %rsi      # 0xad0a
movl $0x4, %edx
movq %rax, %rdi
callq 0x21f0
xorps %xmm0, %xmm0
ucomiss 0x590a(%rip), %xmm0     # 0xf284
jbe 0x9994
movq 0x5655(%rip), %rdi      # 0xefd8
leaq 0x1385(%rip), %rsi      # 0xad0f
movl $0x29, %edx
callq 0x21f0
movss 0x58e8(%rip), %xmm0     # 0xf284
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x627a
jmp 0x99b8
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x626c
cmpb $0x1, 0x58c1(%rip)      # 0xf280
jne 0x9a07
movq 0x5610(%rip), %rbx      # 0xefd8
leaq 0x1276(%rip), %rsi      # 0xac45
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 0x55de(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
cmpb $0x1, 0x5872(%rip)      # 0xf280
jne 0x9a82
movq 0x55c1(%rip), %rbx      # 0xefd8
leaq 0x131b(%rip), %rsi      # 0xad39
movl $0x16, %edx
movq %rbx, %rdi
callq 0x21f0
movq 0x583e(%rip), %r14      # 0xf270
testq %r14, %r14
je 0x9a53
movq %r14, %rdi
callq 0x20c0
movq 0x5592(%rip), %rdi      # 0xefd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x21f0
jmp 0x9a6a
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2310
movq 0x5567(%rip), %rdi      # 0xefd8
leaq 0x1113(%rip), %rsi      # 0xab8b
movl $0x4, %edx
callq 0x21f0
movq 0x57e7(%rip), %rsi      # 0xf270
leaq 0x18(%rsp), %rdi
callq 0x6eb8
cmpb $0x1, 0x57e6(%rip)      # 0xf280
jne 0x9ae2
movq 0x5535(%rip), %rbx      # 0xefd8
leaq 0x119b(%rip), %rsi      # 0xac45
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 0x5503(%rip), %rdi      # 0xefd8
callq 0x2040
movq %rax, %rdi
callq 0x2120
leaq 0x18(%rsp), %rdi
callq 0x6a1a
addq $0x10080, %rsp          # imm = 0x10080
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9b98
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x9b9b
movq %rbx, %rdi
callq 0x2230
movq %rsp, %rdi
movq %rax, %rsi
callq 0x860a
movq %rbx, %rdi
callq 0x20b0
movq 0x54a9(%rip), %rdi      # 0xefd8
leaq 0x121a(%rip), %rsi      # 0xad50
movl $0x19, %edx
callq 0x21f0
movq 0x5729(%rip), %rsi      # 0xf270
movq 0x548a(%rip), %rdi      # 0xefd8
callq 0x21b0
movq %rax, %rbx
leaq 0x1145(%rip), %rsi      # 0xaca2
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 0x8624
callq 0x2300
jmp 0x9b9b
movq %rax, %rdi
callq 0x7292
jmp 0x9b98
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x6a1a
movq %rbx, %rdi
callq 0x2350