// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/colorix.c
// Function: do_colorix_image_RIX3
static void do_colorix_image_RIX3(deark *c, struct colorix_ctx *d, i64 pos1)
{
	de_bitmap *img = NULL;
	dbuf *unc_pixels = 0;
	dbuf *final_pixels_dbuf; // copy of pointer; do not free
	i64 final_pixels_pos;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "image at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	if(!de_good_image_dimensions(c, d->width, d->height)) goto done;

	if(d->imgtype==4) {
		d->rowspan = de_pad_to_n(d->width, 8) / 2;
	}
	else {
		d->rowspan = d->width;
	}
	if(d->rowspan<1) goto done;

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

	if(d->is_compressed) {
		unc_pixels = dbuf_create_membuf(c, d->unc_image_size+256, 0);
		if(!do_colorix_decompress(c, d, pos1, unc_pixels)) {
			goto done;
		}
		final_pixels_dbuf = unc_pixels;
		final_pixels_pos = 0;
	}
	else {
		final_pixels_dbuf = c->infile;
		final_pixels_pos = pos1;
	}

	if(d->imgtype==4) {
		de_convert_image_paletted_planar(final_pixels_dbuf, final_pixels_pos, 4,
			d->rowspan, d->rowspan/4, d->pal, img, 0x2);
	}
	else { // assume 0
		de_convert_image_paletted(final_pixels_dbuf, final_pixels_pos, 8,
			d->rowspan, d->pal, img, 0);
	}

	de_bitmap_write_to_file(img, NULL, DE_CREATEFLAG_OPT_IMAGE);

done:
	de_bitmap_destroy(img);
	dbuf_close(unc_pixels);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x151cae(%rip), %rsi    # 0x1ba32e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
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 0x686b8
jmp 0x6884e
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x4, %eax
jne 0x686ee
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movl $0x8, %esi
callq 0x15ce90
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x686fe
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jge 0x6870e
jmp 0x6884e
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
imulq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
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, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x7(%rax)
je 0x687a2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
addq $0x100, %rsi            # imm = 0x100
xorl %edx, %edx
callq 0x168020
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x68880
cmpl $0x0, %eax
jne 0x68790
jmp 0x6884e
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
jmp 0x687b6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x4, %eax
jne 0x6880d
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x4, %r8d
cqto
idivq %r8
movq %rax, %r8
movq -0x10(%rbp), %r9
addq $0x40, %r9
movq -0x20(%rbp), %rax
movl $0x4, %edx
movq %rax, (%rsp)
movl $0x2, 0x8(%rsp)
callq 0x16c690
jmp 0x6883c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %r8
addq $0x40, %r8
movq -0x20(%rbp), %r9
movl $0x8, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x16afd0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x28(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)