// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-lzh.c
// Function: lh5x_read_offsets_tree
static int lh5x_read_offsets_tree(struct lzh_ctx *cctx, struct lzh_tree_wrapper *tree,
	const char *name)
{
	deark *c = cctx->c;
	UI ncodes;
	UI curr_idx;
	int retval = 0;
	int saved_indent_level;
	char pos_descr[32];

	de_dbg_indent_save(c, &saved_indent_level);
	de_bitreader_describe_curpos(&cctx->bitrd, pos_descr, sizeof(pos_descr));
	de_dbg2(c, "%s tree at %s", name, pos_descr);
	de_dbg_indent(c, 1);

	ncodes = (UI)lzh_getbits(cctx, cctx->lh5x_offsets_tree_fields_nbits);
	de_dbg2(c, "num codes in %s tree: %u", name, ncodes);

	if(ncodes>cctx->lh5x_offsets_tree_max_codes) {
		goto done;
	}

	tree->ht = fmtutil_huffman_create_decoder(c, (i64)ncodes, (i64)ncodes);

	if(ncodes==0) {
		UI null_val;

		null_val = (UI)lzh_getbits(cctx, cctx->lh5x_offsets_tree_fields_nbits);
		de_dbg3(c, "val0: %u", null_val);
		if(null_val >= cctx->lh5x_offsets_tree_max_codes) goto done;
		fmtutil_huffman_add_code(c, tree->ht->bk, 0, 0, (fmtutil_huffman_valtype)null_val);
		retval = 1;
		goto done;
	}

	curr_idx = 0;
	while(curr_idx < ncodes) {
		UI symlen;

		symlen = lh5x_read_a_code_length(cctx);
		de_dbg3(c, "len[%u] = %u", curr_idx, symlen);
		fmtutil_huffman_record_a_code_length(c, tree->ht->builder, (fmtutil_huffman_valtype)curr_idx, symlen);
		curr_idx++;
	}
	if(cctx->bitrd.eof_flag) goto done;

	if(!fmtutil_huffman_make_canonical_code(c, tree->ht->bk, tree->ht->builder, 0, NULL)) goto done;

	retval = 1;
done:
	if(!retval) {
		lzh_set_err_flag(cctx);
	}
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x16a540
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq 0x54cd8(%rip), %rsi     # 0x1d6e74
movb $0x0, %al
callq 0x15b350
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x84(%rax), %esi
callq 0x181a10
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x24(%rbp), %ecx
leaq 0x54ca9(%rip), %rsi     # 0x1d6e82
movb $0x0, %al
callq 0x15b350
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x88(%rcx), %eax
jbe 0x1821f4
jmp 0x182318
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
movl -0x24(%rbp), %eax
movl %eax, %edx
callq 0x188560
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x24(%rbp)
jne 0x182280
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x84(%rax), %esi
callq 0x181a10
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0x27b99(%rip), %rsi     # 0x1a9dd4
movb $0x0, %al
callq 0x15b400
movl -0x54(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x88(%rcx), %eax
jb 0x182256
jmp 0x182318
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
movl -0x54(%rbp), %r8d
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x187720
movl $0x1, -0x2c(%rbp)
jmp 0x182318
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x1822d8
movq -0x8(%rbp), %rdi
callq 0x182340
movl %eax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x58(%rbp), %ecx
leaq 0x27b31(%rip), %rsi     # 0x1a9ddd
movb $0x0, %al
callq 0x15b400
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rsi
movl -0x28(%rbp), %edx
movl -0x58(%rbp), %ecx
callq 0x187f20
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x182287
movq -0x8(%rbp), %rax
cmpb $0x0, 0x50(%rax)
je 0x1822e4
jmp 0x182318
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x188020
cmpl $0x0, %eax
jne 0x182311
jmp 0x182318
movl $0x1, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x182327
movq -0x8(%rbp), %rdi
callq 0x1823c0
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x15b5a0
movl -0x2c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)