// File: 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
movq %rsp, %rbp
subq $0x10170, %rsp          # imm = 0x10170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x10078(%rbp), %rdi
callq 0xa780
cmpq $0x0, -0x10(%rbp)
je 0x1051e
testb $0x1, 0x7ed7(%rip)      # 0x18298
je 0x10429
movq 0x7c0e(%rip), %rdi      # 0x17fd8
leaq 0x193c(%rip), %rsi      # 0x11d0d
callq 0x21c0
movq %rax, -0x100b8(%rbp)
jmp 0x103df
movq -0x100b8(%rbp), %rdi
movq 0x7ea3(%rip), %rsi      # 0x18290
callq 0x21c0
movq %rax, -0x100c0(%rbp)
jmp 0x103fb
movq -0x100c0(%rbp), %rdi
leaq 0x17e4(%rip), %rsi      # 0x11bed
callq 0x21c0
jmp 0x10410
jmp 0x10429
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10080(%rbp)
movl %eax, -0x10084(%rbp)
jmp 0x108d9
movq -0x10(%rbp), %rdi
callq 0xd2c0
movl %eax, -0x100c4(%rbp)
jmp 0x1043a
movq -0x10(%rbp), %rdi
callq 0xd2e0
movl %eax, -0x100c8(%rbp)
jmp 0x1044b
movl -0x100c8(%rbp), %ecx
movl -0x100c4(%rbp), %eax
imull %ecx, %eax
cltq
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2040
movq %rax, -0x100d0(%rbp)
jmp 0x10480
movq -0x100d0(%rbp), %rax
movq %rax, -0x10090(%rbp)
movq -0x10(%rbp), %rdi
callq 0xdae0
jmp 0x10499
movq -0x10(%rbp), %rdi
movq -0x10090(%rbp), %rsi
callq 0xd440
jmp 0x104ab
movq -0x10090(%rbp), %rsi
leaq -0x10078(%rbp), %rdi
callq 0xb220
jmp 0x104c0
movq -0x10090(%rbp), %rax
movq %rax, -0x100d8(%rbp)
cmpq $0x0, %rax
je 0x104e0
movq -0x100d8(%rbp), %rdi
callq 0x2270
testb $0x1, 0x7db1(%rip)      # 0x18298
je 0x1051c
movq 0x7ae8(%rip), %rdi      # 0x17fd8
leaq 0x17b0(%rip), %rsi      # 0x11ca7
callq 0x21c0
movq %rax, -0x100e0(%rbp)
jmp 0x10505
movq -0x100e0(%rbp), %rdi
movq 0x7aad(%rip), %rsi      # 0x17fc0
callq 0x21f0
jmp 0x1051a
jmp 0x1051c
jmp 0x1051e
movq -0x8(%rbp), %rdi
movl 0x7d58(%rip), %esi      # 0x18280
callq 0x3020
movq %rax, -0x100e8(%rbp)
jmp 0x10536
movq -0x100e8(%rbp), %rax
movq %rax, -0x10098(%rbp)
testb $0x1, 0x7d4d(%rip)      # 0x18298
je 0x10624
movq 0x7a80(%rip), %rdi      # 0x17fd8
leaq 0x17cd(%rip), %rsi      # 0x11d2c
callq 0x21c0
movq %rax, -0x100f0(%rbp)
jmp 0x1056d
movq -0x100f0(%rbp), %rdi
movq 0x7cfd(%rip), %rsi      # 0x18278
callq 0x21c0
movq %rax, -0x100f8(%rbp)
jmp 0x10589
movq -0x100f8(%rbp), %rdi
leaq 0x17b5(%rip), %rsi      # 0x11d4c
callq 0x21c0
movq %rax, -0x10100(%rbp)
jmp 0x105a5
movq -0x10100(%rbp), %rdi
movl 0x7cce(%rip), %esi      # 0x18280
callq 0x2350
movq %rax, -0x10108(%rbp)
jmp 0x105c0
movq -0x10108(%rbp), %rdi
leaq 0x16b9(%rip), %rsi      # 0x11c87
callq 0x21c0
movq %rax, -0x10110(%rbp)
jmp 0x105dc
movq -0x10098(%rbp), %rdi
callq 0x3f80
movq %rax, -0x10118(%rbp)
jmp 0x105f1
movq -0x10118(%rbp), %rsi
movq -0x10110(%rbp), %rdi
callq 0x21c0
movq %rax, -0x10120(%rbp)
jmp 0x1060d
movq -0x10120(%rbp), %rdi
leaq 0x1752(%rip), %rsi      # 0x11d6d
callq 0x21c0
jmp 0x10622
jmp 0x10624
movss 0x7c70(%rip), %xmm0     # 0x1829c
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x1063b
jp 0x1063b
jmp 0x106d6
testb $0x1, 0x7c56(%rip)      # 0x18298
je 0x10694
movq 0x798d(%rip), %rdi      # 0x17fd8
leaq 0x1704(%rip), %rsi      # 0x11d56
callq 0x21c0
movq %rax, -0x10128(%rbp)
jmp 0x10660
movq -0x10128(%rbp), %rdi
movss 0x7c2d(%rip), %xmm0     # 0x1829c
callq 0x2150
movq %rax, -0x10130(%rbp)
jmp 0x1067d
movq -0x10130(%rbp), %rdi
leaq 0x16e1(%rip), %rsi      # 0x11d6c
callq 0x21c0
jmp 0x10692
jmp 0x10694
xorps %xmm0, %xmm0
ucomiss 0x7bfe(%rip), %xmm0     # 0x1829c
jbe 0x106b7
movq 0x7931(%rip), %rdi      # 0x17fd8
leaq 0x16c3(%rip), %rsi      # 0x11d71
callq 0x21c0
jmp 0x106b5
jmp 0x106b7
movq -0x10098(%rbp), %rsi
movss 0x7bd6(%rip), %xmm0     # 0x1829c
leaq -0x10078(%rbp), %rdi
callq 0xaa70
jmp 0x106d4
jmp 0x106ed
movq -0x10098(%rbp), %rsi
leaq -0x10078(%rbp), %rdi
callq 0xaa40
jmp 0x106eb
jmp 0x106ed
testb $0x1, 0x7ba4(%rip)      # 0x18298
je 0x10729
movq 0x78db(%rip), %rdi      # 0x17fd8
leaq 0x15a3(%rip), %rsi      # 0x11ca7
callq 0x21c0
movq %rax, -0x10138(%rbp)
jmp 0x10712
movq -0x10138(%rbp), %rdi
movq 0x78a0(%rip), %rsi      # 0x17fc0
callq 0x21f0
jmp 0x10727
jmp 0x10729
testb $0x1, 0x7b68(%rip)      # 0x18298
je 0x10781
movq 0x789f(%rip), %rdi      # 0x17fd8
leaq 0x165b(%rip), %rsi      # 0x11d9b
callq 0x21c0
movq %rax, -0x10140(%rbp)
jmp 0x1074e
movq -0x10140(%rbp), %rdi
movq 0x7b2c(%rip), %rsi      # 0x18288
callq 0x21c0
movq %rax, -0x10148(%rbp)
jmp 0x1076a
movq -0x10148(%rbp), %rdi
leaq 0x1475(%rip), %rsi      # 0x11bed
callq 0x21c0
jmp 0x1077f
jmp 0x10781
movq 0x7b00(%rip), %rsi      # 0x18288
leaq -0x10078(%rbp), %rdi
callq 0xbef0
jmp 0x10796
jmp 0x10888
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10080(%rbp)
movl %eax, -0x10084(%rbp)
movl -0x10084(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x108d9
movq -0x10080(%rbp), %rdi
movq %rdi, -0x10158(%rbp)
callq 0x2240
movq %rax, %rsi
leaq -0x100b0(%rbp), %rdi
callq 0xf100
movq -0x10158(%rbp), %rdi
callq 0x20c0
movq 0x77e3(%rip), %rdi      # 0x17fd8
leaq 0x15b6(%rip), %rsi      # 0x11db2
callq 0x21c0
movq %rax, -0x10150(%rbp)
jmp 0x1080a
movq -0x10150(%rbp), %rdi
movq 0x7a70(%rip), %rsi      # 0x18288
callq 0x21c0
movq %rax, -0x10160(%rbp)
jmp 0x10826
movq -0x10160(%rbp), %rdi
leaq 0x14d0(%rip), %rsi      # 0x11d04
callq 0x21c0
movq %rax, -0x10168(%rbp)
jmp 0x10842
movq -0x10168(%rbp), %rdi
movq 0x7770(%rip), %rsi      # 0x17fc0
callq 0x21f0
jmp 0x10857
movl $0x1, %edi
callq 0x2220
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10080(%rbp)
movl %eax, -0x10084(%rbp)
leaq -0x100b0(%rbp), %rdi
callq 0xf150
callq 0x2330
jmp 0x10886
jmp 0x108d9
testb $0x1, 0x7a09(%rip)      # 0x18298
je 0x108c4
movq 0x7740(%rip), %rdi      # 0x17fd8
leaq 0x1408(%rip), %rsi      # 0x11ca7
callq 0x21c0
movq %rax, -0x10170(%rbp)
jmp 0x108ad
movq -0x10170(%rbp), %rdi
movq 0x7705(%rip), %rsi      # 0x17fc0
callq 0x21f0
jmp 0x108c2
jmp 0x108c4
leaq -0x10078(%rbp), %rdi
callq 0xb650
addq $0x10170, %rsp          # imm = 0x10170
popq %rbp
retq
leaq -0x10078(%rbp), %rdi
callq 0xb650
movq -0x10080(%rbp), %rdi
callq 0x2370
movq %rax, %rdi
callq 0x5470
nopl (%rax)