// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rsi, %r13
movq %rdi, (%rsp)
cmpq $0x100, %rdx            # imm = 0x100
je 0xa957e
cmpq $0x4, %rbx
je 0xa955b
cmpq $0x10, %rbx
je 0xa956e
cmpq $0x2, %rbx
jne 0xa988a
movq $-0x1000000, 0x9c(%r13) # imm = 0xFF000000
jmp 0xa959a
leaq 0x9c(%r13), %rcx
pushq $0xa
popq %rdi
pushq $0x2
popq %rsi
pushq $0x4
popq %r8
jmp 0xa9590
leaq 0x9c(%r13), %rcx
pushq $0x14
popq %rdi
pushq $0x10
popq %r8
jmp 0xa958e
leaq 0x9c(%r13), %rcx
pushq $0x28
popq %rdi
movl $0x100, %r8d            # imm = 0x100
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xe1b11
movq 0x78(%r13), %rax
movl (%rax), %edx
cmpq $0x5, %rdx
ja 0xa98fc
leaq 0x7f1bf(%rip), %rax     # 0x128770
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
movq %r13, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
jmpq *%rcx
leaq 0x7f6a0(%rip), %rsi     # 0x128c6b
movq (%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xdeba7
pushq $0x2
popq %rcx
pushq $-0x1
popq %rax
incq %rax
movb $0x1, %dl
movl %edx, 0xc(%rsp)
cmpq %rax, %rbx
je 0xa963a
movq 0x78(%r13), %rdx
cmpq 0x8(%rdx), %rcx
jge 0xa963a
movq 0x10(%rdx), %rdx
cmpb $0x3f, -0x2(%rdx,%rcx)
ja 0xa9620
cmpb $0x3f, -0x1(%rdx,%rcx)
ja 0xa9620
cmpb $0x40, (%rdx,%rcx)
leaq 0x3(%rcx), %rcx
jb 0xa95ec
leaq 0x7f6b6(%rip), %rsi     # 0x128cdd
movl $0x0, 0xc(%rsp)
movq (%rsp), %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x2
popq %r15
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0xa987e
movq 0x78(%r13), %rax
cmpq 0x8(%rax), %r15
jge 0xa987e
movq 0x10(%rax), %rax
movzbl -0x2(%rax,%r15), %ebx
movzbl -0x1(%rax,%r15), %r13d
movzbl (%rax,%r15), %ebp
cmpb $0x0, 0xc(%rsp)
je 0xa9700
movl %ebx, %edi
callq 0xe1cec
movb %al, 0xb(%rsp)
movl %r13d, %edi
callq 0xe1cec
movl %eax, %r14d
movl %ebp, %edi
callq 0xe1cec
movzbl 0xb(%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 0x10(%rsp), %r9
movl %eax, 0x9c(%r9,%r12,4)
leaq 0x20(%rsp), %r14
movq %r14, %rdi
pushq $0x40
popq %rsi
leaq 0x5a8a6(%rip), %rdx     # 0x103f75
movl %ebx, %ecx
movl %r13d, %r8d
movq %r9, %r13
movl %ebp, %r9d
xorl %eax, %eax
callq 0xde40c
movl 0x9c(%r13,%r12,4), %edx
movq (%rsp), %rdi
movq %r12, %rsi
movq %r14, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xdf153
jmp 0xa973f
rolb $0x2, %bl
rolb $0x2, %r13b
rolb $0x2, %bpl
movzbl %bl, %eax
shll $0x10, %eax
movzbl %r13b, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl %bpl, %edx
orl %ecx, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movq 0x10(%rsp), %r13
movl %edx, 0x9c(%r13,%r12,4)
movq (%rsp), %rdi
movq %r12, %rsi
callq 0xdf23b
incq %r12
addq $0x3, %r15
movq 0x18(%rsp), %rbx
jmp 0xa9641
leaq 0x7f4a0(%rip), %rsi     # 0x128bf7
movq (%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xdeba7
pushq $0x14
popq %rbx
leaq 0x7f553(%rip), %r15     # 0x128ccf
xorl %r12d, %r12d
cmpq $0x10, %r12
je 0xa97cc
movq 0x78(%r13), %rax
cmpq 0x8(%rax), %r12
jge 0xa97cc
movq 0x10(%rax), %rax
movzbl (%rax,%r12), %edx
movl %ebx, %edi
xorl %esi, %esi
callq 0xe1a23
movl %eax, 0x9c(%r13,%r12,4)
movq 0x78(%r13), %rax
movq 0x10(%rax), %rax
movzbl (%rax,%r12), %ecx
movq (%rsp), %rdi
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde9f1
incq %r12
jmp 0xa977f
pushq $-0x1
popq %rsi
movq (%rsp), %rdi
jmp 0xa997e
leaq 0x7f450(%rip), %rsi     # 0x128c2f
movq (%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xdeba7
pushq $0x1e
popq %r14
leaq 0x67b9b(%rip), %rbx     # 0x1113a0
leaq 0x20(%rsp), %r12
pushq $0x20
popq %r13
xorl %ebp, %ebp
movq 0x10(%rsp), %r15
cmpq %rbp, 0x18(%rsp)
je 0xa987e
movq 0x78(%r15), %rax
cmpq 0x8(%rax), %rbp
jge 0xa987e
movq 0x10(%rax), %rax
movzbl (%rax,%rbp), %edx
movl %r14d, %edi
xorl %esi, %esi
callq 0xe1a23
movl %eax, 0x9c(%r15,%rbp,4)
movq 0x78(%r15), %rax
movq 0x10(%rax), %rax
movzbl (%rax,%rbp), %ecx
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xde40c
movl 0x9c(%r15,%rbp,4), %edx
movq (%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xdf153
incq %rbp
jmp 0xa9815
pushq $-0x1
popq %rsi
movq (%rsp), %rdi
callq 0xdeba7
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7f2f2(%rip), %rsi     # 0x128b92
movq (%rsp), %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xde896
leaq 0x7f30d(%rip), %rsi     # 0x128bcf
xorl %ebp, %ebp
movq (%rsp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x78(%r13), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
jle 0xa991c
movq 0x10(%rax), %rdx
movb (%rdx), %al
cmpq $0x1, %rcx
je 0xa991e
movzbl 0x1(%rdx), %ebp
jmp 0xa991e
leaq 0x7f395(%rip), %rsi     # 0x128c98
movq (%rsp), %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf05a
xorl %eax, %eax
movzbl %al, %ebx
leaq 0x7f389(%rip), %rsi     # 0x128cb1
movq (%rsp), %r14
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xde896
leaq 0x7f381(%rip), %rsi     # 0x128cc0
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
leaq 0x9c(%r13), %rcx
pushq $0xa
popq %rdi
pushq $0x4
popq %r8
movl %ebx, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xe1b11
pushq $0x14
popq %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0xe1a23
movl %eax, 0x9c(%r13)
pushq $-0x1
popq %rsi
movq %r14, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdeba7