// File: /workspace/github_cpp_makefile_star2_O3/cristian-bicheru[P]arith/./huffman.h
// Function: void huffman::CompressBuffer<unsigned char, unsigned long>(std::vector<unsigned char, std::allocator<unsigned char>>&, buffer::CodecByteStream&)
void CompressBuffer(std::vector<SymbolType>& UncompressedBuffer, buffer::CodecByteStream& CompressedBuffer) {
        std::map<SymbolType, ValueType> SortedFrequencyTable;
        PopulateFrequencyTable(SortedFrequencyTable, UncompressedBuffer);
        HuffmanTree<SymbolType, ValueType> HuffTree(SortedFrequencyTable);
        HuffTree.ConstructSymbolTable();
        auto SymTable = HuffTree.GetSymbolTable();
        uint64_t index = sizeof(uint16_t)+sizeof(uint64_t);
        for (auto keyval : SortedFrequencyTable) {
            buffer::EncodeTypeToBuffer<SymbolType>(CompressedBuffer.GetBuffer(), index, &keyval.first);
            index += sizeof(SymbolType);
            buffer::EncodeTypeToBuffer<ValueType>(CompressedBuffer.GetBuffer(), index, &keyval.second);
            index += sizeof(ValueType);
        }
        auto ushrt = uint16_t(index);
        buffer::EncodeTypeToBuffer<uint16_t>(CompressedBuffer.GetBuffer(), 0, &ushrt);
        auto ull = uint64_t(UncompressedBuffer.size());
        buffer::EncodeTypeToBuffer<uint64_t>(CompressedBuffer.GetBuffer(), sizeof(uint16_t), &ull);

        std::vector<bool> code;
        for (SymbolType symbol : UncompressedBuffer) {
            code = SymTable[symbol];
            for (bool bit : code) {
                CompressedBuffer.WriteBit(bit);
            }
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x50(%rsp), %r15
movl $0x0, (%r15)
xorl %eax, %eax
movq %rax, 0x8(%r15)
movq %r15, 0x10(%r15)
movq %r15, 0x18(%r15)
movq %rax, 0x20(%r15)
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x4996
leaq 0xa8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x49da
leaq 0xa8(%rsp), %rdi
callq 0x4e32
leaq 0xb0(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x8268
movq 0x60(%rsp), %rax
movl $0xa, %r13d
cmpq %r15, %rax
je 0x3ff1
xorl %r12d, %r12d
movups 0x20(%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movb 0x10(%rsp), %cl
movq (%rbx), %rdx
movq %r13, %rdi
movb %cl, (%rdx,%r13)
movl $0x8, %ecx
movb 0x10(%rsp,%rcx), %dl
movq (%rbx), %rsi
addq %r12, %rsi
movb %dl, 0x3(%rcx,%rsi)
incq %rcx
cmpq $0x10, %rcx
jne 0x3fc2
addq $0x9, %rdi
movq %rdi, %r13
movq %rax, %rdi
callq 0x2150
addq $0x9, %r12
cmpq %r15, %rax
jne 0x3fa6
movq (%rbx), %rax
movq %r13, %rcx
movb %cl, (%rax)
movq (%rbx), %rax
movb %ch, 0x1(%rax)
movq 0x8(%r14), %rax
subq (%r14), %rax
movq %rax, 0x40(%rsp)
xorl %eax, %eax
movb 0x40(%rsp,%rax), %cl
movq (%rbx), %rdx
movb %cl, 0x2(%rdx,%rax)
incq %rax
cmpq $0x8, %rax
jne 0x400d
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq (%r14), %rbp
movq 0x8(%r14), %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %rbp
je 0x40f5
movb (%rbp), %al
movb %al, 0xf(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x4f7a
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x4fe0
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r12
movl 0x28(%rsp), %r14d
cmpq %r12, %r15
setne %al
testl %r14d, %r14d
setne %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x40d8
xorl %r13d, %r13d
movq (%r15), %rax
xorl %esi, %esi
btq %r13, %rax
setb %sil
movq %rbx, %rdi
callq 0x3c84
xorl %eax, %eax
cmpl $0x3f, %r13d
leal 0x1(%r13), %ecx
sete %al
leaq (%r15,%rax,8), %r15
movl $0x0, %eax
cmovel %eax, %ecx
cmpq %r12, %r15
setne %al
cmpl %r14d, %ecx
setne %dl
orb %al, %dl
movl %ecx, %r13d
jne 0x4097
incq %rbp
cmpq 0x38(%rsp), %rbp
jne 0x404f
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x40f5
callq 0x21c0
leaq 0x78(%rsp), %rdi
callq 0x8558
leaq 0xa8(%rsp), %rdi
callq 0x509a
leaq 0x48(%rsp), %rdi
callq 0x856c
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x412a
movq %rax, %rbx
jmp 0x4154
jmp 0x4131
movq %rax, %rbx
jmp 0x4161
jmp 0x4138
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x414a
callq 0x21c0
leaq 0x78(%rsp), %rdi
callq 0x8558
leaq 0xa8(%rsp), %rdi
callq 0x509a
leaq 0x48(%rsp), %rdi
callq 0x856c
movq %rbx, %rdi
callq 0x2320