// File: /workspace/github_cpp_makefile_star2_O1/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 0x4a0a
leaq 0xa8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x4a4e
leaq 0xa8(%rsp), %rdi
callq 0x4e56
leaq 0xb0(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x833a
movq 0x60(%rsp), %rax
cmpq %r15, %rax
je 0x4021
movl $0xa, %r12d
xorl %r13d, %r13d
movups 0x20(%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movb 0x10(%rsp), %cl
movq (%rbx), %rdx
movb %cl, (%rdx,%r12)
movl $0x8, %ecx
movb 0x10(%rsp,%rcx), %dl
movq (%rbx), %rsi
addq %r13, %rsi
movb %dl, 0x3(%rcx,%rsi)
incq %rcx
cmpq $0x10, %rcx
jne 0x3ff3
addq $0x9, %r12
movq %rax, %rdi
callq 0x2150
addq $0x9, %r13
cmpq %r15, %rax
jne 0x3fda
jmp 0x4026
movw $0xa, %r12w
movw %r12w, 0xe(%rsp)
xorl %eax, %eax
movb 0xe(%rsp,%rax), %cl
movq (%rbx), %rdx
movb %cl, (%rdx,%rax)
incq %rax
cmpq $0x1, %rax
je 0x402e
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 0x404f
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 0x4128
movb (%rbp), %al
movb %al, 0xd(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xd(%rsp), %rsi
callq 0x4fe8
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x504c
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 0x411a
xorl %r13d, %r13d
movq (%r15), %rax
xorl %esi, %esi
btq %r13, %rax
setb %sil
movq %rbx, %rdi
callq 0x3cb0
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 0x40d9
incq %rbp
cmpq 0x38(%rsp), %rbp
jne 0x4091
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4150
callq 0x21c0
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x862a
leaq 0xa8(%rsp), %rdi
callq 0x50ec
leaq 0x48(%rsp), %rdi
callq 0x863e
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4185
movq %rax, %rbx
jmp 0x41c8
jmp 0x418c
movq %rax, %rbx
jmp 0x41d5
jmp 0x4193
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x41be
callq 0x21c0
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x862a
leaq 0xa8(%rsp), %rdi
callq 0x50ec
leaq 0x48(%rsp), %rdi
callq 0x863e
movq %rbx, %rdi
callq 0x2320