// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/mscompress.c
// Function: mslzh_read_huffman_tree
static void mslzh_read_huffman_tree(struct mslzh_context *lzhctx, UI idx)
{
	UI i;
	int saved_indent_level;
	deark *c = lzhctx->c;
	struct mslzh_tree *htr = &lzhctx->htree[idx];
	char tmps[32];

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(lzhctx->c, "huffman tree #%u at %s, nsyms=%u, enctype=%u",
		idx, de_bitreader_describe_curpos(&lzhctx->bitrd, tmps, sizeof(tmps)),
		htr->num_symbols, htr->enctype);
	de_dbg_indent(c, 1);

	htr->symlengths = de_mallocarray(c, htr->num_symbols, sizeof(htr->symlengths[0]));

	switch(htr->enctype) {
	case 0:
		mslzh_read_huffman_tree_enctype_0(lzhctx, htr);
		break;
	case 1:
		mslzh_read_huffman_tree_enctype_1(lzhctx, htr);
		break;
	case 2:
		mslzh_read_huffman_tree_enctype_2(lzhctx, htr);
		break;
	case 3:
		mslzh_read_huffman_tree_enctype_3(lzhctx, htr);
		break;
	default:
		mslzh_set_errorflag(lzhctx);
	}

	if(lzhctx->bitrd.eof_flag) {
		mslzh_set_errorflag(lzhctx);
		goto done;
	}

	for(i=0; i<htr->num_symbols; i++) {
		de_dbg2(c, "length[%u] = %u", i, (UI)htr->symlengths[i]);
		fmtutil_huffman_record_a_code_length(c, htr->fmtuht->builder, (fmtutil_huffman_valtype)i,
			(UI)htr->symlengths[i]);
	}

	if(!fmtutil_huffman_make_canonical_code(c, htr->fmtuht->bk, htr->fmtuht->builder, 0, NULL)) {
		de_dfilter_set_errorf(c, lzhctx->dres, lzhctx->modname, "Failed to construct Huffman tree");
		mslzh_set_errorflag(lzhctx);
		goto done;
	}

	if(c->debug_level>=4) {
		fmtutil_huffman_dump(c, htr->fmtuht);
	}

done:
	de_free(c, htr->symlengths);
	htr->symlengths = NULL;
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq 0x68(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq (%rdi), %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x5c(%rbp)
addq $0x20, %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x16a540
movq -0x68(%rbp), %rdi
movl -0x5c(%rbp), %edx
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl (%rax), %r9d
movl 0x4(%rax), %r8d
leaq 0xd9e88(%rip), %rsi     # 0x1bcd82
xorl %eax, %eax
callq 0x15b0d0
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x58(%rbp)
subq $0x3, %rax
ja 0xe2f91
movq -0x58(%rbp), %rax
leaq 0xd9bc4(%rip), %rcx     # 0x1bcb10
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe32e0
jmp 0xe2f9a
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe3340
jmp 0xe2f9a
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe3440
jmp 0xe2f9a
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe3520
jmp 0xe2f9a
movq -0x8(%rbp), %rdi
callq 0xe2e60
movq -0x8(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xe2fb2
movq -0x8(%rbp), %rdi
callq 0xe2e60
jmp 0xe3091
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xe301b
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %ecx
leaq 0xf40c0(%rip), %rsi     # 0x1d70a2
movb $0x0, %al
callq 0x15b350
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rsi
movl -0x10(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x10(%rbp), %ecx
movzbl (%rax,%rcx), %ecx
callq 0x187f20
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xe2fb9
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x188020
cmpl $0x0, %eax
jne 0xe3075
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdx
leaq 0xd9d4c(%rip), %rcx     # 0x1bcdaf
movb $0x0, %al
callq 0x177450
movq -0x8(%rbp), %rdi
callq 0xe2e60
jmp 0xe3091
movq -0x20(%rbp), %rax
cmpl $0x4, (%rax)
jl 0xe308f
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x187cc0
jmp 0xe3091
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15b820
movq -0x28(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x15b5a0
addq $0x70, %rsp
popq %rbp
retq