// File: Manca[P]algorithms1/./assignment2.hpp
// Function: assignment2::partitionMedian(std::vector<int, std::allocator<int>>&, int, int)
int partitionMedian(vector<int>& input, int left, int right)
    {
        noCompMedian += right - left - 1;
        
        int midInd = (left + right - 1) / 2;
        // initially pivot position is unknown
        int p = -1;
        
        // compute the median of the three elements (first, median, last)
        // and assign its index to the pivot
        if (input[left] < input[midInd])
        {
            if (input[left] >= input[right-1])
                p = left;
            else if (input[midInd] < input[right-1])
                p = midInd;
        }
        else
        {
            if (input[midInd] >= input[right-1])
                p = midInd;
            else if (input[left] < input[right-1])
                p = left;
        }
        // fallback
        if (p == -1)
            p = right - 1;
        
        // bring the median pivot to the beginning
        swap(input[left], input[p]);
        
        return partition(input, left, right);
    }

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movl %edx, 0x28(%rsp)
movl 0x28(%rsp), %eax
subl 0x2c(%rsp), %eax
subl $0x1, %eax
addl 0x2144a(%rip), %eax     # 0x241ec
movl %eax, 0x21444(%rip)     # 0x241ec
movl 0x2c(%rsp), %eax
addl 0x28(%rsp), %eax
subl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x24(%rsp)
movl $0xffffffff, 0x20(%rsp) # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x2e74
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
movl 0x28(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x18(%rsp), %eax
cmpl (%rcx), %eax
jl 0x2e34
movl 0x2c(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x2e72
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rdi
movl 0x28(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl (%rcx), %eax
jge 0x2e70
movl 0x24(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x2e72
jmp 0x2ef2
movq 0x30(%rsp), %rdi
movslq 0x24(%rsp), %rsi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movl 0x28(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x84b0
movq %rax, %rcx
movl 0x10(%rsp), %eax
cmpl (%rcx), %eax
jl 0x2eb2
movl 0x24(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x2ef0
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0x84b0
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %rdi
movl 0x28(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x84b0
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl (%rcx), %eax
jge 0x2eee
movl 0x2c(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x2ef0
jmp 0x2ef2
cmpl $-0x1, 0x20(%rsp)
jne 0x2f04
movl 0x28(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0x84b0
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
movslq 0x20(%rsp), %rsi
callq 0x84b0
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x2ba0
movq 0x30(%rsp), %rdi
movl 0x2c(%rsp), %esi
movl 0x28(%rsp), %edx
callq 0x2bd0
addq $0x38, %rsp
retq
nopl (%rax)