// File: cristian-bicheru[P]arith/./huffman.h
// Function: huffman::HuffmanTree<unsigned char, unsigned long>::HuffmanTree(std::map<unsigned char, unsigned long, std::less<unsigned char>, std::allocator<std::pair<unsigned char const, unsigned long>>> const&)
explicit HuffmanTree(const std::map<SymbolType, ValueType>& SortedFrequencyTable) {
            std::deque<HuffmanNode<SymbolType, ValueType>*> SymbolQueue;
            HuffmanNode<SymbolType, ValueType>* NodePtr;

            for (auto SymbolFrequency : SortedFrequencyTable) {
                AllNodes.push_back(new HuffmanNode<SymbolType, ValueType>(std::get<1>(SymbolFrequency), std::get<0>(SymbolFrequency)));
                SymbolQueue.push_front(AllNodes.back());
            }

            while (SymbolQueue.size() > 1) {
                std::sort(SymbolQueue.rbegin(), SymbolQueue.rend(), ComparePointerObjects<HuffmanNode<SymbolType, ValueType>>);
                //std::cout << SymbolQueue.back()->GetValue() << std::endl;
                NodePtr = SymbolQueue.back();
                SymbolQueue.pop_back();
                AllNodes.push_back(new HuffmanNode<SymbolType, ValueType>(NodePtr, SymbolQueue.back()));
                SymbolQueue.push_front(AllNodes.back());
                SymbolQueue.pop_back();
            }

            ParentNode = SymbolQueue[0];
        }

// Assembly:
subq $0x168, %rsp            # imm = 0x168
movq %rdi, 0x160(%rsp)
movq %rsi, 0x158(%rsp)
movq 0x160(%rsp), %rdi
movq %rdi, 0x60(%rsp)
addq $0x8, %rdi
movq %rdi, 0x58(%rsp)
callq 0xcea0
movq 0x60(%rsp), %rdi
addq $0x38, %rdi
movq %rdi, 0x68(%rsp)
callq 0xceb0
leaq 0x108(%rsp), %rdi
callq 0xcec0
jmp 0xa194
movq 0x158(%rsp), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rdi
callq 0xced0
movq %rax, 0xe0(%rsp)
movq 0xe8(%rsp), %rdi
callq 0xcf00
movq %rax, 0xd8(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xcf30
testb $0x1, %al
jne 0xa1ec
jmp 0xa308
leaq 0xe0(%rsp), %rdi
callq 0xcf50
movq %rax, %rcx
movq 0x60(%rsp), %rax
movups (%rcx), %xmm0
movaps %xmm0, 0xc0(%rsp)
addq $0x38, %rax
movq %rax, 0x48(%rsp)
movl $0x20, %edi
callq 0x21b0
movq %rax, 0x50(%rsp)
jmp 0xa226
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xcfa0
movq 0x38(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0x40(%rsp)
callq 0xcfb0
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
movzbl (%rax), %edx
callq 0xcfc0
jmp 0xa25e
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %rsi
callq 0xcf70
jmp 0xa27f
movq 0x60(%rsp), %rdi
addq $0x38, %rdi
callq 0xd060
movq %rax, %rsi
leaq 0x108(%rsp), %rdi
callq 0xd000
jmp 0xa29f
jmp 0xa2a1
leaq 0xe0(%rsp), %rdi
callq 0xd0a0
jmp 0xa1ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xa48c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xa47f
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x2190
jmp 0xa47f
jmp 0xa30a
leaq 0x108(%rsp), %rdi
callq 0xd0d0
cmpq $0x1, %rax
jbe 0xa44b
leaq 0x98(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x108(%rsp), %rsi
movq %rsi, 0x20(%rsp)
callq 0xd150
movq 0x20(%rsp), %rsi
leaq 0x78(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xd1b0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq 0x2eab(%rip), %rdx      # 0xd210
callq 0xd0f0
jmp 0xa36c
leaq 0x108(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xd240
movq 0x8(%rsp), %rdi
movq (%rax), %rax
movq %rax, 0xf0(%rsp)
callq 0xd270
movq 0x60(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x10(%rsp)
movl $0x20, %edi
callq 0x21b0
movq %rax, 0x18(%rsp)
jmp 0xa3b2
movq 0xf0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd240
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
movq (%rax), %rdx
callq 0xd2e0
jmp 0xa3de
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0xcf70
jmp 0xa3f9
movq 0x60(%rsp), %rdi
addq $0x38, %rdi
callq 0xd060
movq %rax, %rsi
leaq 0x108(%rsp), %rdi
callq 0xd000
jmp 0xa419
leaq 0x108(%rsp), %rdi
callq 0xd270
jmp 0xa30a
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
callq 0x2190
jmp 0xa47f
leaq 0x108(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xd340
movq %rax, %rcx
movq 0x60(%rsp), %rax
movq (%rcx), %rcx
movq %rcx, (%rax)
leaq 0x108(%rsp), %rdi
callq 0xd370
addq $0x168, %rsp            # imm = 0x168
retq
leaq 0x108(%rsp), %rdi
callq 0xd370
movq 0x68(%rsp), %rdi
callq 0xd3e0
movq 0x58(%rsp), %rdi
callq 0xac00
movq 0x100(%rsp), %rdi
callq 0x2310
nopl (%rax)