// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/colorix.c
// Function: do_colorix_RIX3
static void do_colorix_RIX3(deark *c, struct colorix_ctx *d)
{
	i64 pos;

	pos = 4;
	d->width = de_getu16le_p(&pos);
	d->height = de_getu16le_p(&pos);
	de_dbg_dimensions(c, d->width, d->height);

	d->paltype = de_getbyte_p(&pos);
	de_dbg(c, "palette type: 0x%02x", (UI)d->paltype);
	if(d->paltype!=0xab && d->paltype!=0xaf) {
		de_err(c, "Unsupported palette type: 0x%02x", (UI)d->paltype);
		goto done;
	}

	d->stgtype = de_getbyte_p(&pos);
	de_dbg(c, "storage type: 0x%02x", (UI)d->stgtype);

	if(d->stgtype & 0x80) d->is_compressed = 1;
	if(d->stgtype & 0x40) d->has_extension_block = 1;
	if(d->stgtype & 0x20) d->is_encrypted = 1;
	d->imgtype = d->stgtype & 0x0f; // I guess?
	de_dbg_indent(c, 1);
	de_dbg(c, "image type: %u", d->imgtype);
	de_dbg_indent(c, -1);
	declare_colorix_fmt(c, d);

	if(d->is_encrypted) {
		de_err(c, "Encrypted files not supported");
		goto done;
	}

	if(d->has_extension_block) {
		i64 e_len;

		e_len = de_getu16le_p(&pos);
		de_dbg(c, "extension block: dpos=%"I64_FMT", dlen=%"I64_FMT, pos, e_len);
		// I've found no files with extension blocks, so no reason to parse them.
		pos += e_len;
	}

	read_colorix_palette(c, d, pos);
	pos += d->pal_nbytes;

	if(d->imgtype==0 || d->imgtype==4) {
		;
	}
	else {
		de_err(c, "Unsupported image type: 0x%02x", (UI)d->stgtype);
		goto done;
	}

	do_colorix_image_RIX3(c, d, pos);
done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x4, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1652c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x4(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %edx
leaq 0x141f96(%rip), %rsi    # 0x1a9e7c
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0xab, %eax
je 0x67f2a
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0xaf, %eax
je 0x67f2a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %edx
leaq 0x141f52(%rip), %rsi    # 0x1a9e70
movb $0x0, %al
callq 0x15bfb0
jmp 0x680cf
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x165170
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x5(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %edx
leaq 0x13909a(%rip), %rsi    # 0x1a0ff1
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x67f78
movq -0x10(%rbp), %rax
movb $0x1, 0x7(%rax)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x67f90
movq -0x10(%rbp), %rax
movb $0x1, 0x9(%rax)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x67fa8
movq -0x10(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
andl $0xf, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x6(%rax)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %edx
leaq 0x15e089(%rip), %rsi    # 0x1c6066
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x68510
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
je 0x68020
movq -0x8(%rbp), %rdi
leaq 0x141e7d(%rip), %rsi    # 0x1a9e91
movb $0x0, %al
callq 0x15bfb0
jmp 0x680cf
movq -0x10(%rbp), %rax
cmpb $0x0, 0x9(%rax)
je 0x68065
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x141e5d(%rip), %rsi    # 0x1a9eaf
movb $0x0, %al
callq 0x15b0d0
movq -0x20(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x68570
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x0, %eax
je 0x680a0
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x4, %eax
jne 0x680a2
jmp 0x680be
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %edx
leaq 0x141e1e(%rip), %rsi    # 0x1a9ed3
movb $0x0, %al
callq 0x15bfb0
jmp 0x680cf
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x68640
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)