// File: ctSkennerton[P]fxtract/util/ordhuff_x.c
// Function: main
int
main (int argc, char **argv)
{
    unsigned        freq[MAXTEST], code[MAXTEST], bits[MAXTEST];
    char            zcode[33];
    int             i, ncodes;

    if (argc != 2)
        return fputs ("Usage: ordhuff_x (freqfile | -)\n", stderr);

    FILE           *finp =
        strcmp (argv[1], "-") ? fopen (argv[1], "r") : stdin;

    if (!finp)
        return 1;

    for (ncodes = 0; 
         ncodes < MAXTEST && fscanf (finp, "%ud", &freq[ncodes]) == 1; 
        ++ncodes);

    ordhuff(ncodes, freq, code, bits);

    unsigned        raw = 0, pkd = 0;

    for (i = 0; i < ncodes; ++i) {
        prbits(zcode, (int) code[i], (int) bits[i]);
        printf ("%4d %8d %s\n", i, freq[i], zcode);
        raw += freq[i];
        pkd += freq[i] * strlen (zcode);
    }

    fprintf (stderr, "Exprevbits: %4.2f\n", (float) pkd / raw);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f50, %rsp           # imm = 0x2F50
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x12dd
movq 0x3d1a(%rip), %rax      # 0x4fe0
movq (%rax), %rsi
leaq 0x1d34(%rip), %rdi      # 0x3004
callq 0x10d0
movl %eax, -0x4(%rbp)
jmp 0x1502
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1d39(%rip), %rsi      # 0x3025
callq 0x1150
cmpl $0x0, %eax
je 0x1313
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x215c(%rip), %rsi      # 0x3461
callq 0x10e0
movq %rax, -0x2f40(%rbp)
jmp 0x1324
movq 0x3cbe(%rip), %rax      # 0x4fd8
movq (%rax), %rax
movq %rax, -0x2f40(%rbp)
movq -0x2f40(%rbp), %rax
movq %rax, -0x2f30(%rbp)
cmpq $0x0, -0x2f30(%rbp)
jne 0x1348
movl $0x1, -0x4(%rbp)
jmp 0x1502
movl $0x0, -0x2f28(%rbp)
xorl %eax, %eax
cmpl $0x3e8, -0x2f28(%rbp)   # imm = 0x3E8
movb %al, -0x2f41(%rbp)
jge 0x139c
movq -0x2f30(%rbp), %rdi
movslq -0x2f28(%rbp), %rax
leaq -0xfb0(%rbp), %rdx
shlq $0x2, %rax
addq %rax, %rdx
leaq 0x1c9e(%rip), %rsi      # 0x3027
movb $0x0, %al
callq 0x1190
cmpl $0x1, %eax
sete %al
movb %al, -0x2f41(%rbp)
movb -0x2f41(%rbp), %al
testb $0x1, %al
jne 0x13a8
jmp 0x13bb
jmp 0x13aa
movl -0x2f28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f28(%rbp)
jmp 0x1352
movl -0x2f28(%rbp), %edi
leaq -0xfb0(%rbp), %rsi
leaq -0x1f50(%rbp), %rdx
leaq -0x2ef0(%rbp), %rcx
callq 0x1570
movl $0x0, -0x2f34(%rbp)
movl $0x0, -0x2f38(%rbp)
movl $0x0, -0x2f24(%rbp)
movl -0x2f24(%rbp), %eax
cmpl -0x2f28(%rbp), %eax
jge 0x14c5
leaq -0x2f20(%rbp), %rdi
movslq -0x2f24(%rbp), %rax
movl -0x1f50(%rbp,%rax,4), %esi
movslq -0x2f24(%rbp), %rax
movl -0x2ef0(%rbp,%rax,4), %edx
callq 0x1510
movl -0x2f24(%rbp), %esi
movslq -0x2f24(%rbp), %rax
movl -0xfb0(%rbp,%rax,4), %edx
leaq -0x2f20(%rbp), %rcx
leaq 0x1bd6(%rip), %rdi      # 0x302b
movb $0x0, %al
callq 0x1030
movslq -0x2f24(%rbp), %rax
movl -0xfb0(%rbp,%rax,4), %eax
addl -0x2f34(%rbp), %eax
movl %eax, -0x2f34(%rbp)
movslq -0x2f24(%rbp), %rax
movl -0xfb0(%rbp,%rax,4), %eax
movq %rax, -0x2f50(%rbp)
leaq -0x2f20(%rbp), %rdi
callq 0x1060
movq -0x2f50(%rbp), %rcx
imulq %rax, %rcx
movl -0x2f38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x2f38(%rbp)
movl -0x2f24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f24(%rbp)
jmp 0x13f9
movq 0x3b14(%rip), %rax      # 0x4fe0
movq (%rax), %rdi
movl -0x2f38(%rbp), %eax
cvtsi2ss %rax, %xmm0
movl -0x2f34(%rbp), %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1b43(%rip), %rsi      # 0x3037
movb $0x1, %al
callq 0x1170
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2f50, %rsp           # imm = 0x2F50
popq %rbp
retq
nop