// File: jimmiebergmann[P]fbx-file/miniz.c
// Function: tdefl_calculate_minimum_redundancy(tdefl_sym_freq*, int)
static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n)
{
    int root, leaf, next, avbl, used, dpth;
    if (n == 0)
        return;
    else if (n == 1)
    {
        A[0].m_key = 1;
        return;
    }
    A[0].m_key += A[1].m_key;
    root = 0;
    leaf = 2;
    for (next = 1; next < n - 1; next++)
    {
        if (leaf >= n || A[root].m_key < A[leaf].m_key)
        {
            A[next].m_key = A[root].m_key;
            A[root++].m_key = (mz_uint16)next;
        }
        else
            A[next].m_key = A[leaf++].m_key;
        if (leaf >= n || (root < next && A[root].m_key < A[leaf].m_key))
        {
            A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key);
            A[root++].m_key = (mz_uint16)next;
        }
        else
            A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key);
    }
    A[n - 2].m_key = 0;
    for (next = n - 3; next >= 0; next--)
        A[next].m_key = A[A[next].m_key].m_key + 1;
    avbl = 1;
    used = dpth = 0;
    root = n - 2;
    next = n - 1;
    while (avbl > 0)
    {
        while (root >= 0 && (int)A[root].m_key == dpth)
        {
            used++;
            root--;
        }
        while (avbl > used)
        {
            A[next--].m_key = (mz_uint16)(dpth);
            avbl--;
        }
        avbl = 2 * used;
        dpth++;
        used = 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x1f016
jmp 0x1f2a9
cmpl $0x1, -0xc(%rbp)
jne 0x1f02a
movq -0x8(%rbp), %rax
movw $0x1, (%rax)
jmp 0x1f2a9
jmp 0x1f02c
movq -0x8(%rbp), %rax
movzwl 0x4(%rax), %edx
movq -0x8(%rbp), %rax
movzwl (%rax), %ecx
addl %edx, %ecx
movw %cx, (%rax)
movl $0x0, -0x10(%rbp)
movl $0x2, -0x14(%rbp)
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1f198
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x1f08a
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jge 0x1f0c0
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movw (%rax,%rcx,4), %dx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movw %dx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x10(%rbp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,4)
jmp 0x1f0e2
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x14(%rbp)
movslq %ecx, %rcx
movw (%rax,%rcx,4), %dx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movw %dx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x1f10e
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x1f155
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movzwl (%rcx,%rdx,4), %ecx
cmpl %ecx, %eax
jge 0x1f155
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movzwl (%rcx,%rdx,4), %ecx
addl %ecx, %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movw %dx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x10(%rbp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,4)
jmp 0x1f188
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,4), %eax
movq -0x8(%rbp), %rcx
movl -0x14(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %edx, %rdx
movzwl (%rcx,%rdx,4), %ecx
addl %ecx, %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movw %dx, (%rax,%rcx,4)
jmp 0x1f18a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1f055
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movw $0x0, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x1f1eb
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x18(%rbp), %rdx
movzwl (%rcx,%rdx,4), %ecx
movzwl (%rax,%rcx,4), %eax
addl $0x1, %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movslq -0x18(%rbp), %rcx
movw %dx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1f1b4
movl $0x1, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x1f2a9
jmp 0x1f21e
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x25(%rbp)
jl 0x1f23e
movq -0x8(%rbp), %rax
movslq -0x10(%rbp), %rcx
movzwl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
sete %al
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %al
testb $0x1, %al
jne 0x1f247
jmp 0x1f25b
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1f21e
jmp 0x1f25d
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x1f28c
movl -0x24(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %esi
addl $-0x1, %esi
movl %esi, -0x18(%rbp)
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1f25d
movl -0x20(%rbp), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
jmp 0x1f212
popq %rbp
retq
nopl (%rax,%rax)