// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/QV.c
// Function: Huffman
static HScheme *Huffman(uint64 *hist, HScheme *inscheme)
{ HScheme *scheme;
  HTree   *heap[259];
  HTree    node[512];
  int      hsize;
  HTree   *lft, *rgt;
  int      value, range;
  int     i;

  scheme = (HScheme *) Malloc(sizeof(HScheme),"Allocating Huffman scheme record");
  if (scheme == NULL)
    return (NULL);

  hsize = 0;                        //  Load heap
  value = 0;
  if (inscheme != NULL)
    { node[0].count = 0;
      node[0].lft   = (HTree *) (uint64) 255;
      node[0].rgt   = NULL;
      heap[++hsize] = node+(value++);
    }
  for (i = 0; i < 256; i++)
    if (hist[i] > 0)
      { if (inscheme != NULL && (inscheme->codelens[i] > HUFF_CUTOFF || i == 255))
          node[0].count += hist[i];
        else
          { node[value].count = hist[i];
            node[value].lft   = (HTree *) (uint64) i;
            node[value].rgt   = NULL;
            heap[++hsize] = node+(value++);
          }
      }

  for (i = hsize/2; i >= 1; i--)    //  Establish heap property
    Reheap(i,heap,hsize);

  range = value;                    //   Merge pairs with smallest count until have a tree
  for (i = 1; i < value; i++)
    { lft = heap[1];
      heap[1] = heap[hsize--];
      Reheap(1,heap,hsize);
      rgt = heap[1];
      node[range].lft = lft;
      node[range].rgt = rgt;
      node[range].count = lft->count + rgt->count;
      heap[1] = node+(range++);
      Reheap(1,heap,hsize);
    }

  for (i = 0; i < 256; i++)        //  Build the code table
    { scheme->codebits[i] = 0;
      scheme->codelens[i] = 0;
    }

  Build_Table(node+(range-1),0,0,scheme->codebits,scheme->codelens);

  if (inscheme != NULL)            //  Set scheme type and if truncated (2), map truncated codes
    { scheme->type = 2;            //    to code and length for 255
      for (i = 0; i < 255; i++)
        if (inscheme->codelens[i] > HUFF_CUTOFF || scheme->codelens[i] > HUFF_CUTOFF)
          { scheme->codelens[i] = scheme->codelens[255];
            scheme->codebits[i] = scheme->codebits[255];
          }
    }
  else
    { scheme->type = 0;
      for (i = 0; i < 256; i++)
        { if (scheme->codelens[i] > HUFF_CUTOFF)
            scheme->type = 1;
        }
    }

  return (scheme);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3870, %rsp           # imm = 0x3870
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x40804, %edi          # imm = 0x40804
leaq 0x47b1(%rip), %rsi      # 0xf240
callq 0x22c0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xaaac
movq $0x0, -0x8(%rbp)
jmp 0xaf58
movl $0x0, -0x3844(%rbp)
movl $0x0, -0x385c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xab23
movq $0x0, -0x3830(%rbp)
movl $0xff, %eax
movq %rax, -0x3840(%rbp)
movq $0x0, -0x3838(%rbp)
leaq -0x3840(%rbp), %rcx
movl -0x385c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x385c(%rbp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rcx
movl -0x3844(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3844(%rbp)
cltq
movq %rcx, -0x840(%rbp,%rax,8)
movl $0x0, -0x3864(%rbp)
cmpl $0x100, -0x3864(%rbp)   # imm = 0x100
jge 0xac53
movq -0x10(%rbp), %rax
movslq -0x3864(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jbe 0xac3d
cmpq $0x0, -0x18(%rbp)
je 0xab9d
movq -0x18(%rbp), %rax
movslq -0x3864(%rbp), %rcx
cmpl $0x10, 0x404(%rax,%rcx,4)
jg 0xab7b
cmpl $0xff, -0x3864(%rbp)
jne 0xab9d
movq -0x10(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x3830(%rbp), %rax
movq %rax, -0x3830(%rbp)
jmp 0xac3b
movq -0x10(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movslq -0x385c(%rbp), %rdx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movslq -0x3864(%rbp), %rcx
movslq -0x385c(%rbp), %rdx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x385c(%rbp), %rcx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
leaq -0x3840(%rbp), %rcx
movl -0x385c(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x385c(%rbp)
cltq
imulq $0x18, %rax, %rax
addq %rax, %rcx
movl -0x3844(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3844(%rbp)
cltq
movq %rcx, -0x840(%rbp,%rax,8)
jmp 0xac3d
jmp 0xac3f
movl -0x3864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xab2d
movl -0x3844(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x3864(%rbp)
cmpl $0x1, -0x3864(%rbp)
jl 0xac99
movl -0x3864(%rbp), %edi
leaq -0x840(%rbp), %rsi
movl -0x3844(%rbp), %edx
callq 0xd4c0
movl -0x3864(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xac67
movl -0x385c(%rbp), %eax
movl %eax, -0x3860(%rbp)
movl $0x1, -0x3864(%rbp)
movl -0x3864(%rbp), %eax
cmpl -0x385c(%rbp), %eax
jge 0xadd8
movq -0x838(%rbp), %rax
movq %rax, -0x3850(%rbp)
movl -0x3844(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x3844(%rbp)
cltq
movq -0x840(%rbp,%rax,8), %rax
movq %rax, -0x838(%rbp)
leaq -0x840(%rbp), %rsi
movl -0x3844(%rbp), %edx
movl $0x1, %edi
callq 0xd4c0
movq -0x838(%rbp), %rax
movq %rax, -0x3858(%rbp)
movq -0x3850(%rbp), %rcx
movslq -0x3860(%rbp), %rdx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x3858(%rbp), %rcx
movslq -0x3860(%rbp), %rdx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x3850(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x3858(%rbp), %rax
addq 0x10(%rax), %rcx
movslq -0x3860(%rbp), %rdx
leaq -0x3840(%rbp), %rax
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
leaq -0x3840(%rbp), %rax
movl -0x3860(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3860(%rbp)
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x838(%rbp)
leaq -0x840(%rbp), %rsi
movl -0x3844(%rbp), %edx
movl $0x1, %edi
callq 0xd4c0
movl -0x3864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xacaf
movl $0x0, -0x3864(%rbp)
cmpl $0x100, -0x3864(%rbp)   # imm = 0x100
jge 0xae28
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movl $0x0, 0x4(%rax,%rcx,4)
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movl $0x0, 0x404(%rax,%rcx,4)
movl -0x3864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xade2
leaq -0x3840(%rbp), %rdi
movl -0x3860(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
movq -0x20(%rbp), %r8
addq $0x404, %r8             # imm = 0x404
xorl %edx, %edx
movl %edx, %esi
callq 0xd5c0
cmpq $0x0, -0x18(%rbp)
je 0xaefc
movq -0x20(%rbp), %rax
movl $0x2, (%rax)
movl $0x0, -0x3864(%rbp)
cmpl $0xff, -0x3864(%rbp)
jge 0xaefa
movq -0x18(%rbp), %rax
movslq -0x3864(%rbp), %rcx
cmpl $0x10, 0x404(%rax,%rcx,4)
jg 0xaeb2
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
cmpl $0x10, 0x404(%rax,%rcx,4)
jle 0xaee7
movq -0x20(%rbp), %rax
movl 0x800(%rax), %edx
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movl %edx, 0x404(%rax,%rcx,4)
movq -0x20(%rbp), %rax
movl 0x400(%rax), %edx
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,4)
jmp 0xaee9
movl -0x3864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xae7c
jmp 0xaf50
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x3864(%rbp)
cmpl $0x100, -0x3864(%rbp)   # imm = 0x100
jge 0xaf4e
movq -0x20(%rbp), %rax
movslq -0x3864(%rbp), %rcx
cmpl $0x10, 0x404(%rax,%rcx,4)
jle 0xaf3b
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
jmp 0xaf3d
movl -0x3864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3864(%rbp)
jmp 0xaf10
jmp 0xaf50
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x3870, %rsp           # imm = 0x3870
popq %rbp
retq
nopw %cs:(%rax,%rax)