// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
movq 0x8(%rsi), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq (%r14), %rdi
movq 0x8(%r14), %rsi
subq %rdi, %rsi
sarq $0x2, %rsi
movq %rsi, %r8
addq %rdx, %r8
jne 0x264c
xorl %r12d, %r12d
movq %rsp, %rsi
movq 0x20(%rsp), %rdi
callq 0x60a8
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x263a
callq 0x21b0
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r12d, %r12d
cmpq %rdx, %r13
jae 0x2683
leaq (%rcx,%r13,4), %rdx
cmpq %rsi, %rbx
jae 0x26ab
movl (%rcx,%r13,4), %r8d
cmpl (%rdi,%rbx,4), %r8d
jge 0x26c9
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x2707
movl %r8d, (%rsi)
jmp 0x26be
cmpq %rsi, %rbx
jae 0x2712
leaq (%rdi,%rbx,4), %rdx
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x26fa
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2702
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
cmpq %r8, %rsi
je 0x26f0
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x270f
movl (%rdi,%rbx,4), %r9d
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
cmpl (%rcx,%r13,4), %r9d
jg 0x26b5
cmpq %r8, %rsi
je 0x2746
movl %r9d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x2759
movq %rsp, %rdi
callq 0x733a
jmp 0x270f
movq %rsp, %rdi
callq 0x733a
incq %rbx
jmp 0x2712
movq %rsp, %rdi
callq 0x733a
incq %r13
incq %rbp
movq (%r15), %rcx
movq 0x8(%r15), %rax
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
movq (%r14), %rdi
movq 0x8(%r14), %rsi
subq %rdi, %rsi
sarq $0x2, %rsi
leaq (%rsi,%rdx), %r8
cmpq %r8, %rbp
jb 0x2656
jmp 0x261f
leaq (%rdi,%rbx,4), %rdx
movq %rsp, %rdi
callq 0x733a
movq (%r15), %rcx
movq 0x8(%r15), %rax
subq %rcx, %rax
incq %rbx
sarq $0x2, %rax
subq %r13, %r12
addq %rax, %r12
jmp 0x2712
jmp 0x276d
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x277e
callq 0x21b0
movq %rbx, %rdi
callq 0x2310