// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pcpaint.c
// Function: acquire_palette_rgb
static void acquire_palette_rgb(deark *c, lctx *d, i64 num_entries)
{
	i64 k;
	u8 cr1, cg1, cb1;
	u8 cr2, cg2, cb2;
	int has_8bit_samples = 0;
	char tmps[64];

	// Pre-scan
	for(k=0; k<num_entries; k++) {
		if(3*k+2 >= d->pal_info_to_use->esize) break;
		cr1 = d->pal_info_to_use->data[3*k+0];
		cg1 = d->pal_info_to_use->data[3*k+1];
		cb1 = d->pal_info_to_use->data[3*k+2];
		if(cr1>63 || cg1>63 || cb1>63) {
			de_dbg(c, "[detected 8-bit palette samples]");
			has_8bit_samples = 1;
			break;
		}
	}

	// For real
	for(k=0; k<num_entries; k++) {
		if(3*k+2 >= d->pal_info_to_use->esize) break;
		cr1 = d->pal_info_to_use->data[3*k+0];
		cg1 = d->pal_info_to_use->data[3*k+1];
		cb1 = d->pal_info_to_use->data[3*k+2];

		if(has_8bit_samples) {
			cr2 = (cr1<<2) | (cr1>>6);
			cg2 = (cg1<<2) | (cg1>>6);
			cb2 = (cb1<<2) | (cb1>>6);
			d->pal[k] = DE_MAKE_RGB(cr2, cg2, cb2);
			de_dbg_pal_entry(c, k, d->pal[k]);
		}
		else {
			cr2 = de_scale_63_to_255(cr1);
			cg2 = de_scale_63_to_255(cg1);
			cb2 = de_scale_63_to_255(cb1);
			d->pal[k] = DE_MAKE_RGB(cr2, cg2, cb2);
			de_snprintf(tmps, sizeof(tmps), "(%2d,%2d,%2d) "DE_CHAR_RIGHTARROW" ",
				(int)cr1, (int)cg1, (int)cb1);
			de_dbg_pal_entry2(c, k, d->pal[k], tmps, NULL, NULL);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x10360d
imulq $0x3, -0x20(%rbp), %rax
addq $0x2, %rax
movq -0x10(%rbp), %rcx
movq 0x78(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jl 0x10357d
jmp 0x10360d
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb 0x1(%rax,%rcx), %al
movb %al, -0x22(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb 0x2(%rax,%rcx), %al
movb %al, -0x23(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x3f, %eax
jg 0x1035df
movzbl -0x22(%rbp), %eax
cmpl $0x3f, %eax
jg 0x1035df
movzbl -0x23(%rbp), %eax
cmpl $0x3f, %eax
jle 0x1035fa
movq -0x8(%rbp), %rdi
leaq 0xbe30b(%rip), %rsi     # 0x1c18f5
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x2c(%rbp)
jmp 0x10360d
jmp 0x1035fc
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x103553
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x1037c4
imulq $0x3, -0x20(%rbp), %rax
addq $0x2, %rax
movq -0x10(%rbp), %rcx
movq 0x78(%rcx), %rcx
cmpq 0x8(%rcx), %rax
jl 0x10363f
jmp 0x1037c4
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb 0x1(%rax,%rcx), %al
movb %al, -0x22(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x10(%rax), %rax
imulq $0x3, -0x20(%rbp), %rcx
movb 0x2(%rax,%rcx), %al
movb %al, -0x23(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x103715
movzbl -0x21(%rbp), %eax
shll $0x2, %eax
movzbl -0x21(%rbp), %ecx
sarl $0x6, %ecx
orl %ecx, %eax
movb %al, -0x24(%rbp)
movzbl -0x22(%rbp), %eax
shll $0x2, %eax
movzbl -0x22(%rbp), %ecx
sarl $0x6, %ecx
orl %ecx, %eax
movb %al, -0x25(%rbp)
movzbl -0x23(%rbp), %eax
shll $0x2, %eax
movzbl -0x23(%rbp), %ecx
sarl $0x6, %ecx
orl %ecx, %eax
movb %al, -0x26(%rbp)
movzbl -0x24(%rbp), %edx
shll $0x10, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movzbl -0x25(%rbp), %eax
shll $0x8, %eax
orl %eax, %edx
movzbl -0x26(%rbp), %eax
orl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl %edx, 0x9c(%rax,%rcx,4)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x9c(%rax,%rcx,4), %edx
callq 0x15bf00
jmp 0x1037b1
movzbl -0x21(%rbp), %edi
callq 0x161710
movb %al, -0x24(%rbp)
movzbl -0x22(%rbp), %edi
callq 0x161710
movb %al, -0x25(%rbp)
movzbl -0x23(%rbp), %edi
callq 0x161710
movb %al, -0x26(%rbp)
movzbl -0x24(%rbp), %edx
shll $0x10, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movzbl -0x25(%rbp), %eax
shll $0x8, %eax
orl %eax, %edx
movzbl -0x26(%rbp), %eax
orl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl %edx, 0x9c(%rax,%rcx,4)
leaq -0x70(%rbp), %rdi
movzbl -0x21(%rbp), %ecx
movzbl -0x22(%rbp), %r8d
movzbl -0x23(%rbp), %r9d
movl $0x40, %esi
leaq 0x997ef(%rip), %rdx     # 0x19cf71
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x9c(%rax,%rcx,4), %edx
leaq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x15bdb0
jmp 0x1037b3
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x103615
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)