// File: /workspace/github_cpp_makefile_star2_O2/Manca[P]algorithms1/./assignment6.hpp
// Function: assignment6::computeSumOfMedians(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
int computeSumOfMedians(const string& fileName)
    {
        std::ifstream file(fileName, ios::in);
        DataStructures::Heap heapHigh(true);    // Min-Heap - will hold the smallest element of the larger half
        DataStructures::Heap heapLow(false);    // Max-Heap - will hold the largest element of the smaller half
        
        std::vector<int> medians;
    
        if (file.is_open())
        {
            int num;
            while (file >> num)
            {
                if (heapLow.size() == 0)
                {
                    heapLow.insert(num);
                    medians.push_back(num);
                    continue;
                }
                
                // insert in appropriate heap
                if (num > heapLow[0])
                    heapHigh.insert(num);
                else
                    heapLow.insert(num);
                
                // balance the heaps
                if (heapLow.size() - heapHigh.size() > 1)
                    heapHigh.insert(heapLow.extractMinMax());   // from heapLow we extract max
                else if (heapHigh.size() - heapLow.size() > 1)
                    heapLow.insert(heapHigh.extractMinMax());   // from heapHigh we extract min
                
                // extract the median
                if (heapLow.size() >= heapHigh.size())
                    medians.push_back(heapLow[0]);
                else if (heapHigh.size() > heapLow.size())
                    medians.push_back(heapHigh[0]);
                
            }
            
            int totalSum = 0;
            for (auto m : medians)
            {
                totalSum += m;
            }
            
            assert(totalSum % 10000 == 1213);
            
            return totalSum;
        }
        
        return -1;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdi, %rsi
leaq 0x70(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x2290
leaq 0x58(%rsp), %r14
movb $0x1, -0x8(%r14)
xorps %xmm0, %xmm0
andq $0x0, 0x10(%r14)
movups %xmm0, (%r14)
leaq 0x18(%rsp), %r15
movb $0x0, -0x8(%r15)
movups %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x2070
testb %al, %al
je 0x47f4
leaq 0x70(%rsp), %r15
leaq 0xc(%rsp), %r12
leaq 0x10(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x50(%rsp), %rbx
leaq 0x8(%rsp), %r14
movq %r15, %rdi
movq %r12, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x47f9
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl 0xc(%rsp), %esi
testl %ecx, %ecx
je 0x4771
cmpl (%rax), %esi
movq %r13, %rdi
cmovgq %rbx, %rdi
callq 0x52b2
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
shrq $0x2, %rax
movq 0x60(%rsp), %rcx
subq 0x58(%rsp), %rcx
shrq $0x2, %rcx
movl %eax, %edx
subl %ecx, %edx
cmpl $0x2, %edx
jl 0x4789
movq %r13, %rdi
callq 0x52de
movq %rbx, %rdi
jmp 0x479b
movq %r13, %rdi
callq 0x52b2
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4ffc
jmp 0x46fb
subl %eax, %ecx
cmpl $0x2, %ecx
jl 0x47a2
movq %rbx, %rdi
callq 0x52de
movq %r13, %rdi
movl %eax, %esi
callq 0x52b2
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rsi
subq %rcx, %rsi
shrq $0x2, %rsi
cmpl %esi, %edx
jge 0x47de
movl (%rcx), %eax
movl %eax, 0x8(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7cb0
jmp 0x46fb
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x7cb0
jmp 0x46fb
pushq $-0x1
popq %rbx
jmp 0x482e
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
xorl %ebx, %ebx
leaq 0x58(%rsp), %r14
leaq 0x18(%rsp), %r15
cmpq %rcx, %rax
je 0x481c
addl (%rax), %ebx
addq $0x4, %rax
jmp 0x480f
movl $0x2710, %ecx           # imm = 0x2710
movl %ebx, %eax
cltd
idivl %ecx
cmpl $0x4bd, %edx            # imm = 0x4BD
jne 0x4866
leaq 0x30(%rsp), %rdi
callq 0x606a
movq %r15, %rdi
callq 0x606a
movq %r14, %rdi
callq 0x606a
leaq 0x70(%rsp), %rdi
callq 0x2080
movl %ebx, %eax
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4b21(%rip), %rdi      # 0x938e
leaq 0x4ad5(%rip), %rsi      # 0x9349
leaq 0x4b2c(%rip), %rcx      # 0x93a7
movl $0x98, %edx
callq 0x2150
jmp 0x4889
jmp 0x4889
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x606a
leaq 0x18(%rsp), %rdi
callq 0x606a
leaq 0x58(%rsp), %rdi
callq 0x606a
leaq 0x70(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x22f0