// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/graphics/backends/xlib/bitmapxlib.cpp
// Function: smooth::GUI::BitmapXLib::CreateBitmap(smooth::GUI::Size const&, int)
S::Bool S::GUI::BitmapXLib::CreateBitmap(const Size &nSize, Int nDepth)
{
	if (display == NIL) return False;

	DeleteBitmap();

	if (nDepth == -1)		  nDepth = XDefaultDepth(display, XDefaultScreen(display));
	if (nDepth != 24 && nDepth != 32) nDepth = 24;

	/* Find best fit for pixel format.
	 */
	int			 count	 = 0;
	int			 index	 = 0;
	XPixmapFormatValues	*formats = XListPixmapFormats(display, &count);

	for (Int i = 0; i < count; i++)
	{
		if (Math::Abs(formats[i].depth - nDepth) < Math::Abs(formats[index].depth - nDepth)) index = i;

		if (formats[i].depth == nDepth) break;
	}

	/* Allocate and create image.
	 */
	bytes	= new UnsignedByte [nSize.cy * nSize.cx * (formats[index].bits_per_pixel / 8) + nSize.cy * (((nSize.cx * formats[index].bits_per_pixel) % formats[index].scanline_pad) / 8)];
	bitmap	= XCreateImage(display, XDefaultVisual(display, XDefaultScreen(display)), formats[index].depth, ZPixmap, 0, (char *) bytes, nSize.cx, nSize.cy, formats[index].scanline_pad, 0);

	if (bitmap == NIL) { delete [] (UnsignedByte *) bytes; XFree(formats); return False; }

	size	= nSize;
	depth	= formats[index].depth;
	bpp	= formats[index].bits_per_pixel;
	align	= formats[index].scanline_pad / 8;

	XFree(formats);

	return True;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x20(%rdi)
je 0xbddba
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x18(%rax)
cmpl $-0x1, %ebp
jne 0xbdc43
movq 0x20(%rbx), %r15
movq %r15, %rdi
callq 0x57dd0
movq %r15, %rdi
movl %eax, %esi
callq 0x58fd0
movl %eax, %ebp
xorl %r13d, %r13d
cmpl $0x20, %ebp
sete %bpl
leaq 0x4(%rsp), %r12
movl $0x0, (%r12)
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x57300
movq %rax, %r15
movslq (%r12), %rax
xorl %ecx, %ecx
testq %rax, %rax
jle 0xbdcfb
movb %bpl, %r13b
leal 0x18(,%r13,8), %edx
decq %rax
movq %r15, %rsi
xorl %edi, %edi
movslq %ecx, %r8
leaq (%r8,%r8,2), %r8
movl (%r15,%r8,4), %r8d
movl %r8d, %r10d
subl %edx, %r10d
xorl %r9d, %r9d
movl $0x0, %r11d
subl %edx, %r8d
je 0xbdcb5
sarl $0x1f, %r10d
orl $0x1, %r10d
movl %r10d, %r11d
movl (%rsi), %r10d
movl %r10d, %ebp
subl %edx, %ebp
sarl $0x1f, %ebp
orl $0x1, %ebp
movl %r10d, %r12d
subl %edx, %r12d
cmovel %r9d, %ebp
imull %r12d, %ebp
imull %r8d, %r11d
movl %edi, %r8d
cmpl %r11d, %ebp
jl 0xbdce0
movl %ecx, %r8d
cmpl %edx, %r10d
je 0xbdcf8
leaq 0x1(%rdi), %r9
addq $0xc, %rsi
movl %r8d, %ecx
cmpq %rdi, %rax
movq %r9, %rdi
jne 0xbdc8b
movslq %r8d, %rcx
movl (%r14), %edx
leaq (%rcx,%rcx,2), %r13
movl 0x4(%r15,%r13,4), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
imull %edx, %ecx
imull %edx, %eax
cltd
idivl 0x8(%r15,%r13,4)
leal 0x7(%rdx), %eax
testl %edx, %edx
cmovnsl %edx, %eax
sarl $0x3, %eax
addl %ecx, %eax
imull 0x4(%r14), %eax
movslq %eax, %rdi
callq 0x56670
movq %rax, 0x18(%rbx)
movq 0x20(%rbx), %r12
movq %r12, %rdi
callq 0x57dd0
movq %r12, %rdi
movl %eax, %esi
callq 0x57360
movq 0x18(%rbx), %r9
movl (%r14), %r10d
movl 0x4(%r14), %r11d
movl (%r15,%r13,4), %edx
movl 0x8(%r15,%r13,4), %ebp
movq %r12, %rdi
movq %rax, %rsi
movl $0x2, %ecx
xorl %r8d, %r8d
pushq $0x0
pushq %rbp
pushq %r11
pushq %r10
callq 0x590f0
addq $0x20, %rsp
movq %rax, 0x28(%rbx)
testq %rax, %rax
setne %bpl
je 0xbddbe
leaq (%r15,%r13,4), %rax
movq (%r14), %rcx
movq %rcx, 0x10(%rbx)
movb (%rax), %cl
movb %cl, 0xa(%rbx)
movb 0x4(%rax), %cl
movb %cl, 0xb(%rbx)
movl 0x8(%rax), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
shrl $0x3, %ecx
movb %cl, 0xc(%rbx)
jmp 0xbddcc
xorl %ebp, %ebp
jmp 0xbddd4
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0xbddcc
callq 0x561e0
movq %r15, %rdi
callq 0x57e80
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop