// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jovianvi.c
// Function: do_read_palette
static void do_read_palette(deark *c, lctx *d)
{
	i64 k, z;
	i64 idx;
	u8 b1[3];
	u8 b2[3];

	de_dbg(c, "palette at %d", (int)d->palpos);
	de_dbg_indent(c, 1);

	for(k=0; k<d->num_pal_colors; k++) {
		idx = d->pal_first_entry_idx + k;
		if(idx > 255) break;

		de_read(b1, d->palpos + 3*k, 3);
		for(z=0; z<3; z++) {
			if(d->pal_code==0) {
				b2[z] = de_scale_63_to_255(b1[z]); // 6-bit palette samples
			}
			else {
				b2[z] = b1[z]; // 8-bit palette samples
			}
		}

		d->pal[idx] = DE_MAKE_RGB(b2[0],b2[1],b2[2]);

		if(d->pal_code==0) {
			char tmps[64];
			de_snprintf(tmps, sizeof(tmps), "(%2d,%2d,%2d) "DE_CHAR_RIGHTARROW" ",
				(int)b1[0], (int)b1[1], (int)b1[2]);
			de_dbg_pal_entry2(c, k, d->pal[idx], tmps, NULL, NULL);
		}
		else {
			de_dbg_pal_entry(c, k, d->pal[idx]);
		}
	}

	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %edx
leaq 0x100dfb(%rip), %rsi    # 0x1bbf50
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jge 0xbb2cc
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0xff, -0x28(%rbp)
jle 0xbb1a3
jmp 0xbb2cc
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x2b(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
imulq $0x3, -0x18(%rbp), %rax
addq %rax, %rdx
movl $0x3, %ecx
callq 0x164d10
movq $0x0, -0x20(%rbp)
cmpq $0x3, -0x20(%rbp)
jge 0xbb21f
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0xbb1ff
movq -0x20(%rbp), %rax
movzbl -0x2b(%rbp,%rax), %edi
callq 0x161710
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, -0x2e(%rbp,%rax)
jmp 0xbb20f
movq -0x20(%rbp), %rax
movb -0x2b(%rbp,%rax), %cl
movq -0x20(%rbp), %rax
movb %cl, -0x2e(%rbp,%rax)
jmp 0xbb211
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xbb1d1
movzbl -0x2e(%rbp), %edx
shll $0x10, %edx
orl $0xff000000, %edx       # imm = 0xFF000000
movzbl -0x2d(%rbp), %eax
shll $0x8, %eax
orl %eax, %edx
movzbl -0x2c(%rbp), %eax
orl %eax, %edx
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movl %edx, 0x58(%rax,%rcx,4)
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0xbb2a0
leaq -0x70(%rbp), %rdi
movzbl -0x2b(%rbp), %ecx
movzbl -0x2a(%rbp), %r8d
movzbl -0x29(%rbp), %r9d
movl $0x40, %esi
leaq 0xe1cff(%rip), %rdx     # 0x19cf71
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x58(%rax,%rcx,4), %edx
leaq -0x70(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %r8
callq 0x15bdb0
jmp 0xbb2b9
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x58(%rax,%rcx,4), %edx
callq 0x15bf00
jmp 0xbb2bb
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xbb172
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x70, %rsp
popq %rbp
retq