// File: atsidaev[P]trx2x/DiskImage.cpp
// Function: reconst()
void reconst(void)
{
  int i, j, k;
  int f, l;

  /* collect leaf nodes in the first half of the table */
  /* and replace the freq by (freq + 1) / 2. */
  j = 0;
  for(i = 0; i < T; i++)
  {
    if(son[i] >= T)
    {
      freq[j] = (freq[i] + 1) / 2;
      son[j] = son[i];
      j++;
    }
  }
  /* begin constructing tree by connecting sons */
  for(i = 0, j = N_CHAR; j < T; i += 2, j++)
  {
    k = i + 1;
    f = freq[j] = freq[i] + freq[k];
    for(k = j - 1; f < freq[k]; k--);
    k++;
    l = (j - k) * sizeof(*freq);
    memcpy(&freq[k + 1], &freq[k], l);
    freq[k] = f;
    memcpy(&son[k + 1], &son[k], l);
    son[k] = i;
  }
  /* connect prnt */
  for (i = 0; i < T; i++)
    if ((k = son[i]) >= T) prnt[k] = i;
    else prnt[k] = prnt[k + 1] = i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x8(%rbp)
movl $0x0, -0x4(%rbp)
cmpl $0x273, -0x4(%rbp)      # imm = 0x273
jae 0xd225
movslq -0x4(%rbp), %rcx
leaq 0x60e6(%rip), %rax      # 0x132a0
movswl (%rax,%rcx,2), %eax
cmpl $0x273, %eax            # imm = 0x273
jb 0xd218
movslq -0x4(%rbp), %rcx
leaq 0x5480(%rip), %rax      # 0x12650
movzwl (%rax,%rcx,2), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movw %ax, %dx
movslq -0x8(%rbp), %rcx
leaq 0x5463(%rip), %rax      # 0x12650
movw %dx, (%rax,%rcx,2)
movslq -0x4(%rbp), %rcx
leaq 0x60a4(%rip), %rax      # 0x132a0
movw (%rax,%rcx,2), %dx
movslq -0x8(%rbp), %rcx
leaq 0x6095(%rip), %rax      # 0x132a0
movw %dx, (%rax,%rcx,2)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xd21a
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xd1a6
movl $0x0, -0x4(%rbp)
movl $0x13a, -0x8(%rbp)      # imm = 0x13A
cmpl $0x273, -0x8(%rbp)      # imm = 0x273
jae 0xd360
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0x53fc(%rip), %rax      # 0x12650
movzwl (%rax,%rcx,2), %eax
movslq -0xc(%rbp), %rdx
leaq 0x53ed(%rip), %rcx      # 0x12650
movzwl (%rcx,%rdx,2), %ecx
addl %ecx, %eax
movslq -0x8(%rbp), %rdx
leaq 0x53dc(%rip), %rcx      # 0x12650
movw %ax, (%rcx,%rdx,2)
movzwl %ax, %eax
movl %eax, -0x10(%rbp)
movl -0x8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0x10(%rbp), %eax
movslq -0xc(%rbp), %rdx
leaq 0x53bb(%rip), %rcx      # 0x12650
movzwl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jge 0xd2aa
jmp 0xd29f
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xd287
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %eax
subl -0xc(%rbp), %eax
cltq
shlq %rax
movl %eax, -0x14(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
leaq 0x5380(%rip), %rdi      # 0x12650
shlq %rax
addq %rax, %rdi
movslq -0xc(%rbp), %rax
leaq 0x536f(%rip), %rsi      # 0x12650
shlq %rax
addq %rax, %rsi
movslq -0x14(%rbp), %rdx
callq 0x10c0
movl -0x10(%rbp), %eax
movw %ax, %dx
movslq -0xc(%rbp), %rcx
leaq 0x534f(%rip), %rax      # 0x12650
movw %dx, (%rax,%rcx,2)
movl -0xc(%rbp), %eax
addl $0x1, %eax
cltq
leaq 0x5f8c(%rip), %rdi      # 0x132a0
shlq %rax
addq %rax, %rdi
movslq -0xc(%rbp), %rax
leaq 0x5f7b(%rip), %rsi      # 0x132a0
shlq %rax
addq %rax, %rsi
movslq -0x14(%rbp), %rdx
callq 0x10c0
movl -0x4(%rbp), %eax
movw %ax, %dx
movslq -0xc(%rbp), %rcx
leaq 0x5f5b(%rip), %rax      # 0x132a0
movw %dx, (%rax,%rcx,2)
movl -0x4(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xd233
movl $0x0, -0x4(%rbp)
cmpl $0x273, -0x4(%rbp)      # imm = 0x273
jae 0xd3d6
movslq -0x4(%rbp), %rcx
leaq 0x5f25(%rip), %rax      # 0x132a0
movswl (%rax,%rcx,2), %eax
movl %eax, -0xc(%rbp)
cmpl $0x273, %eax            # imm = 0x273
jb 0xd3a0
movl -0x4(%rbp), %eax
movw %ax, %dx
movslq -0xc(%rbp), %rcx
leaq 0x57a6(%rip), %rax      # 0x12b40
movw %dx, (%rax,%rcx,2)
jmp 0xd3c9
movl -0x4(%rbp), %eax
movw %ax, %dx
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0x578a(%rip), %rax      # 0x12b40
movw %dx, (%rax,%rcx,2)
movslq -0xc(%rbp), %rcx
leaq 0x577b(%rip), %rax      # 0x12b40
movw %dx, (%rax,%rcx,2)
jmp 0xd3cb
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xd367
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)