// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
subq $0x2, %rax
je 0x1030ad
jmp 0x103084
movq -0x20(%rbp), %rax
subq $0x4, %rax
je 0x1030cb
jmp 0x103090
movq -0x20(%rbp), %rax
subq $0x10, %rax
je 0x1030f4
jmp 0x10309c
movq -0x20(%rbp), %rax
subq $0x100, %rax            # imm = 0x100
je 0x10311b
jmp 0x103142
movq -0x10(%rbp), %rax
movl $0xff000000, 0x9c(%rax) # imm = 0xFF000000
movq -0x10(%rbp), %rax
movl $0xffffffff, 0xa0(%rax) # imm = 0xFFFFFFFF
jmp 0x103147
movq -0x10(%rbp), %rcx
addq $0x9c, %rcx
movl $0xa, %edi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
movl $0x4, %r8d
xorl %r9d, %r9d
callq 0x161320
jmp 0x103147
movq -0x10(%rbp), %rcx
addq $0x9c, %rcx
movl $0x14, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x10, %r8d
movl %r9d, %esi
callq 0x161320
jmp 0x103147
movq -0x10(%rbp), %rcx
addq $0x9c, %rcx
movl $0x28, %edi
xorl %r9d, %r9d
xorl %eax, %eax
movl %eax, %edx
movl $0x100, %r8d            # imm = 0x100
movl %r9d, %esi
callq 0x161320
jmp 0x103147
jmp 0x1032c6
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movl (%rax), %eax
movq %rax, -0x28(%rbp)
subq $0x5, %rax
ja 0x1032a8
movq -0x28(%rbp), %rax
leaq 0xbe2f2(%rip), %rcx     # 0x1c145c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xbe626(%rip), %rsi     # 0x1c17aa
movb $0x0, %al
callq 0x15b0d0
jmp 0x1032c4
movq -0x8(%rbp), %rdi
leaq 0xbe64c(%rip), %rsi     # 0x1c17e7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1032d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x1032c4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xbe62e(%rip), %rsi     # 0x1c180f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x1033a0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x1032c4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xbe61c(%rip), %rsi     # 0x1c1847
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x103450
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x1032c4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0xbe611(%rip), %rsi     # 0x1c1883
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x103530
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
jmp 0x1032c4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movl (%rax), %edx
leaq 0xbe5f3(%rip), %rsi     # 0x1c18b0
movb $0x0, %al
callq 0x15bc10
jmp 0x1032c6
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)