// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-huffman.c
// Function: fmtutil_huffman_make_canonical_tree2
static int fmtutil_huffman_make_canonical_tree2(deark *c, struct fmtutil_huffman_codebook *bk,
	struct fmtutil_huffman_code_builder *builder, UI max_sym_len_used)
{
	UI symlen;
	UI codes_count_total = 0;
	UI prev_code_bit_length = 0;
	u64 prev_code = 0;
	int retval = 0;
	char b2buf[72];

	// For each possible symbol length...
	for(symlen=max_sym_len_used; symlen>=1; symlen--) {
		UI k;

		// Find all the codes that use this symbol length, in order
		for(k=0; k<(UI)builder->lengths_arr_numused; k++) {
			int ret;
			u64 this_code;

			if(builder->lengths_arr[k].len != symlen) continue;
			// Found a code of the length we're looking for.

			if(codes_count_total==0) {
				this_code = 0;
			}
			else  {
				this_code = (prev_code>>(prev_code_bit_length-symlen)) + 1;
			}

			prev_code = this_code;
			prev_code_bit_length = symlen;
			codes_count_total++;

			if(c->debug_level>=3) {
				de_dbg3(c, "code: \"%s\" = %d",
					de_print_base2_fixed(b2buf, sizeof(b2buf), this_code, symlen),
					(int)builder->lengths_arr[k].val);
			}
			ret = fmtutil_huffman_add_code(c, bk, this_code, symlen, builder->lengths_arr[k].val);
			if(!ret) {
				goto done;
			}
		}
	}
	retval = 1;

done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x1, -0x20(%rbp)
jb 0x188390
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl %ecx, %eax
jae 0x188380
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x84(%rbp), %ecx
movl 0x4(%rax,%rcx,8), %eax
cmpl -0x20(%rbp), %eax
je 0x188293
jmp 0x18836c
cmpl $0x0, -0x24(%rbp)
jne 0x1882a6
movq $0x0, -0x90(%rbp)
jmp 0x1882c0
movq -0x30(%rbp), %rax
movl -0x28(%rbp), %ecx
subl -0x20(%rbp), %ecx
movl %ecx, %ecx
shrq %cl, %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x3, (%rax)
jl 0x18832f
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x80(%rbp), %rdi
movq -0x90(%rbp), %rdx
movl -0x20(%rbp), %ecx
movl $0x48, %esi
callq 0x15cf60
movq -0x98(%rbp), %rdi
movq %rax, %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,8), %ecx
leaq 0x21cec(%rip), %rsi     # 0x1aa014
movb $0x0, %al
callq 0x15b400
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x90(%rbp), %rdx
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x84(%rbp), %r8d
movl (%rax,%r8,8), %r8d
callq 0x187720
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
jne 0x18836a
jmp 0x188397
jmp 0x18836c
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x188261
jmp 0x188382
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x18824d
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)