// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x8, %edx
callq 0x22b0
movb $0x1, 0x50(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%rsp)
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movb $0x0, 0x30(%rsp)
movups %xmm0, 0x38(%rsp)
movq %rax, 0x48(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x2070
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0x5409
leaq 0x70(%rsp), %rbx
leaq 0xc(%rsp), %r14
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0x50(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x53ca
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl 0xc(%rsp), %esi
testl %ecx, %ecx
je 0x52e9
cmpl (%rax), %esi
movq %r15, %rdi
cmovgq %r13, %rdi
callq 0x64e6
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rax
movq %rax, %rdi
subq %rdx, %rdi
movq %rdi, %r9
shrq $0x2, %r9
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rcx
movq %rcx, %r8
subq %rsi, %r8
movq %r8, %r10
shrq $0x2, %r10
movl %r9d, %r11d
subl %r10d, %r11d
cmpl $0x2, %r11d
jl 0x530a
movl (%rdx), %ebp
movl -0x4(%rdx,%rdi), %ecx
movl %ecx, (%rdx)
addq $-0x4, %rax
movq %rax, 0x40(%rsp)
movzbl 0x30(%rsp), %esi
movq %r15, %rdi
callq 0x6fd0
movq %r13, %rdi
jmp 0x5335
movq %r15, %rdi
callq 0x64e6
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x53a8
movl 0xc(%rsp), %eax
jmp 0x5398
subl %r9d, %r10d
cmpl $0x2, %r10d
jl 0x533c
movl (%rsi), %ebp
movl -0x4(%rsi,%r8), %eax
movl %eax, (%rsi)
addq $-0x4, %rcx
movq %rcx, 0x60(%rsp)
movzbl 0x50(%rsp), %esi
movq %r13, %rdi
callq 0x6fd0
movq %r15, %rdi
movl %ebp, %esi
callq 0x64e6
movq 0x38(%rsp), %rax
movq 0x40(%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 0x5386
movl (%rcx), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
jne 0x5398
movq %r12, %rdi
leaq 0x8(%rsp), %rdx
callq 0x8c10
jmp 0x5248
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x53b8
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5248
movq %r12, %rdi
movq %r14, %rdx
callq 0x739e
jmp 0x5248
movq %r12, %rdi
leaq 0x8(%rsp), %rdx
callq 0x8c10
jmp 0x5248
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
xorl %ebx, %ebx
cmpq %rcx, %rax
je 0x53e3
addl (%rax), %ebx
addq $0x4, %rax
jmp 0x53d6
movslq %ebx, %rax
imulq $0x68db8bad, %rax, %rcx # imm = 0x68DB8BAD
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x2c, %rcx
addl %edx, %ecx
imull $0x2710, %ecx, %ecx     # imm = 0x2710
subl %ecx, %eax
cmpl $0x4bd, %eax            # imm = 0x4BD
jne 0x5454
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5418
callq 0x21b0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5427
callq 0x21b0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5436
callq 0x21b0
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 0x4f93(%rip), %rdi      # 0xa3ee
leaq 0x4f47(%rip), %rsi      # 0xa3a9
leaq 0x4f9e(%rip), %rcx      # 0xa407
movl $0x98, %edx
callq 0x2120
jmp 0x5477
jmp 0x5477
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5489
callq 0x21b0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5498
callq 0x21b0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x54a7
callq 0x21b0
leaq 0x70(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2310