// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tim.c
// Function: do_pal8
static void do_pal8(deark *c, lctx *d)
{
	de_bitmap *img = NULL;
	i64 clut_size;
	i64 ncolors_per_clut;
	i64 num_cluts;
	i64 second_header_blk_pos;
	i64 img_data_size_field;
	i64 width_field;
	i64 rowspan;
	i64 pos;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg_indent(c, 1); // still in the first header block

	if(!d->palette_flag) {
		de_err(c, "8-bit images without a palette aren't supported");
		goto done;
	}

	clut_size = de_getu32le(8);

	ncolors_per_clut = de_getu16le(16);
	num_cluts = de_getu16le(18);

	de_dbg(c, "clut 'size': %d", (int)clut_size);
	de_dbg(c, "colors per clut: %d", (int)ncolors_per_clut);
	de_dbg(c, "num cluts: %d", (int)num_cluts);
	de_dbg_indent(c, -1); // end of first header block

	do_read_palette(c, d, 20, ncolors_per_clut);

	second_header_blk_pos = 20 + num_cluts*ncolors_per_clut*2;
	de_dbg(c, "second header block at %d", (int)second_header_blk_pos);
	de_dbg_indent(c, 1);
	img_data_size_field = de_getu32le(second_header_blk_pos);
	de_dbg(c, "image data size field: %d", (int)img_data_size_field);
	width_field = de_getu16le(second_header_blk_pos+8);
	d->width = 2*width_field;
	d->height = de_getu16le(second_header_blk_pos+10);
	de_dbg(c, "width field: %d (width=%d)", (int)width_field, (int)d->width);
	de_dbg(c, "height: %d", (int)d->height);
	if(!de_good_image_dimensions(c, d->width, d->height)) goto done;
	de_dbg_indent(c, -1);

	img = de_bitmap_create(c, d->width, d->height, 3);

	pos = second_header_blk_pos + 12;
	de_dbg(c, "image data block at %d", (int)pos);
	rowspan = d->width;

	de_convert_image_paletted(c->infile, pos,
		8, rowspan, d->pal, img, 0);

	de_bitmap_write_to_file(img, NULL, 0);
done:
	de_dbg_indent_restore(c, saved_indent_level);
	de_bitmap_destroy(img);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x135f74
movq -0x8(%rbp), %rdi
leaq 0x95b08(%rip), %rsi     # 0x1cba70
movb $0x0, %al
callq 0x15bfb0
jmp 0x1361d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x8, %esi
callq 0x165540
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x10, %esi
callq 0x165280
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x12, %esi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x95ad9(%rip), %rsi     # 0x1cbaa0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x95ad1(%rip), %rsi     # 0x1cbab0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0x95acd(%rip), %rsi     # 0x1cbac4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl $0x14, %edx
callq 0x1361f0
movq -0x30(%rbp), %rax
imulq -0x28(%rbp), %rax
shlq %rax
addq $0x14, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x95a8b(%rip), %rsi     # 0x1cbad2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x165540
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x95a6a(%rip), %rsi     # 0x1cbaec
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
callq 0x165280
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rcx
shlq %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
addq $0xa, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
leaq 0x95a1a(%rip), %rsi     # 0x1cbb06
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x6ce6f(%rip), %rsi     # 0x1a2f77
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x136132
jmp 0x1361d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x18(%rbp)
movq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
leaq 0x959a2(%rip), %rsi     # 0x1cbb21
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rcx
movq -0x10(%rbp), %r8
addq $0x20, %r8
movq -0x18(%rbp), %r9
movl $0x8, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x16afd0
movq -0x8(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x15b5a0
movq -0x18(%rbp), %rdi
callq 0x16af60
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)