// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/riff.c
// Function: do_palette
static void do_palette(deark *c, lctx *d, struct de_iffctx *ictx, i64 pos, i64 len)
{
	i64 ver;
	i64 n;
	i64 i;
	u8 r,g,b,flags;
	u32 clr;
	char tmps[32];

	if(!ictx->is_le) return;
	ver = de_getu16le(pos);
	de_dbg(c, "version: 0x%04x", (unsigned int)ver);
	pos += 2;
	n = de_getu16le(pos);
	de_dbg(c, "number of entries: %d", (int)n);
	pos += 2;
	if(n>(len-4)/4) n=(len-4)/4;
	if(n>1024) n=1024;
	if(n<1) return;

	de_dbg(c, "palette entries at %d", (int)pos);
	de_dbg_indent(c, 1);
	for(i=0; i<n; i++) {
		r = de_getbyte(pos);
		g = de_getbyte(pos+1);
		b = de_getbyte(pos+2);
		flags = de_getbyte(pos+3);
		pos += 4;
		clr = DE_MAKE_RGB(r, g, b);
		de_snprintf(tmps, sizeof(tmps), " flags=0x%02x", (unsigned int)flags);
		de_dbg_pal_entry2(c, i, clr, NULL, NULL, tmps);
	}
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x58(%rax)
jne 0x11fb8e
jmp 0x11fd72
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0xa128f(%rip), %rsi     # 0x1c0e43
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x82cad(%rip), %rsi     # 0x1a289a
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
subq $0x4, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jle 0x11fc3c
movq -0x28(%rbp), %rax
subq $0x4, %rax
movl $0x4, %ecx
cqto
idivq %rcx
movq %rax, -0x38(%rbp)
cmpq $0x400, -0x38(%rbp)     # imm = 0x400
jle 0x11fc4e
movq $0x400, -0x38(%rbp)     # imm = 0x400
cmpq $0x1, -0x38(%rbp)
jge 0x11fc5a
jmp 0x11fd72
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xa60b7(%rip), %rsi     # 0x1c5d22
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x11fd64
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x165060
movb %al, -0x41(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x1, %rsi
callq 0x165060
movb %al, -0x42(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2, %rsi
callq 0x165060
movb %al, -0x43(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x3, %rsi
callq 0x165060
movb %al, -0x44(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movzbl -0x41(%rbp), %eax
shll $0x10, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movzbl -0x42(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x43(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x48(%rbp)
leaq -0x70(%rbp), %rdi
movzbl -0x44(%rbp), %ecx
movl $0x20, %esi
leaq 0x89ded(%rip), %rdx     # 0x1a9b1d
movb $0x0, %al
callq 0x15a980
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x48(%rbp), %edx
leaq -0x70(%rbp), %r9
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x15bdb0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x11fc88
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)