// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/graphics/imageloader/imageloader.cpp
// Function: smooth::GUI::ImageLoader::Load(smooth::String const&)
S::GUI::Bitmap S::GUI::ImageLoader::Load(const String &fileName)
{
	ImageLoader	*loader = NIL;

	if	(fileName.ToLower().Contains(".pci:")) loader = new ImageLoaderPCI(fileName);
#ifdef __WIN32__
	else if (fileName.StartsWith("Icon:"))	       loader = new ImageLoaderIcon(fileName);
#endif

	if (loader == NIL)
	{
		/* Auto-detect image format.
		 */
		Buffer<UnsignedByte>	 buffer(12);
		InStream		 in(STREAM_FILE, fileName, IS_READ);

		in.InputData(buffer, 12);

		Short	 format = DetectImageFormat(buffer);

		if	(format == IMAGE_FORMAT_PCI)  loader = new ImageLoaderPCI(fileName);
		else if (format == IMAGE_FORMAT_PNG)  loader = new ImageLoaderPNG(fileName);
		else if (format == IMAGE_FORMAT_JPEG) loader = new ImageLoaderJPEG(fileName);
		else if (format == IMAGE_FORMAT_WEBP) loader = new ImageLoaderWebP(fileName);
	}

	/* Load image.
	 */
	Bitmap	 bitmap;

	if (loader != NIL)
	{
		bitmap = loader->Load();

		delete loader;
	}

	/* Look in the startup and application folders if no image has been found yet.
	 */
	if (!fileName.StartsWith(Application::GetStartupDirectory()) && !fileName.StartsWith(Application::GetApplicationDirectory()))
	{
		if (bitmap == NIL) bitmap = Load(Application::GetStartupDirectory().Append(fileName));
		if (bitmap == NIL) bitmap = Load(Application::GetApplicationDirectory().Append(fileName));
	}

	return bitmap;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x58090
leaq 0x91a75(%rip), %rsi     # 0xf361b
leaq 0x8(%rsp), %rdi
callq 0x579f0
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x55180
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
je 0x61c01
movl $0x48, %edi
callq 0x556b0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62468
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58950
jmp 0x61d06
leaq 0x8(%rsp), %rdi
movl $0xc, %esi
callq 0x620b8
leaq 0x20(%rsp), %rdi
movl $0x3, %esi
movq %r14, %rdx
movl $0x2, %ecx
callq 0x58730
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x61c36
movq (%rax), %rsi
jmp 0x61c38
xorl %esi, %esi
leaq 0x20(%rsp), %rdi
movl $0xc, %edx
callq 0x56f50
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x61efb
cmpw $0x3, %ax
ja 0x61cd6
movzwl %ax, %eax
leaq 0x9197b(%rip), %rcx     # 0xf35e0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x48, %edi
callq 0x556b0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62468
jmp 0x61cd9
movl $0x48, %edi
callq 0x556b0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62174
jmp 0x61cd9
movl $0x48, %edi
callq 0x556b0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62ce0
jmp 0x61cd9
movl $0x48, %edi
callq 0x556b0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x62710
jmp 0x61cd9
xorl %r15d, %r15d
leaq 0x20(%rsp), %rdi
callq 0x555b0
leaq 0xfe266(%rip), %rax     # 0x15ff50
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
callq 0x62130
movq %rbx, %rdi
xorl %esi, %esi
callq 0x58950
testq %r15, %r15
je 0x61d23
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x582c0
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
leaq 0x20(%rsp), %rdi
callq 0x58530
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x577d0
testb %al, %al
je 0x61d4d
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0x61e24
leaq 0x8(%rsp), %rdi
callq 0x57a50
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x577d0
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
testb %bpl, %bpl
jne 0x61e24
movq %rbx, %rdi
xorl %esi, %esi
callq 0x57e30
testb %al, %al
je 0x61dd6
leaq 0x20(%rsp), %rdi
callq 0x58530
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x562f0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x581f0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x582c0
leaq 0x8(%rsp), %rdi
callq 0x59148
leaq 0x20(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x57e30
testb %al, %al
je 0x61e24
leaq 0x20(%rsp), %rdi
callq 0x57a50
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x562f0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x581f0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x582c0
leaq 0x8(%rsp), %rdi
callq 0x59148
jmp 0x61d3e
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x61e3b
jmp 0x61e3b
jmp 0x61e3b
movq %rax, %r14
movl $0x48, %esi
movq %r15, %rdi
callq 0x55480
jmp 0x61e82
jmp 0x61e54
jmp 0x61ee8
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x59148
jmp 0x61ebc
jmp 0x61ee8
jmp 0x61eb9
jmp 0x61eb9
jmp 0x61e7f
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x59200
jmp 0x61ebc
jmp 0x61eb9
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x555b0
jmp 0x61e91
movq %rax, %r14
leaq 0xfe0b8(%rip), %rax     # 0x15ff50
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
callq 0x62130
jmp 0x61ef3
movq %rax, %r14
movl $0x48, %esi
movq %r15, %rdi
callq 0x55480
jmp 0x61ef3
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0x61eeb
jmp 0x61ee8
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x59200
jmp 0x61edc
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0x61ef3
movq %rax, %r14
movq %rbx, %rdi
callq 0x59148
movq %r14, %rdi
callq 0x57090