// File: /workspace/github_c_makefile_star2_O0/wkoszek[P]mini_gzip/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 0xb656
jmp 0xb8e9
cmpl $0x1, -0xc(%rbp)
jne 0xb66a
movq -0x8(%rbp), %rax
movw $0x1, (%rax)
jmp 0xb8e9
jmp 0xb66c
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 0xb7d8
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xb6ca
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 0xb700
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 0xb722
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 0xb74e
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xb795
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 0xb795
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 0xb7c8
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 0xb7ca
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb695
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 0xb82b
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 0xb7f4
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 0xb8e9
jmp 0xb85e
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x25(%rbp)
jl 0xb87e
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 0xb887
jmp 0xb89b
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xb85e
jmp 0xb89d
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jle 0xb8cc
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 0xb89d
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 0xb852
popq %rbp
retq
nopl (%rax,%rax)