// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/classes/gui/window/backends/xlib/windowxlib.cpp
// Function: smooth::GUI::WindowXLib::SetIcon(smooth::GUI::Bitmap const&)
S::Int S::GUI::WindowXLib::SetIcon(const Bitmap &newIcon)
{
	if (sysIcon != NIL)
	{
		delete [] sysIcon;

		sysIcon	    = NIL;
		sysIconSize = 0;
	}

	Int	 index = 0;
	Size	 size  = newIcon.GetSize();
	Int	 depth = newIcon.GetDepth();

	sysIconSize = 2 + size.cx * size.cy;
	sysIcon	    = new UnsignedLong [sysIconSize];

	sysIcon[index++] = size.cx;
	sysIcon[index++] = size.cy;

	Color	 backgroundColor16 = ((Setup::BackgroundColor.GetBlue() >> 3) << 11) | ((Setup::BackgroundColor.GetGreen() >> 2) << 5) | (Setup::BackgroundColor.GetRed() >> 3);
	Color	 backgroundColor24 = Setup::BackgroundColor;

	XImage	*image = (XImage *) newIcon.GetSystemBitmap();

	for (Int y = 0; y < size.cy; y++)
	{
		for (Int x = 0; x < size.cx; x++)
		{
			Long	 value = XGetPixel(image, x, y);

			if	(depth == 16) sysIcon[index++] = (value == backgroundColor16 ? 0 : 255) << 24 | (((value >> 11) & 0x1F) << 19) | (((value >> 5) & 0x3F) << 10) | ((value & 0x1F) << 3);
			else if (depth == 24) sysIcon[index++] = (value == backgroundColor24 ? 0 : 255) << 24 | value;
			else if (depth == 32) sysIcon[index++] = 						value;
		}
	}

	return Success();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, 0x158(%rax)
je 0x126442
movq -0x80(%rbp), %rax
movq 0x158(%rax), %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, %rax
je 0x126429
movq -0x88(%rbp), %rdi
callq 0x5a5e0
movq -0x80(%rbp), %rax
movq $0x0, 0x158(%rax)
movl $0x0, 0x160(%rax)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5ce60
movq (%rax), %rax
movq %rax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5b190
movb %al, %cl
movq -0x80(%rbp), %rax
movsbl %cl, %ecx
movl %ecx, -0x20(%rbp)
movl -0x1c(%rbp), %ecx
imull -0x18(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, 0x160(%rax)
movslq 0x160(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x5ab20
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x158(%rax)
movslq -0x1c(%rbp), %rsi
movq 0x158(%rax), %rcx
movl -0x14(%rbp), %edx
movl %edx, %edi
addl $0x1, %edi
movl %edi, -0x14(%rbp)
movslq %edx, %rdx
movq %rsi, (%rcx,%rdx,8)
movslq -0x18(%rbp), %rdx
movq 0x158(%rax), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq 0xe1fb3(%rip), %rdi     # 0x2084a8
callq 0x5b650
sarl $0x3, %eax
shll $0xb, %eax
movl %eax, -0x90(%rbp)
movq 0xe1f9b(%rip), %rdi     # 0x2084a8
callq 0x5d920
movl %eax, %ecx
movl -0x90(%rbp), %eax
sarl $0x2, %ecx
shll $0x5, %ecx
orl %ecx, %eax
movl %eax, -0x8c(%rbp)
movq 0xe1f79(%rip), %rdi     # 0x2084a8
callq 0x59f20
movl %eax, %ecx
movl -0x8c(%rbp), %eax
sarl $0x3, %ecx
orl %ecx, %eax
movslq %eax, %rsi
leaq -0x30(%rbp), %rdi
xorl %edx, %edx
callq 0x59be0
leaq -0x40(%rbp), %rdi
movq 0xe1f4e(%rip), %rsi     # 0x2084a8
callq 0x5c720
movq -0x10(%rbp), %rdi
callq 0x5d9f0
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x1266e1
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1266d1
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x48(%rbp), %rdi
movl -0x50(%rbp), %esi
movl -0x4c(%rbp), %edx
callq *%rax
movq %rax, -0x58(%rbp)
cmpl $0x10, -0x20(%rbp)
jne 0x12663c
movq -0x58(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x59210
movq -0x98(%rbp), %rsi
movq %rax, %rdi
movq -0x80(%rbp), %rax
movl $0xff, %ecx
xorl %edx, %edx
cmpq %rdi, %rsi
cmovel %edx, %ecx
shll $0x18, %ecx
movslq %ecx, %rdx
movq -0x58(%rbp), %rcx
sarq $0xb, %rcx
andq $0x1f, %rcx
shlq $0x13, %rcx
orq %rcx, %rdx
movq -0x58(%rbp), %rcx
sarq $0x5, %rcx
andq $0x3f, %rcx
shlq $0xa, %rcx
orq %rcx, %rdx
movq -0x58(%rbp), %rcx
andq $0x1f, %rcx
shlq $0x3, %rcx
orq %rcx, %rdx
movq 0x158(%rax), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1266c1
cmpl $0x18, -0x20(%rbp)
jne 0x126696
movq -0x58(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x59210
movq -0xa0(%rbp), %rsi
movq %rax, %rdi
movq -0x80(%rbp), %rax
movl $0xff, %ecx
xorl %edx, %edx
cmpq %rdi, %rsi
cmovel %edx, %ecx
shll $0x18, %ecx
movslq %ecx, %rdx
orq -0x58(%rbp), %rdx
movq 0x158(%rax), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1266bf
cmpl $0x20, -0x20(%rbp)
jne 0x1266bd
movq -0x80(%rbp), %rax
movq -0x58(%rbp), %rdx
movq 0x158(%rax), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x1266bf
jmp 0x1266c1
jmp 0x1266c3
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x126586
jmp 0x1266d3
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x126573
leaq -0x68(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x5ca80
movq -0xb0(%rbp), %rdi
callq 0x59680
movl %eax, -0xa4(%rbp)
jmp 0x126705
leaq -0x68(%rbp), %rdi
callq 0x5a410
movl -0xa4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5a410
movq -0x70(%rbp), %rdi
callq 0x5b6b0
nopl (%rax,%rax)