// File: /workspace/github_c_makefile_star2_O3/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 0xb0079
cmpq $0x2, %r15
je 0xb00a0
cmpq $0x4, %r15
jne 0xb045a
leaq 0x9c(%rbp), %rcx
movl $0x4, %r8d
movl $0xa, %edi
movl $0x2, %esi
jmp 0xb00c1
cmpq $0x10, %r15
je 0xb00ad
cmpq $0x100, %r15            # imm = 0x100
jne 0xb045a
leaq 0x9c(%rbp), %rcx
movl $0x100, %r8d            # imm = 0x100
movl $0x28, %edi
jmp 0xb00bf
movq $-0x1000000, 0x9c(%rbp) # imm = 0xFF000000
jmp 0xb00cb
leaq 0x9c(%rbp), %rcx
movl $0x10, %r8d
movl $0x14, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xec55a
movq 0x78(%rbp), %rax
movl (%rax), %edx
cmpq $0x5, %rdx
ja 0xb02f6
leaq 0x8596e(%rip), %rax     # 0x135a50
movslq (%rax,%rdx,4), %rcx
addq %rax, %rcx
movq %rbp, 0x8(%rsp)
jmpq *%rcx
leaq 0x85e54(%rip), %rsi     # 0x135f4b
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x78(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x2, %edx
movq %r15, %rsi
movb $0x1, %dil
movl %edi, 0x4(%rsp)
cmpq %rcx, %rdx
jge 0xb032e
movq 0x10(%rax), %rdi
cmpb $0x3f, -0x2(%rdi,%rdx)
ja 0xb0315
cmpb $0x3f, -0x1(%rdi,%rdx)
ja 0xb0315
cmpb $0x40, (%rdi,%rdx)
jae 0xb0315
addq $0x3, %rdx
decq %rsi
jne 0xb0121
jmp 0xb032e
leaq 0x85d6d(%rip), %rsi     # 0x135ed7
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x85e24(%rip), %rbx     # 0x135faf
xorl %r15d, %r15d
movq 0x78(%rbp), %rax
cmpq 0x8(%rax), %r15
jge 0xb04cc
movq 0x10(%rax), %rax
movzbl (%rax,%r15), %edx
movl $0x14, %edi
xorl %esi, %esi
callq 0xec464
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 0xe87e4
incq %r15
cmpq $0x10, %r15
jne 0xb018e
jmp 0xb04cc
leaq 0x85d24(%rip), %rsi     # 0x135f0f
movq %r14, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x6e268(%rip), %rbx     # 0x11e474
leaq 0x20(%rsp), %r12
xorl %r13d, %r13d
movq 0x78(%rbp), %rax
cmpq 0x8(%rax), %r13
jge 0xb044d
movq 0x10(%rax), %rax
movzbl (%rax,%r13), %edx
movl $0x1e, %edi
xorl %esi, %esi
callq 0xec464
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 0xe8193
movl 0x9c(%rbp,%r13,4), %edx
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0xe90a3
incq %r13
cmpq %r13, %r15
jne 0xb0214
jmp 0xb044d
leaq 0x85be4(%rip), %rsi     # 0x135e72
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 0xe8617
leaq 0x85bff(%rip), %rsi     # 0x135eaf
movq %rbp, %rbx
xorl %ebp, %ebp
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r14, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x78(%rbx), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
jle 0xb0469
movq 0x10(%rax), %rdx
movb (%rdx), %al
cmpq $0x1, %rcx
je 0xb046b
movzbl 0x1(%rdx), %ebp
jmp 0xb046b
leaq 0x85c7b(%rip), %rsi     # 0x135f78
movq %r14, %rdi
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8faa
leaq 0x85ca1(%rip), %rsi     # 0x135fbd
movl $0x0, 0x4(%rsp)
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movq %r15, 0x18(%rsp)
movl $0x2, %r15d
xorl %ebp, %ebp
movq %r14, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rax
cmpq 0x8(%rax), %r15
jge 0xb044d
movq 0x10(%rax), %rax
movzbl -0x2(%rax,%r15), %ebx
movzbl -0x1(%rax,%r15), %r13d
movzbl (%rax,%r15), %r12d
cmpb $0x0, 0x4(%rsp)
je 0xb03fe
movl %ebx, %edi
callq 0xec78a
movb %al, 0x3(%rsp)
movl %r13d, %edi
callq 0xec78a
movl %eax, %r14d
movl %r12d, %edi
callq 0xec78a
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 0x60bce(%rip), %rdx     # 0x110f98
movl %ebx, %ecx
movl %r13d, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0xe8193
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 0xe90a3
jmp 0xb043b
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 0xe91fc
incq %rbp
addq $0x3, %r15
cmpq %rbp, 0x18(%rsp)
jne 0xb0340
movq %r14, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movzbl %al, %ebx
leaq 0x85b1c(%rip), %rsi     # 0x135f91
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x85b18(%rip), %rsi     # 0x135fa0
movq %r14, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %r15
leaq 0x9c(%r15), %rcx
movl $0x4, %r8d
movl $0xa, %edi
movl %ebx, %esi
xorl %edx, %edx
xorl %r9d, %r9d
callq 0xec55a
movl $0x14, %edi
xorl %esi, %esi
movl %ebp, %edx
callq 0xec464
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 0xe8a15