// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/pcpaint.c
// Function: acquire_palette
static void acquire_palette(deark *c, lctx *d, i64 ncolors)
{
	// Start with a default palette
	switch(ncolors) {
	case 2:
		d->pal[0] = DE_STOCKCOLOR_BLACK;
		d->pal[1] = DE_STOCKCOLOR_WHITE;
		break;
	case 4:
		de_copy_std_palette(DE_PALID_CGA, 2, 0, d->pal, 4, 0);
		break;
	case 16:
		de_copy_std_palette(DE_PALID_PC16, 0, 0, d->pal, 16, 0);
		break;
	case 256:
		de_copy_std_palette(DE_PALID_VGA256, 0, 0, d->pal, 256, 0);
		break;
	default:
		goto done;
	}

	switch(d->pal_info_to_use->edesc) {
	case 0:
		de_dbg(c, "palette type: standard %d-color palette (no palette in file)", (int)ncolors);
		break;
	case 1:
		de_dbg(c, "palette type: CGA coded 4-color palette");
		de_dbg_indent(c, 1);
		acquire_palette_cga4color(c, d);
		de_dbg_indent(c, -1);
		break;
	case 2:
		de_dbg(c, "palette type: %d indices into standard 16-color palette", (int)ncolors);
		de_dbg_indent(c, 1);
		acquire_palette_indirect16col(c, d, ncolors);
		de_dbg_indent(c, -1);
		break;
	case 3:
		de_dbg(c, "palette type: %d indices into standard EGA 64-color palette", (int)ncolors);
		de_dbg_indent(c, 1);
		acquire_palette_ega64idx(c, d, ncolors);
		de_dbg_indent(c, -1);
		break;
	case 4:
	case 5:
		de_dbg(c, "palette type: %d-color RGB palette (in file)", (int)ncolors);
		de_dbg_indent(c, 1);
		acquire_palette_rgb(c, d, ncolors);
		de_dbg_indent(c, -1);
		break;
	default:
		de_warn(c, "Unknown palette type: %u", (UI)d->pal_info_to_use->edesc);
	}
done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %r14
cmpq $0xf, %rdx
jg 0xb0bcb
cmpq $0x2, %r15
je 0xb0bf2
cmpq $0x4, %r15
jne 0xb103c
leaq 0x9c(%rbp), %rcx
movl $0x4, %r8d
movl $0xa, %edi
movl $0x2, %esi
jmp 0xb0c13
cmpq $0x10, %r15
je 0xb0bff
cmpq $0x100, %r15            # imm = 0x100
jne 0xb103c
leaq 0x9c(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
movl $0x28, %edi
jmp 0xb0c11
movq $-0x1000000, 0x9c(%rbp) # imm = 0xFF000000
jmp 0xb0c1d
leaq 0x9c(%rbp), %rcx
movl $0x10, %r8d
movl $0x14, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xecbbc
movq 0x78(%rbp), %rax
movl (%rax), %edx
cmpq $0x5, %rdx
ja 0xb0ecf
leaq 0x84a94(%rip), %rax     # 0x1356c8
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
movq %rbp, 0x8(%rsp)
jmpq *%rcx
leaq 0x84f7a(%rip), %rsi     # 0x135bc3
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movb $0x1, %al
movl %eax, 0x4(%rsp)
testq %r15, %r15
jle 0xb0f07
movq 0x78(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x2, %edx
movq %r15, %rsi
cmpq %rcx, %rdx
jge 0xb0f07
movq 0x10(%rax), %rdi
cmpb $0x3f, -0x2(%rdi,%rdx)
ja 0xb0eee
cmpb $0x3f, -0x1(%rdi,%rdx)
ja 0xb0eee
cmpb $0x40, (%rdi,%rdx)
jae 0xb0eee
addq $0x3, %rdx
decq %rsi
jne 0xb0c82
jmp 0xb0f07
leaq 0x84e8b(%rip), %rsi     # 0x135b4f
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x84f42(%rip), %rbx     # 0x135c27
xorl %r15d, %r15d
movq 0x78(%rbp), %rax
cmpq 0x8(%rax), %r15
jge 0xb0eb4
movq 0x10(%rax), %rax
movzbl (%rax,%r15), %edx
movl $0x14, %edi
xorl %esi, %esi
callq 0xecac6
movl %eax, 0x9c(%rbp,%r15,4)
movq 0x78(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax,%r15), %ecx
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe93cf
incq %r15
cmpq $0x10, %r15
jne 0xb0ce8
jmp 0xb0eb4
leaq 0x84e42(%rip), %rsi     # 0x135b87
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
testq %r15, %r15
jle 0xb102f
leaq 0x6d5f5(%rip), %rbx     # 0x11e364
leaq 0x20(%rsp), %r12
xorl %r13d, %r13d
movq 0x78(%rbp), %rax
cmpq 0x8(%rax), %r13
jge 0xb102f
movq 0x10(%rax), %rax
movzbl (%rax,%r13), %edx
movl $0x1e, %edi
xorl %esi, %esi
callq 0xecac6
movl %eax, 0x9c(%rbp,%r13,4)
movq 0x78(%rbp), %rax
movq 0x10(%rax), %rax
movzbl (%rax,%r13), %ecx
movl $0x20, %esi
movq %r12, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xe8d67
movl 0x9c(%rbp,%r13,4), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe9c1e
incq %r13
cmpq %r13, %r15
jne 0xb0d77
jmp 0xb102f
leaq 0x84cf9(%rip), %rsi     # 0x135aea
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9226
leaq 0x84d14(%rip), %rsi     # 0x135b27
movq %rbp, %rbx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
movq %r14, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x78(%rbx), %rax
movq 0x8(%rax), %rcx
movl $0x0, %ebx
testq %rcx, %rcx
jle 0xb0e48
movq 0x10(%rax), %rdx
movzbl (%rdx), %ebx
cmpq $0x2, %rcx
jl 0xb0e56
movq 0x10(%rax), %rax
movzbl 0x1(%rax), %ebp
leaq 0x84dac(%rip), %rsi     # 0x135c09
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9226
leaq 0x84da8(%rip), %rsi     # 0x135c18
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%rsp), %r15
leaq 0x9c(%r15), %rcx
movl $0x4, %r8d
movl $0xa, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xecbbc
movl $0x14, %edi
xorl %esi, %esi
movl %ebp, %edx
callq 0xecac6
movl %eax, 0x9c(%r15)
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9585
leaq 0x84d1a(%rip), %rsi     # 0x135bf0
movq %r14, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9b27
leaq 0x84d40(%rip), %rsi     # 0x135c35
movl $0x0, 0x4(%rsp)
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
movq %r15, 0x18(%rsp)
testq %r15, %r15
jle 0xb102f
movl $0x2, %r15d
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rax
cmpq 0x8(%rax), %r15
jge 0xb102f
movq 0x10(%rax), %rax
movzbl -0x2(%rax,%r15), %ebx
movzbl -0x1(%rax,%r15), %r13d
movzbl (%rax,%r15), %r12d
cmpb $0x0, 0x4(%rsp)
je 0xb0fe0
movl %ebx, %edi
callq 0xecde3
movb %al, 0x3(%rsp)
movl %r13d, %edi
callq 0xecde3
movl %eax, %r14d
movl %r12d, %edi
callq 0xecde3
movzbl 0x3(%rsp), %ecx
shll $0x10, %ecx
movzbl %r14b, %edx
shll $0x8, %edx
orl %ecx, %edx
movzbl %al, %eax
orl %edx, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movq 0x8(%rsp), %r14
movl %eax, 0x9c(%r14,%rbp,4)
movl $0x40, %esi
leaq 0x20(%rsp), %rdi
leaq 0x5ffdd(%rip), %rdx     # 0x110f89
movl %ebx, %ecx
movl %r13d, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0xe8d67
movl 0x9c(%r14,%rbp,4), %edx
movq 0x10(%rsp), %rdi
movq %rdi, %r14
movq %rbp, %rsi
leaq 0x20(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe9c1e
jmp 0xb101d
rolb $0x2, %bl
rolb $0x2, %r13b
rolb $0x2, %r12b
movzbl %bl, %eax
shll $0x10, %eax
movzbl %r13b, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl %r12b, %edx
orl %ecx, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movq 0x8(%rsp), %rax
movl %edx, 0x9c(%rax,%rbp,4)
movq %r14, %rdi
movq %rbp, %rsi
callq 0xe9d68
incq %rbp
addq $0x3, %r15
cmpq %rbp, 0x18(%rsp)
jne 0xb0f22
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq