// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/colorix.c
// Function: rixdecomp_interpret_nodetable_item
static void rixdecomp_interpret_nodetable_item(struct rixdecomp_ctx *rhctx,
	i64 itempos, u64 currcode, UI currcode_nbits)
{
	u16 dval;

	if(rhctx->errflag) return;
	if((itempos < rhctx->nodetable_dpos) ||
		(itempos+2 > rhctx->nodetable_dpos+rhctx->nodetable_dlen))
	{
		rhctx->errflag = 1;
		return;
	}
	if(currcode_nbits>=FMTUTIL_HUFFMAN_MAX_CODE_LENGTH) return;

	dval = (u16)dbuf_getu16le(rhctx->dcmpri->f, itempos);
	de_dbg2(rhctx->c, "item@%"I64_FMT": 0x%04x", itempos, (UI)dval);

	if(dval>=2 && dval<0x1000 && (dval%2==0)) { // a "pointer" item
		// The very next item is the start of the "1" subtree.
		rixdecomp_interpret_nodetable_item(rhctx, itempos+2, ((currcode<<1) | 1), currcode_nbits+1);
		if(rhctx->errflag) goto done;

		// The pointer item tells how many bytes are between the pointer item
		// and the start of the "0" subtree.
		rixdecomp_interpret_nodetable_item(rhctx, itempos+2+(i64)dval, currcode<<1, currcode_nbits+1);
		if(rhctx->errflag) goto done;
	}
	else if(dval>=0x1000 && dval<=0x10ff) { // a leaf item
		fmtutil_huffman_valtype adj_value;

		adj_value = (fmtutil_huffman_valtype)(dval-0x1000);
		if(rhctx->c->debug_level>=3) {
			de_dbg3(rhctx->c, "code: \"%s\" = %d",
				de_print_base2_fixed(rhctx->tmpbuf, sizeof(rhctx->tmpbuf), currcode, currcode_nbits),
				(int)adj_value);
		}
		if(!fmtutil_huffman_add_code(rhctx->c, rhctx->ht->bk, currcode, currcode_nbits, adj_value)) {
			rhctx->errflag = 1;
		}
	}
	else {
		rhctx->errflag = 1;
		goto done;
	}

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r15
cmpb $0x0, 0x30(%rdi)
sete %al
movq %rdi, (%rsp)
testb $0x1, %al
je 0x48f79
movq 0x88(%rdi), %rax
cmpq %r15, %rax
jg 0x48f75
leaq 0x2(%r15), %r13
addq 0x90(%rdi), %rax
cmpq %rax, %r13
jg 0x48f75
cmpl $0x2f, %ebp
ja 0x48f79
movq 0x10(%rdi), %rax
movq %rdi, %r12
movq (%rax), %rdi
movq %r15, %rsi
callq 0xe3fa3
movq %rax, %r14
movq (%r12), %rdi
movzwl %r14w, %r12d
leaq 0xc84e2(%rip), %rsi     # 0x11137f
movq %r15, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xde9f1
testb $0x1, %r14b
jne 0x48ef6
leal -0x2(%r12), %eax
cmpl $0xffd, %eax            # imm = 0xFFD
ja 0x48ef6
leaq 0x1(,%rbx,2), %rdx
incl %ebp
movq (%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
movl %ebp, %ecx
callq 0x48e26
cmpb $0x0, 0x30(%r15)
jne 0x48f79
movq %r15, %rdi
addq %rbx, %rbx
movzwl %r14w, %r15d
addq %r13, %r15
movb $0x1, %al
jmp 0x48e44
andl $0xff00, %r14d          # imm = 0xFF00
cmpl $0x1000, %r14d          # imm = 0x1000
movq (%rsp), %rdi
jne 0x48f75
addl $0xfffff000, %r12d      # imm = 0xFFFFF000
movq (%rdi), %r14
cmpl $0x3, (%r14)
jl 0x48f55
movq (%rsp), %rax
leaq 0x9e(%rax), %rdi
pushq $0x48
popq %rsi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xdfc03
leaq 0xc8457(%rip), %rsi     # 0x111390
movq %r14, %rdi
movq %rax, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xdea83
movq (%rsp), %rdi
movq %rbx, %rdx
movq (%rdi), %r14
jmp 0x48f58
movq %rbx, %rdx
movq 0x50(%rdi), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdi
movl %ebp, %ecx
movl %r12d, %r8d
callq 0xf7e56
movq (%rsp), %rdi
testl %eax, %eax
jne 0x48f79
movb $0x1, 0x30(%rdi)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq