// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x10088, %rsp          # imm = 0x10088
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x555a
testq %r14, %r14
je 0x83a9
cmpb $0x1, 0x6f64(%rip)      # 0xf260
jne 0x832f
movq 0x6cd3(%rip), %rdi      # 0xefd8
leaq 0x19da(%rip), %rsi      # 0x9ce6
callq 0x2190
movq 0x6f40(%rip), %rsi      # 0xf258
movq %rax, %rdi
callq 0x2190
leaq 0x189f(%rip), %rsi      # 0x9bc6
movq %rax, %rdi
callq 0x2190
movq %r14, %rdi
callq 0x685e
movl %eax, %ebp
movq %r14, %rdi
callq 0x6862
imull %ebp, %eax
leaq (,%rax,4), %rcx
testl %eax, %eax
pushq $-0x1
popq %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, %r15
movq %r14, %rdi
callq 0x6c0e
movq %r14, %rdi
movq %r15, %rsi
callq 0x691e
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x5a8a
movq %r15, %rdi
callq 0x2230
cmpb $0x1, 0x6ed4(%rip)      # 0xf260
jne 0x83a9
movq 0x6c43(%rip), %rdi      # 0xefd8
leaq 0x18e4(%rip), %rsi      # 0x9c80
callq 0x2190
movq %rax, %rdi
callq 0x20d0
movl 0x6e99(%rip), %esi      # 0xf248
movq %rbx, %rdi
callq 0x2acc
movq %rax, %rbx
cmpb $0x1, 0x6e9f(%rip)      # 0xf260
jne 0x8436
movq 0x6c0e(%rip), %rdi      # 0xefd8
leaq 0x1934(%rip), %rsi      # 0x9d05
callq 0x2190
movq 0x6e63(%rip), %rsi      # 0xf240
movq %rax, %rdi
callq 0x2190
leaq 0x1939(%rip), %rsi      # 0x9d25
movq %rax, %rdi
callq 0x2190
movl 0x6e4e(%rip), %esi      # 0xf248
movq %rax, %rdi
callq 0x2300
leaq 0x1857(%rip), %rsi      # 0x9c60
movq %rax, %rdi
callq 0x2190
movq %rax, %r14
movq %rbx, %rdi
callq 0x3264
movq %r14, %rdi
movq %rax, %rsi
callq 0x2190
leaq 0x1918(%rip), %rsi      # 0x9d46
movq %rax, %rdi
callq 0x2190
movss 0x6e26(%rip), %xmm0     # 0xf264
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x8448
jnp 0x84bd
cmpb $0x1, 0x6e11(%rip)      # 0xf260
jne 0x848b
movq 0x6b80(%rip), %rdi      # 0xefd8
leaq 0x18d0(%rip), %rsi      # 0x9d2f
callq 0x2190
movss 0x6df8(%rip), %xmm0     # 0xf264
movq %rax, %rdi
callq 0x2120
leaq 0x18ca(%rip), %rsi      # 0x9d45
movq %rax, %rdi
callq 0x2190
movss 0x6dd9(%rip), %xmm0     # 0xf264
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jbe 0x84ae
movq 0x6b3e(%rip), %rdi      # 0xefd8
leaq 0x18a9(%rip), %rsi      # 0x9d4a
callq 0x2190
movss 0x6db6(%rip), %xmm0     # 0xf264
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x5676
jmp 0x84ca
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x5668
movb 0x6d90(%rip), %al       # 0xf260
cmpb $0x1, %al
jne 0x84f5
movq 0x6afd(%rip), %rdi      # 0xefd8
leaq 0x179e(%rip), %rsi      # 0x9c80
callq 0x2190
movq %rax, %rdi
callq 0x20d0
movb 0x6d6b(%rip), %al       # 0xf260
testb $0x1, %al
je 0x852a
movq 0x6ad8(%rip), %rdi      # 0xefd8
leaq 0x186d(%rip), %rsi      # 0x9d74
callq 0x2190
movq 0x6d3d(%rip), %rsi      # 0xf250
movq %rax, %rdi
callq 0x2190
leaq 0x16a4(%rip), %rsi      # 0x9bc6
movq %rax, %rdi
callq 0x2190
movq 0x6d1f(%rip), %rsi      # 0xf250
leaq 0x20(%rsp), %rdi
callq 0x6168
cmpb $0x1, 0x6d1e(%rip)      # 0xf260
jne 0x855f
movq 0x6a8d(%rip), %rdi      # 0xefd8
leaq 0x172e(%rip), %rsi      # 0x9c80
callq 0x2190
movq %rax, %rdi
callq 0x20d0
leaq 0x20(%rsp), %rdi
callq 0x5d36
addq $0x10088, %rsp          # imm = 0x10088
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8600
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8603
movq %rbx, %rdi
callq 0x2210
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x763a
movq %rbx, %rdi
callq 0x20a0
movq 0x6a30(%rip), %rdi      # 0xefd8
leaq 0x17dc(%rip), %rsi      # 0x9d8b
callq 0x2190
movq 0x6c95(%rip), %rsi      # 0xf250
movq %rax, %rdi
callq 0x2190
leaq 0x1713(%rip), %rsi      # 0x9cdd
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rdi
callq 0x21f0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x7654
callq 0x22e0
jmp 0x8603
movq %rax, %rdi
callq 0x398a
jmp 0x8600
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5d36
movq %rbx, %rdi
callq 0x2320