// File: sbme-tutorials[P]huffman-encoding/huffman.cpp
// Function: Huffman::outputEncoded(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Huffman::outputEncoded(std::string outputFile)
{
    std::string directory = "./encoded/" + outputFile + ".txt";
    std::ofstream myFile;
    myFile.open(directory);
    myFile << intensity << "\n"
           << width << " " << height << " " << maxIntensity << " "
           << codeTable.size() << " " << sizeOfEncoded << " " << std::endl; //<< bitSize << " "; // print info
    for (auto c : codeTable)
    {
        myFile << (int)c.first << " " << c.second << " " << std::endl;
    }
    bitPacking();
    for (auto p : packed)
    {
        myFile << p;
    }
    myFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x350, %rsp            # imm = 0x350
movq %rsi, %rdx
movq %rdi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq 0x76a8(%rip), %rsi      # 0xd090
leaq -0x50(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x7450
movq -0x2c8(%rbp), %rsi
leaq 0x7695(%rip), %rdx      # 0xd09b
leaq -0x30(%rbp), %rdi
callq 0x7400
jmp 0x5a11
leaq -0x50(%rbp), %rdi
callq 0x31d0
leaq -0x260(%rbp), %rdi
callq 0x34a0
jmp 0x5a28
leaq -0x260(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x3150
jmp 0x5a3f
movq -0x2d0(%rbp), %rsi
addq $0x30, %rsi
leaq -0x260(%rbp), %rdi
callq 0x3290
movq %rax, -0x2d8(%rbp)
jmp 0x5a5f
movq -0x2d8(%rbp), %rdi
leaq 0x7633(%rip), %rsi      # 0xd0a0
callq 0x32b0
movq %rax, -0x2e0(%rbp)
jmp 0x5a7b
movq -0x2e0(%rbp), %rdi
movq -0x2d0(%rbp), %rax
movl 0x20(%rax), %esi
callq 0x34c0
movq %rax, -0x2e8(%rbp)
jmp 0x5a9a
movq -0x2e8(%rbp), %rdi
leaq 0x75fa(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x2f0(%rbp)
jmp 0x5ab6
movq -0x2f0(%rbp), %rdi
movq -0x2d0(%rbp), %rax
movl 0x24(%rax), %esi
callq 0x34c0
movq %rax, -0x2f8(%rbp)
jmp 0x5ad5
movq -0x2f8(%rbp), %rdi
leaq 0x75bf(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x300(%rbp)
jmp 0x5af1
movq -0x300(%rbp), %rdi
movq -0x2d0(%rbp), %rax
movl 0x28(%rax), %esi
callq 0x34c0
movq %rax, -0x308(%rbp)
jmp 0x5b10
movq -0x308(%rbp), %rdi
leaq 0x7584(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x310(%rbp)
jmp 0x5b2c
movq -0x2d0(%rbp), %rdi
addq $0xa0, %rdi
callq 0x7560
movq -0x310(%rbp), %rdi
movq %rax, %rsi
callq 0x30c0
movq %rax, -0x318(%rbp)
jmp 0x5b57
movq -0x318(%rbp), %rdi
leaq 0x753d(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x320(%rbp)
jmp 0x5b73
movq -0x320(%rbp), %rdi
movq -0x2d0(%rbp), %rax
movq 0xf0(%rax), %rsi
callq 0x32a0
movq %rax, -0x328(%rbp)
jmp 0x5b96
movq -0x328(%rbp), %rdi
leaq 0x74fe(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x330(%rbp)
jmp 0x5bb2
movq -0x330(%rbp), %rdi
movq 0xd408(%rip), %rsi      # 0x12fc8
callq 0x32f0
jmp 0x5bc7
movq -0x2d0(%rbp), %rax
addq $0xa0, %rax
movq %rax, -0x268(%rbp)
movq -0x268(%rbp), %rdi
callq 0x7580
movq %rax, -0x270(%rbp)
movq -0x268(%rbp), %rdi
callq 0x7340
movq %rax, -0x278(%rbp)
leaq -0x270(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x72e0
testb $0x1, %al
jne 0x5c1d
jmp 0x5d35
leaq -0x270(%rbp), %rdi
callq 0x75b0
movq %rax, %rsi
leaq -0x2a0(%rbp), %rdi
callq 0x75d0
jmp 0x5c3a
movzbl -0x2a0(%rbp), %esi
leaq -0x260(%rbp), %rdi
callq 0x34c0
movq %rax, -0x338(%rbp)
jmp 0x5c56
movq -0x338(%rbp), %rdi
leaq 0x743e(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x340(%rbp)
jmp 0x5c72
movq -0x340(%rbp), %rdi
leaq -0x298(%rbp), %rsi
callq 0x3290
movq %rax, -0x348(%rbp)
jmp 0x5c8e
movq -0x348(%rbp), %rdi
leaq 0x7406(%rip), %rsi      # 0xd0a2
callq 0x32b0
movq %rax, -0x350(%rbp)
jmp 0x5caa
movq -0x350(%rbp), %rdi
movq 0xd310(%rip), %rsi      # 0x12fc8
callq 0x32f0
jmp 0x5cbf
leaq -0x2a0(%rbp), %rdi
callq 0x4960
leaq -0x270(%rbp), %rdi
callq 0x7610
jmp 0x5c01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x31d0
jmp 0x5e10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5e07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5dfb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x4960
jmp 0x5dfb
movq -0x2d0(%rbp), %rdi
callq 0x5e20
jmp 0x5d43
movq -0x2d0(%rbp), %rax
addq $0x110, %rax            # imm = 0x110
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rdi
callq 0x6eb0
movq %rax, -0x2b0(%rbp)
movq -0x2a8(%rbp), %rdi
callq 0x6ee0
movq %rax, -0x2b8(%rbp)
leaq -0x2b0(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x6f10
testb $0x1, %al
jne 0x5d96
jmp 0x5dcf
leaq -0x2b0(%rbp), %rdi
callq 0x6f50
movb (%rax), %al
movb %al, -0x2b9(%rbp)
movzbl -0x2b9(%rbp), %esi
leaq -0x260(%rbp), %rdi
callq 0x3450
jmp 0x5dbf
jmp 0x5dc1
leaq -0x2b0(%rbp), %rdi
callq 0x7050
jmp 0x5d7d
leaq -0x260(%rbp), %rdi
callq 0x3400
jmp 0x5ddd
leaq -0x260(%rbp), %rdi
callq 0x3420
leaq -0x30(%rbp), %rdi
callq 0x31d0
addq $0x350, %rsp            # imm = 0x350
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x3420
leaq -0x30(%rbp), %rdi
callq 0x31d0
movq -0x58(%rbp), %rdi
callq 0x34e0
nopl (%rax)