// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x690a6
jmp 0x6926f
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x88(%rcx), %rax
jl 0x690da
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq -0x8(%rbp), %rcx
movq 0x88(%rcx), %rcx
movq -0x8(%rbp), %rdx
addq 0x90(%rdx), %rcx
cmpq %rcx, %rax
jle 0x690e7
movq -0x8(%rbp), %rax
movb $0x1, 0x30(%rax)
jmp 0x6926f
cmpl $0x30, -0x1c(%rbp)
jb 0x690f2
jmp 0x6926f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x165280
movw %ax, -0x1e(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movzwl -0x1e(%rbp), %ecx
leaq 0x140ee3(%rip), %rsi    # 0x1aa003
movb $0x0, %al
callq 0x15b350
movzwl -0x1e(%rbp), %eax
cmpl $0x2, %eax
jl 0x691ba
movzwl -0x1e(%rbp), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0x691ba
movzwl -0x1e(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x691ba
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x2, %rsi
movq -0x18(%rbp), %rdx
shlq %rdx
orq $0x1, %rdx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x69080
movq -0x8(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x69181
jmp 0x6926f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x2, %rsi
movzwl -0x1e(%rbp), %eax
addq %rax, %rsi
movq -0x18(%rbp), %rdx
shlq %rdx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x69080
movq -0x8(%rbp), %rax
cmpb $0x0, 0x30(%rax)
je 0x691b5
jmp 0x6926f
jmp 0x6926d
movzwl -0x1e(%rbp), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jl 0x69261
movzwl -0x1e(%rbp), %eax
cmpl $0x10ff, %eax           # imm = 0x10FF
jg 0x69261
movzwl -0x1e(%rbp), %eax
subl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
cmpl $0x3, (%rax)
jl 0x6922f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x9e, %rdi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl $0x48, %esi
callq 0x15cf60
movq -0x30(%rbp), %rdi
movq %rax, %rdx
movl -0x24(%rbp), %ecx
leaq 0x140dec(%rip), %rsi    # 0x1aa014
movb $0x0, %al
callq 0x15b400
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x24(%rbp), %r8d
callq 0x187720
cmpl $0x0, %eax
jne 0x6925f
movq -0x8(%rbp), %rax
movb $0x1, 0x30(%rax)
jmp 0x6926b
movq -0x8(%rbp), %rax
movb $0x1, 0x30(%rax)
jmp 0x6926f
jmp 0x6926d
jmp 0x6926f
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)