// File: ivanoleinik[P]archiver/src/huffman.cpp
// Function: HuffEncode::HuffEncode(std::istream&)
HuffEncode::HuffEncode(std::istream &in) {
    in.seekg(0, std::ios::end);
    _data.reserve(in.tellg());
    in.seekg(0, std::ios::beg);
    _data.assign((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());

    std::vector<std::size_t> frequencies(256, 0);
    for (unsigned char c : _data)
        frequencies[c]++;
    _tree = std::make_shared<HuffTree>(frequencies);
    _codes = _tree->get_codes();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
callq 0x32f0
movq -0xb0(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0xc0(%rbp)
callq 0x5440
movq -0xb0(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0xb8(%rbp)
callq 0x50b0
movq -0xb0(%rbp), %rax
movq $0x0, 0x48(%rax)
movq $0x0, 0x50(%rax)
movb $0x0, 0x58(%rax)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x32e0
jmp 0x405a
movq -0xc8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x33b0
movq %rdx, -0xd8(%rbp)
movq %rax, -0xd0(%rbp)
jmp 0x4081
movq -0xd8(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movq %rax, -0x28(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5460
movq %rax, -0xe8(%rbp)
jmp 0x40a9
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdi
callq 0x3360
jmp 0x40be
movq -0x10(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x32e0
jmp 0x40cd
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x5530
leaq -0x50(%rbp), %rdi
callq 0x5590
movq -0xc8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x38(%rbp), %edx
movq -0x50(%rbp), %rcx
movl -0x48(%rbp), %r8d
callq 0x5480
jmp 0x4100
movq $0x0, -0x70(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x55c0
movq -0xf0(%rbp), %rcx
leaq -0x68(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
leaq -0x70(%rbp), %rdx
callq 0x55e0
jmp 0x4133
leaq -0x71(%rbp), %rdi
callq 0x5660
movq -0xc8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0x31f0
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rdi
callq 0x3140
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x5680
testb $0x1, %al
jne 0x4180
jmp 0x41e9
leaq -0x88(%rbp), %rdi
callq 0x56c0
movb (%rax), %al
movb %al, -0x91(%rbp)
movzbl -0x91(%rbp), %eax
movl %eax, %esi
leaq -0x68(%rbp), %rdi
callq 0x51a0
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
leaq -0x88(%rbp), %rdi
callq 0x56e0
jmp 0x4167
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x427c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x5660
jmp 0x427c
leaq -0xa8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5700
jmp 0x41fb
movq -0xc8(%rbp), %rdi
addq $0x20, %rdi
movq %rdi, -0xf8(%rbp)
leaq -0xa8(%rbp), %rsi
movq %rsi, -0x100(%rbp)
callq 0x5770
movq -0x100(%rbp), %rdi
callq 0x57a0
movq -0xf8(%rbp), %rdi
callq 0x57c0
movq %rax, %rdi
callq 0x3e80
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
addq $0x30, %rdi
callq 0x57e0
jmp 0x4255
leaq -0x68(%rbp), %rdi
callq 0x53e0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x53e0
movq -0xb8(%rbp), %rdi
callq 0x5360
movq -0xc0(%rbp), %rdi
callq 0x57a0
movq -0xb0(%rbp), %rdi
callq 0x3150
movq -0x18(%rbp), %rdi
callq 0x33d0
nopl (%rax)