// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %r9, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, %r14
movq %rdi, %r15
movl 0x8(%rdi), %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
leaq 0x3a(%rsp), %rsi
movl $0xe, %edx
movq %r14, %rdi
callq 0x2240
leaq 0x4(%rsp), %rbx
movl $0x28, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2240
cmpl $0x0, 0x20(%rbx)
jne 0x84f6
movl 0xc(%rsp), %eax
testl %eax, %eax
js 0x84f6
imull 0x8(%rsp), %eax
movzwl 0x12(%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
jg 0x80fe
cmpl $0x1, %ebx
je 0x8145
cmpl $0x4, %ebx
je 0x8250
cmpl $0x8, %ebx
jne 0x855d
cmpl $0x0, 0x14(%rsp)
jne 0x852b
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 0x44(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movslq 0x8(%rsp), %rax
movslq 0xc(%rsp), %rdx
imulq %rax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
jmp 0x8404
cmpl $0x18, %ebx
je 0x82f6
cmpl $0x20, %ebx
jne 0x8526
movl 0x8(%r15), %r15d
movl 0x14(%rsp), %eax
cmpl $0x3, %eax
je 0x8338
testl %eax, %eax
jne 0x852b
movabsq $0xff0000ff0000, %rax   # imm = 0xFF0000FF0000
movq %rax, 0x2c(%rsp)
movl $0xff, 0x34(%rsp)
jmp 0x834c
cmpl $0x0, 0x14(%rsp)
jne 0x852b
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 0x44(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
sarl $0x3, %eax
movslq %eax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
cmpl $0x8, %eax
jl 0x8404
decl %eax
movl %eax, %ecx
shrl $0x3, %ecx
movb (%r13,%rcx), %dl
andb $0x1, %dl
movb %dl, (%r13,%rax)
movb (%r13,%rcx), %dl
shrb %dl
andb $0x1, %dl
movb %dl, -0x1(%r13,%rax)
movb (%r13,%rcx), %dl
shrb $0x2, %dl
andb $0x1, %dl
movb %dl, -0x2(%r13,%rax)
movb (%r13,%rcx), %dl
shrb $0x3, %dl
andb $0x1, %dl
movb %dl, -0x3(%r13,%rax)
movb (%r13,%rcx), %dl
shrb $0x4, %dl
andb $0x1, %dl
movb %dl, -0x4(%r13,%rax)
movb (%r13,%rcx), %dl
shrb $0x5, %dl
andb $0x1, %dl
movb %dl, -0x5(%r13,%rax)
movb (%r13,%rcx), %dl
shrb $0x6, %dl
andb $0x1, %dl
movb %dl, -0x6(%r13,%rax)
movb (%r13,%rcx), %cl
shrb $0x7, %cl
movb %cl, -0x7(%r13,%rax)
leaq -0x8(%rax), %rcx
cmpq $0xe, %rax
movq %rcx, %rax
jg 0x81bc
jmp 0x8404
cmpl $0x0, 0x14(%rsp)
jne 0x852b
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 0x44(%rsp), %r12d
movq %rbx, %rbp
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2270
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
sarl %eax
movslq %eax, %rdx
movq %rbx, %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
cmpl $0x2, %eax
jl 0x8404
decl %eax
movl %eax, %ecx
shrl %ecx
movb (%r13,%rcx), %dl
andb $0xf, %dl
movb %dl, (%r13,%rax)
movb (%r13,%rcx), %cl
shrb $0x4, %cl
movb %cl, -0x1(%r13,%rax)
leaq -0x2(%rax), %rcx
cmpq $0x2, %rax
movq %rcx, %rax
jg 0x82c6
jmp 0x8404
cmpl $0x0, 0x14(%rsp)
jne 0x852b
movl 0x44(%rsp), %esi
addl 0x8(%r15), %esi
xorl %ebp, %ebp
movq %r14, %rdi
xorl %edx, %edx
callq 0x2270
movl 0x8(%rsp), %eax
imull 0xc(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
xorl %ebx, %ebx
jmp 0x8404
xorl %ebp, %ebp
leaq 0x2c(%rsp), %rsi
movl $0xc, %edx
movq %r14, %rdi
callq 0x2240
addl 0x44(%rsp), %r15d
xorl %ebp, %ebp
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2270
movl 0x8(%rsp), %eax
imull 0xc(%rsp), %eax
shll $0x2, %eax
movslq %eax, %rdx
xorl %ebp, %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x2240
movl 0xc(%rsp), %eax
imull 0x8(%rsp), %eax
testl %eax, %eax
jle 0x8402
movl 0x2c(%rsp), %edi
movl 0x30(%rsp), %r8d
movl %edi, %r9d
shrl $0x8, %r9d
incl %r9d
movl %r8d, %r10d
shrl $0x8, %r10d
incl %r10d
movl 0x34(%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 0x83bf
xorl %ebx, %ebx
movq %rbx, 0x48(%rsp)
movzwl 0x12(%rsp), %eax
movl %eax, (%rsp)
movl 0xc(%rsp), %edx
cmpl $0x2, %edx
jl 0x84b0
movl (%rsp), %ecx
movl %ecx, %eax
shrl $0x3, %eax
cmpw $0x8, %cx
movl $0x1, %esi
cmovael %eax, %esi
movl 0x8(%rsp), %edi
movl %edx, %r8d
shrl %r8d
movslq %edi, %r9
imulq %rsi, %r9
leaq -0x1(%rdx), %rax
imulq %r9, %rax
movq %r13, %r10
addq %rax, %r10
movq %r9, %r11
negq %r11
xorl %r14d, %r14d
movq %r13, %rbx
testl %edi, %edi
jle 0x84a2
movq %r10, %rbp
movq %rbx, %r12
xorl %eax, %eax
testq %rsi, %rsi
je 0x8494
xorl %r15d, %r15d
movb (%r12,%r15), %cl
xorb (%rbp,%r15), %cl
movb %cl, (%r12,%r15)
xorb (%rbp,%r15), %cl
movb %cl, (%rbp,%r15)
xorb %cl, (%r12,%r15)
incq %r15
cmpq %r15, %rsi
jne 0x8471
incq %rax
addq %rsi, %r12
addq %rsi, %rbp
cmpq %rdi, %rax
jne 0x8469
incq %r14
addq %r9, %rbx
addq %r11, %r10
cmpq %r8, %r14
jne 0x845d
movl 0x8(%rsp), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movq 0x58(%rsp), %rax
movl %edx, (%rax)
movq 0x60(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, (%rax)
movq 0x68(%rsp), %rax
movq %r13, (%rax)
movq 0x48(%rsp), %rax
movq 0xc0(%rsp), %rcx
movq %rax, (%rcx)
addq $0x88, %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 0x85e2
leaq 0x6879(%rip), %rsi      # 0xed90
leaq 0x106(%rip), %rdx       # 0x8624
movq %rbx, %rdi
callq 0x2320
cmpl $0x10, %ebx
jne 0x855d
movl $0x18, %edi
callq 0x20e0
movq %rax, %r14
movq %rax, %rdi
movl $0x5, %esi
callq 0x85e2
xorl %ebp, %ebp
leaq 0x6842(%rip), %rsi      # 0xed90
leaq 0xcf(%rip), %rdx        # 0x8624
movq %r14, %rdi
callq 0x2320
movl $0x18, %edi
callq 0x20e0
movq %rax, %r14
leaq 0x1f53(%rip), %rdx      # 0xa4c4
movq %rax, %rdi
movl $0x1, %esi
callq 0x85f8
jmp 0x8545
movq %rax, %r14
cmpl $0x1, %edx
jne 0x85b7
leaq 0x70(%rsp), %rax
movq %r14, %rdi
movl %edx, %esi
movq %rax, %rdx
movq %r13, %rcx
movq %rbp, %r8
callq 0x2555
callq 0x22a0
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x8624
callq 0x2300
movq %r14, %rdi
callq 0x2350
movq %rax, %rdi
callq 0x7292
nop