// File: Alcaro[P]bridges/arlib/deps/miniz.c
// Function: tdefl_calculate_minimum_redundancy
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 0x621b6
jmp 0x62449
cmpl $0x1, -0xc(%rbp)
jne 0x621ca
movq -0x8(%rbp), %rax
movw $0x1, (%rax)
jmp 0x62449
jmp 0x621cc
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 0x62338
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x6222a
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 0x62260
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 0x62282
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 0x622ae
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x622f5
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 0x622f5
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 0x62328
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 0x6232a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x621f5
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 0x6238b
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 0x62354
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 0x62449
jmp 0x623be
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x25(%rbp)
jl 0x623de
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 0x623e7
jmp 0x623fb
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x623be
jmp 0x623fd
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0x6242c
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 0x623fd
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 0x623b2
popq %rbp
retq
nopl (%rax,%rax)