// File: /workspace/github_c_makefile_star2_O3/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:
cmpb $0x0, 0x30(%rdi)
je 0x4b1fa
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rsi, %r13
movq %rdi, %rbx
cmpl $0x31, %ecx
movl $0x30, %eax
cmovael %ecx, %eax
movl %eax, 0x14(%rsp)
movq 0x88(%rbx), %rax
cmpq %r13, %rax
jg 0x4b33e
leaq 0x2(%r13), %r15
addq 0x90(%rbx), %rax
cmpq %rax, %r15
jg 0x4b33e
cmpl %ebp, 0x14(%rsp)
je 0x4b342
movq %rdx, 0x8(%rsp)
movq 0x10(%rbx), %rax
movq (%rax), %rdi
movq %r13, %rsi
callq 0xeebc8
movq %rax, %r14
movq (%rbx), %rdi
movzwl %r14w, %r12d
leaq 0xd31e1(%rip), %rsi     # 0x11e453
movq %r13, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe87e4
testb $0x1, %r14b
jne 0x4b2c9
leal -0x2(%r12), %eax
cmpl $0xffd, %eax            # imm = 0xFFD
ja 0x4b2c9
movq 0x8(%rsp), %r12
leaq 0x1(,%r12,2), %rdx
incl %ebp
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %ecx
callq 0x4b1f3
cmpb $0x0, 0x30(%rbx)
jne 0x4b342
movq %r12, %rdx
addq %r12, %rdx
movzwl %r14w, %r13d
addq %r15, %r13
jmp 0x4b21f
andl $0xff00, %r14d          # imm = 0xFF00
cmpl $0x1000, %r14d          # imm = 0x1000
movq 0x8(%rsp), %rdx
jne 0x4b33e
addl $0xfffff000, %r12d      # imm = 0xFFFFF000
movq (%rbx), %r14
cmpl $0x3, (%r14)
jl 0x4b325
leaq 0x9e(%rbx), %rdi
movl $0x48, %esi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
callq 0xe9d03
leaq 0xd3157(%rip), %rsi     # 0x11e464
movq %r14, %rdi
movq %rax, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe889f
movq 0x8(%rsp), %rdx
movq (%rbx), %r14
movq 0x50(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdi
movl %ebp, %ecx
movl %r12d, %r8d
callq 0x1044c1
testl %eax, %eax
jne 0x4b342
movb $0x1, 0x30(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)