// File: /workspace/github_cpp_makefile_star2_O3/ticky[P]ps2iconsys/gbLib/src/gbImageLoader_BMP.cpp
// Function: GhulbusUtil::gbImageType_BMP_T::ReadFile(std::basic_ifstream<char, std::char_traits<char>>&, int*, int*, int*, unsigned char**, unsigned int**)
void gbImageType_BMP_T::ReadFile(std::ifstream& file, int* width, int* height, int* bpp, 
		                           unsigned char** pp_data, unsigned int** pp_palette) 
	{
		BITMAPFILEHEADER fheader;
		BITMAPINFOHEADER iheader;
		file.seekg(m_file_offset, ::std::ios::beg);
		file.read( reinterpret_cast<char*>(&fheader), sizeof(BITMAPFILEHEADER) );
		file.read( reinterpret_cast<char*>(&iheader), sizeof(BITMAPINFOHEADER));

		if(iheader.biClrUsed || (iheader.biHeight < 0)) { 
			throw( Ghulbus::gbException( Ghulbus::gbException::GB_NOTIMPLEMENTED ) );
		}

		unsigned int* palette = NULL;
		unsigned char* data = new unsigned char[iheader.biWidth*iheader.biHeight*((iheader.biBitCount >= 8)?(iheader.biBitCount>>3):1)];

		try {
			switch(iheader.biBitCount)
			{
			case 1:
				ReadData1Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			case 4:
				ReadData4Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			case 8:
				ReadData8Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			case 16:
				ReadData16Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			case 24:
				ReadData24Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			case 32:
				ReadData32Bit(file, iheader, fheader, data, &palette, m_file_offset);
				break;
			default:
				throw( Ghulbus::gbException( Ghulbus::gbException::GB_FAILED,
											 "Illegal bit depth in BMP image file") );
			}
		} catch(Ghulbus::gbException) {
			if(data)    { delete[] data; }
			if(palette) { delete[] palette; }
			throw;
		}

		FlipImageVertical(iheader, data);

		*width      = iheader.biWidth;
		*height     = iheader.biHeight;
		*bpp        = iheader.biBitCount;
		*pp_data    = data;
		*pp_palette = palette;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %r12
movq %r8, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
leaq 0x52(%rsp), %rsi
movl $0xe, %edx
movq %r14, %rdi
callq 0x2240
leaq 0x8(%rsp), %rbx
movl $0x28, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2240
cmpl $0x0, 0x20(%rbx)
jne 0x8226
movl 0x10(%rsp), %eax
testl %eax, %eax
js 0x8226
imull 0xc(%rsp), %eax
movzwl 0x16(%rsp), %ebx
movl %ebx, %ecx
shrl $0x3, %ecx
cmpl $0x8, %ebx
movl $0x1, %edx
cmovael %ecx, %edx
imull %eax, %edx
movslq %edx, %rdi
callq 0x2030
movq %rax, %r13
cmpl $0xf, %ebx
movq %rax, 0x38(%rsp)
movq %r12, 0x60(%rsp)
jg 0x7e16
cmpl $0x1, %ebx
je 0x7e5d
cmpl $0x4, %ebx
je 0x7f6c
cmpl $0x8, %ebx
jne 0x828d
cmpl $0x0, 0x18(%rsp)
jne 0x825b
movl 0x8(%r15), %r12d
xorl %ebp, %ebp
movl $0x400, %edi            # imm = 0x400
callq 0x2030
movq %rax, %rbx
movl $0x400, %edx            # imm = 0x400
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2240
addl 0x5c(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movslq 0xc(%rsp), %rax
movslq 0x10(%rsp), %rdx
imulq %rax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
jmp 0x812a
cmpl $0x18, %ebx
je 0x8012
cmpl $0x20, %ebx
jne 0x8256
movl 0x8(%r15), %r15d
movl 0x18(%rsp), %eax
cmpl $0x3, %eax
je 0x805e
testl %eax, %eax
jne 0x825b
movabsq $0xff0000ff0000, %rax   # imm = 0xFF0000FF0000
movq %rax, 0x44(%rsp)
movl $0xff, 0x4c(%rsp)
jmp 0x8072
cmpl $0x0, 0x18(%rsp)
jne 0x825b
movl 0x8(%r15), %r12d
xorl %ebp, %ebp
movl $0x8, %edi
callq 0x2030
movq %rax, %rbx
movl $0x8, %edx
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2240
addl 0x5c(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movl 0x10(%rsp), %eax
imull 0xc(%rsp), %eax
sarl $0x3, %eax
movslq %eax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
movl %ecx, %edx
imull %eax, %edx
cmpl $0x8, %edx
jl 0x8054
decl %edx
movl %edx, %eax
shrl $0x3, %eax
movb (%r13,%rax), %cl
andb $0x1, %cl
movb %cl, (%r13,%rdx)
movb (%r13,%rax), %cl
shrb %cl
andb $0x1, %cl
movb %cl, -0x1(%r13,%rdx)
movb (%r13,%rax), %cl
shrb $0x2, %cl
andb $0x1, %cl
movb %cl, -0x2(%r13,%rdx)
movb (%r13,%rax), %cl
shrb $0x3, %cl
andb $0x1, %cl
movb %cl, -0x3(%r13,%rdx)
movb (%r13,%rax), %cl
shrb $0x4, %cl
andb $0x1, %cl
movb %cl, -0x4(%r13,%rdx)
movb (%r13,%rax), %cl
shrb $0x5, %cl
andb $0x1, %cl
movb %cl, -0x5(%r13,%rdx)
movb (%r13,%rax), %cl
shrb $0x6, %cl
andb $0x1, %cl
movb %cl, -0x6(%r13,%rdx)
movb (%r13,%rax), %al
shrb $0x7, %al
movb %al, -0x7(%r13,%rdx)
leaq -0x8(%rdx), %rax
cmpq $0xe, %rdx
movq %rax, %rdx
ja 0x7ed8
jmp 0x812a
cmpl $0x0, 0x18(%rsp)
jne 0x825b
movl 0x8(%r15), %r12d
xorl %ebp, %ebp
movl $0x40, %edi
callq 0x2030
movq %rax, %rbx
movl $0x40, %edx
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2240
addl 0x5c(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movl 0x10(%rsp), %eax
imull 0xc(%rsp), %eax
sarl %eax
movslq %eax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
movl %ecx, %edx
imull %eax, %edx
cmpl $0x2, %edx
jl 0x8054
decl %edx
movl %edx, %eax
shrl %eax
movb (%r13,%rax), %cl
andb $0xf, %cl
movb %cl, (%r13,%rdx)
movb (%r13,%rax), %al
shrb $0x4, %al
movb %al, -0x1(%r13,%rdx)
leaq -0x2(%rdx), %rax
cmpq $0x2, %rdx
movq %rax, %rdx
ja 0x7fe2
jmp 0x812a
cmpl $0x0, 0x18(%rsp)
jne 0x825b
movl 0x8(%r15), %esi
addl 0x5c(%rsp), %esi
xorl %ebp, %ebp
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
movl 0xc(%rsp), %eax
imull 0x10(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
xorl %ebx, %ebx
jmp 0x812a
movq %rbx, 0x30(%rsp)
jmp 0x8137
xorl %ebp, %ebp
leaq 0x44(%rsp), %rsi
movl $0xc, %edx
movq %r14, %rdi
callq 0x2240
addl 0x5c(%rsp), %r15d
xorl %ebp, %ebp
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2270
movl 0xc(%rsp), %eax
imull 0x10(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0x10(%rsp), %eax
imull 0xc(%rsp), %eax
testl %eax, %eax
jle 0x8128
movl 0x44(%rsp), %edi
movl 0x48(%rsp), %r8d
movl %edi, %r9d
shrl $0x8, %r9d
incl %r9d
movl %r8d, %r10d
shrl $0x8, %r10d
incl %r10d
movl 0x4c(%rsp), %r11d
movl %r11d, %ebp
shrl $0x8, %ebp
incl %ebp
movl %eax, %r14d
xorl %r15d, %r15d
movl $0xff, %r12d
movl (%r13,%r15,4), %ecx
movl %ecx, %eax
andl %edi, %eax
xorl %edx, %edx
divl %r9d
movl %eax, %esi
andl %r12d, %esi
shll $0x10, %esi
movl %ecx, %eax
andl %r8d, %eax
xorl %edx, %edx
divl %r10d
shll $0x8, %eax
movzwl %ax, %ebx
orl %esi, %ebx
andl %r11d, %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %ebp
andl %r12d, %eax
orl %ebx, %eax
movl %eax, (%r13,%r15,4)
incq %r15
cmpq %r15, %r14
jne 0x80e5
xorl %ebx, %ebx
movq %rbx, 0x30(%rsp)
movl 0xc(%rsp), %eax
movl 0x10(%rsp), %ecx
movzwl 0x16(%rsp), %edx
movl %edx, 0x4(%rsp)
cmpl $0x2, %ecx
jl 0x81de
movl 0x4(%rsp), %esi
movl %esi, %edx
shrl $0x3, %edx
cmpw $0x8, %si
movl $0x1, %edi
cmovael %edx, %edi
movl %ecx, %r8d
shrl %r8d
movl %ecx, %edx
movslq %eax, %r9
movl %r9d, %r10d
imulq %rdi, %r9
decq %rdx
imulq %r9, %rdx
movq 0x38(%rsp), %r13
movq %r13, %rbx
addq %rdx, %rbx
movq %r9, %r14
negq %r14
xorl %r12d, %r12d
testl %eax, %eax
jle 0x81d0
movq %rbx, %r11
movq %r13, %rbp
xorl %edx, %edx
testq %rdi, %rdi
je 0x81c2
xorl %r15d, %r15d
movb (%rbp,%r15), %sil
xorb (%r11,%r15), %sil
movb %sil, (%rbp,%r15)
xorb (%r11,%r15), %sil
movb %sil, (%r11,%r15)
xorb %sil, (%rbp,%r15)
incq %r15
cmpq %r15, %rdi
jne 0x819f
incq %rdx
addq %rdi, %rbp
addq %rdi, %r11
cmpq %r10, %rdx
jne 0x8197
incq %r12
addq %r9, %r13
addq %r14, %rbx
cmpq %r8, %r12
jne 0x818b
movq 0x68(%rsp), %rdx
movl %eax, (%rdx)
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
movq 0x78(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movq 0x60(%rsp), %rcx
movq %rax, (%rcx)
movq 0x30(%rsp), %rax
movq 0xd0(%rsp), %rcx
movq %rax, (%rcx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x18, %edi
callq 0x20e0
movq %rax, %rbx
movq %rax, %rdi
movl $0x5, %esi
callq 0x831a
leaq 0x6b49(%rip), %rsi      # 0xed90
leaq 0x10e(%rip), %rdx       # 0x835c
movq %rbx, %rdi
callq 0x2320
cmpl $0x10, %ebx
jne 0x828d
movl $0x18, %edi
callq 0x20e0
movq %rax, %r14
movq %rax, %rdi
movl $0x5, %esi
callq 0x831a
xorl %ebp, %ebp
leaq 0x6b12(%rip), %rsi      # 0xed90
leaq 0xd7(%rip), %rdx        # 0x835c
movq %r14, %rdi
callq 0x2320
movl $0x18, %edi
callq 0x20e0
movq %rax, %r14
leaq 0x2273(%rip), %rdx      # 0xa514
movq %rax, %rdi
movl $0x1, %esi
callq 0x8330
jmp 0x8275
movq %rax, %r14
cmpl $0x1, %edx
jne 0x82ef
leaq 0x80(%rsp), %rax
movq %r14, %rdi
movl %edx, %esi
movq %rax, %rdx
movq 0x38(%rsp), %rcx
movq %rbp, %r8
callq 0x2555
callq 0x22a0
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x835c
callq 0x2300
movq %r14, %rdi
callq 0x2350
movq %rax, %rdi
callq 0x7088
nop