// File: /workspace/github_cpp_makefile_star2_O3/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 %r14d, %r14d
movq %r14, 0x68(%rsp)
movb $0x0, 0x30(%rsp)
movups %xmm0, 0x38(%rsp)
movq %r14, 0x48(%rsp)
movq %r14, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x2070
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %al, %al
je 0x5397
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 0x5343
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl 0xc(%rsp), %esi
testl %ecx, %ecx
je 0x5262
cmpl (%rax), %esi
movq %r15, %rdi
cmovgq %r13, %rdi
callq 0x6480
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 0x5283
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 0x6f80
movq %r13, %rdi
jmp 0x52ae
movq %r15, %rdi
callq 0x6480
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5321
movl 0xc(%rsp), %eax
jmp 0x5311
subl %r9d, %r10d
cmpl $0x2, %r10d
jl 0x52b5
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 0x6f80
movq %r15, %rdi
movl %ebp, %esi
callq 0x6480
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 0x52ff
movl (%rcx), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
jne 0x5311
movq %r12, %rdi
leaq 0x8(%rsp), %rdx
callq 0x8b78
jmp 0x51c1
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5331
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x51c1
movq %r12, %rdi
movq %r14, %rdx
callq 0x733a
jmp 0x51c1
movq %r12, %rdi
leaq 0x8(%rsp), %rdx
callq 0x8b78
jmp 0x51c1
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x53d1
xorl %ebx, %ebx
movq %rdi, %rcx
addl (%rcx), %ebx
addq $0x4, %rcx
cmpq %rax, %rcx
jne 0x5357
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 0x53d1
testq %rdi, %rdi
je 0x5392
callq 0x21b0
movq 0x38(%rsp), %r14
testq %r14, %r14
je 0x53a4
movq %r14, %rdi
callq 0x21b0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x53b3
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 0x5016(%rip), %rdi      # 0xa3ee
leaq 0x4fca(%rip), %rsi      # 0xa3a9
leaq 0x5021(%rip), %rcx      # 0xa407
movl $0x98, %edx
callq 0x2120
jmp 0x53f4
jmp 0x53f4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5406
callq 0x21b0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5415
callq 0x21b0
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x5424
callq 0x21b0
leaq 0x70(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2310