// File: /workspace/github_cpp_makefile_star2_O2/ticky[P]ps2iconsys/src/ps2icon_to_obj.cpp
// Function: WriteTextureFile(PS2Icon*)
void WriteTextureFile(PS2Icon* ps2_icon)
{
	unsigned int texture_data[128*128];
	if(verbose_output)
		std::cout << " * Convert texture data from \"" << ps2_input_file << "\"..." ;
	ps2_icon->GetTextureData(texture_data);
	//manual conversion required, since WriteImage() requires 
	// GBCOLOR32 data, whose bit pattern is not fix;
	for(int i=0; i<16384; i++) {
		texture_data[i] = GhulbusGraphics::GBCOLOR32::ARGB( static_cast<int>((texture_data[i] >> 24) & 0xff),
															static_cast<int>((texture_data[i] >> 16) & 0xff),
															static_cast<int>((texture_data[i] >>  8) & 0xff),
															static_cast<int>((texture_data[i])       & 0xff) );
	}
	//in addition the texture is flipped horizontally:
	for(int row=0; row<64; row++) {
		for(int i=0; i<128; i++) {
			texture_data[row*128 + i] ^= texture_data[(127-row)*128 + i] 
				^= texture_data[row*128 + i] ^= texture_data[(127-row)*128 + i];
		}
	}

	if(verbose_output)
		std::cout << "done." << std::endl;

	if(verbose_output)
		std::cout << " * Writing texture to file \"" << texture_output_file << "\"...";
	try {
		GhulbusUtil::WriteImage(texture_output_file, texture_data, 128, 128);
	} catch( Ghulbus::gbException e ) {
		std::cout << "\nError while writing to \"" << texture_output_file << "\"" << std::endl;
		exit(1);
	}
	if(verbose_output)
		std::cout << "done." << std::endl;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x10028, %rsp          # imm = 0x10028
movq %rdi, %r14
cmpb $0x1, 0x639a(%rip)      # 0xe248
jne 0x7ee1
movq 0x6121(%rip), %rdi      # 0xdfd8
leaq 0x1c49(%rip), %rsi      # 0x9b07
callq 0x2180
movq 0x6366(%rip), %rsi      # 0xe230
movq %rax, %rdi
callq 0x2180
leaq 0x1bea(%rip), %rsi      # 0x9ac3
movq %rax, %rdi
callq 0x2180
leaq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x605a
leaq 0xfe20(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0x7f35
xorl %edx, %edx
cmpq $0x80, %rdx
je 0x7f23
movl (%rbx,%rdx,4), %esi
xorl (%rax,%rdx,4), %esi
movl %esi, (%rbx,%rdx,4)
xorl (%rax,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
xorl %esi, (%rbx,%rdx,4)
incq %rdx
jmp 0x7f03
incq %rcx
addq $-0x200, %rax           # imm = 0xFE00
addq $0x200, %rbx            # imm = 0x200
jmp 0x7efb
movb 0x630d(%rip), %al       # 0xe248
testb %al, %al
je 0x7f60
movq 0x6092(%rip), %rdi      # 0xdfd8
leaq 0x1b50(%rip), %rsi      # 0x9a9d
callq 0x2180
movq %rax, %rdi
callq 0x20d0
movb 0x62e8(%rip), %al       # 0xe248
testb $0x1, %al
je 0x7f95
movq 0x606d(%rip), %rdi      # 0xdfd8
leaq 0x1bb4(%rip), %rsi      # 0x9b26
callq 0x2180
movq 0x62c2(%rip), %rsi      # 0xe240
movq %rax, %rdi
callq 0x2180
leaq 0x1b36(%rip), %rsi      # 0x9ac3
movq %rax, %rdi
callq 0x2180
movq 0x62a4(%rip), %rdi      # 0xe240
leaq 0x20(%rsp), %rsi
movl $0x80, %edx
movl $0x80, %ecx
callq 0x6a52
cmpb $0x1, 0x6291(%rip)      # 0xe248
jne 0x7fd4
movq 0x6018(%rip), %rdi      # 0xdfd8
leaq 0x1ad6(%rip), %rsi      # 0x9a9d
callq 0x2180
movq %rax, %rdi
callq 0x20d0
addq $0x10028, %rsp          # imm = 0x10028
popq %rbx
popq %r14
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x8057
movq %rbx, %rdi
callq 0x21f0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x760a
movq %rbx, %rdi
callq 0x20a0
movq 0x5fcd(%rip), %rdi      # 0xdfd8
leaq 0x1adb(%rip), %rsi      # 0x9aed
callq 0x2180
movq 0x6222(%rip), %rsi      # 0xe240
movq %rax, %rdi
callq 0x2180
leaq 0x1a1d(%rip), %rsi      # 0x9a4a
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rdi
callq 0x21e0
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x7624
callq 0x22b0
movq %rbx, %rdi
callq 0x22f0
movq %rax, %rdi
callq 0x395a