// File: /workspace/github_cpp_makefile_star2_O1/Manca[P]algorithms1/./assignment1.hpp
// Function: assignment1::CountSplitInv(std::vector<int, std::allocator<int>>&, std::vector<int, std::allocator<int>> const&, std::vector<int, std::allocator<int>> const&)
long long CountSplitInv(std::vector<int> &input, const std::vector<int>& left, const std::vector<int>& right)
    {
        std::vector<int> result;
        long long inversions = 0;
        
        size_t i = 0, j = 0;
        
        for (size_t k = 0; k < (left.size() + right.size()); k++)
        {
            if ( (i < left.size()) && (j < right.size()) && (left[i] < right[j]))
            {
                result.push_back(left[i]);
                i++;
            }
            else if ( (j < right.size()) && (i <left.size()) && (right[j] <= left[i]))
            {
                result.push_back(right[j]);
                j++;
                
                // inversion found (it's a split inversion)!
                inversions += left.size() - i;
                
                // if you want to print the inversions, uncomment this code
                //for (int o = i; o < left.size(); o++)
                //    cout << right[(j - 1)] << ", " << left[o] << endl;
            }
            else if (i < left.size())
            {
                result.push_back(left[i]);
                i++;
            }
            else if (j < right.size())
            {
                result.push_back(right[j]);
                j++;
            }
        }
        input = result;
        
        return inversions;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
movq %rsi, %rdi
addq %rdx, %rdi
jne 0x2621
xorl %r12d, %r12d
jmp 0x273e
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpq %rdx, %r13
jae 0x2652
cmpq %rsi, %rbx
jae 0x2652
movl (%rax,%r13,4), %edi
cmpl (%rcx,%rbx,4), %edi
jge 0x2652
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x26d4
movl %edi, (%rsi)
jmp 0x267e
cmpq %rdx, %r13
jae 0x2665
cmpq %rsi, %rbx
jae 0x2665
movl (%rcx,%rbx,4), %edi
cmpl (%rax,%r13,4), %edi
jle 0x26b1
cmpq %rdx, %r13
jae 0x2689
leaq (%rax,%r13,4), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x26ca
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x26e0
cmpq %rsi, %rbx
jae 0x2712
leaq (%rcx,%rbx,4), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x2707
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x270f
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x26e5
movl %edi, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x26f1
movq %rsp, %rdi
callq 0x739e
jmp 0x26e0
leaq (%rax,%r13,4), %rdx
movq %rsp, %rdi
callq 0x739e
incq %r13
jmp 0x2712
leaq (%rcx,%rbx,4), %rdx
movq %rsp, %rdi
callq 0x739e
movq 0x8(%r15), %rax
subq (%r15), %rax
incq %rbx
sarq $0x2, %rax
subq %r13, %r12
addq %rax, %r12
jmp 0x2712
movq %rsp, %rdi
callq 0x739e
incq %rbx
incq %rbp
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
movq (%r14), %rcx
movq 0x8(%r14), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
leaq (%rsi,%rdx), %rdi
cmpq %rdi, %rbp
jb 0x262b
movq %rsp, %rsi
movq 0x20(%rsp), %rdi
callq 0x612a
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2759
callq 0x21b0
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x276d
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x277e
callq 0x21b0
movq %rbx, %rdi
callq 0x2310