// File: /workspace/github_cpp_makefile_star2_O1/Czxck001[P]algorithms/src/mom.cc
// Function: int protoSelect<int>(std::vector<int, std::allocator<int>>::iterator, std::vector<int, std::allocator<int>>::iterator, int)
T protoSelect(VIter<T> l, VIter<T> r, int k) {
  assert(l + k < r);

  auto G = (r - l) / GROUPSIZE;
  if (l == r - 1 && k == 0 || G == 0) {
    return *(l + k);
  }

  auto M = std::vector<T>(G);
  for (auto g = 0; g < G; g++) {
    M[g] = medianOfGroup<T>(l + g * GROUPSIZE,
                            l + (g + 1) * GROUPSIZE);
  }  // O(n)

  auto P = protoSelect<T>(M.begin(), M.end(), G / 2);  // T(n / 5)

  auto s = partition<T>(l, r, P);  // O(n)

  if (l + k == s) {
    return *s;
  } else if (l + k < s) {
    return protoSelect<T>(l, s, k);
  } else {  // l + k > s
    return protoSelect<T>(s + 1, r, l + k - s - 1);
  }  // T(7n / 10)

  // T(n) = T(n / 5) + T(7n / 10) + O(n) = O(n)
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r12
movslq %edx, %rax
leaq (%rdi,%rax,4), %rdi
cmpq %rsi, %rdi
jae 0x15de
movl %edx, %r8d
movq %rsi, %rbx
subq %r12, %rbx
sarq $0x2, %rbx
movabsq $0x6666666666666667, %rcx # imm = 0x6666666666666667
movq %rbx, %rax
imulq %rcx
leaq -0x4(%rsi), %rax
cmpq %r12, %rax
sete %al
testl %r8d, %r8d
sete %cl
andb %al, %cl
leaq 0x4(%rbx), %rax
cmpq $0x9, %rax
setb %al
orb %cl, %al
cmpb $0x1, %al
jne 0x149a
movl (%rdi), %ebx
jmp 0x15cd
movq %rdx, %r15
movl %r8d, -0x30(%rbp)
movq %rdi, -0x50(%rbp)
movq %rsi, -0x58(%rbp)
movq %rdx, %rax
shrq $0x3f, %rax
sarq %r15
addq %rax, %r15
leaq -0x48(%rbp), %rdi
leaq -0x29(%rbp), %rdx
movq %r15, %rsi
callq 0x16cc
movq %rbx, -0x60(%rbp)
cmpq $0x5, %rbx
jl 0x1546
movq -0x48(%rbp), %rax
xorl %edx, %edx
movq %r12, %rcx
leaq (%rdx,%rdx,4), %rsi
leaq (%r12,%rsi,4), %rdi
leaq 0x1(%rdx), %rsi
movq %rcx, %r8
xorl %r10d, %r10d
leaq (%rdi,%r10), %rbx
leaq 0x4(%r10), %r9
movl $0x4, %r14d
movq %rbx, %r11
movl (%r11), %r13d
cmpl (%r8,%r14), %r13d
jle 0x1509
leaq (%r8,%r14), %r11
leaq (%r10,%r14), %r13
addq $0x4, %r13
addq $0x4, %r14
cmpq $0x14, %r13
jne 0x14fc
movl (%r11), %r10d
movl (%rbx), %r14d
movl %r14d, (%r11)
movl %r10d, (%rbx)
addq $0x4, %r8
movq %r9, %r10
cmpq $0xc, %r9
jne 0x14eb
movl 0x8(%rdi), %edi
movl %edi, (%rax,%rdx,4)
addq $0x14, %rcx
movq %rsi, %rdx
cmpq %r15, %rsi
jne 0x14d9
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x60(%rbp), %rax
movabsq $0x6666666666666667, %rcx # imm = 0x6666666666666667
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x2, %rdx
addl %eax, %edx
callq 0x142f
movq %r12, %rdi
movq -0x58(%rbp), %rbx
movq %rbx, %rsi
movl %eax, %edx
callq 0x175f
movq -0x50(%rbp), %rdx
subq %rax, %rdx
je 0x159d
jae 0x15a1
movq %r12, %rdi
movq %rax, %rsi
movl -0x30(%rbp), %edx
callq 0x142f
jmp 0x15b6
movl (%rax), %ebx
jmp 0x15b8
addq $0x4, %rax
shrq $0x2, %rdx
decl %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x142f
movl %eax, %ebx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x15cd
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa80(%rip), %rdi       # 0x2065
leaq 0xa83(%rip), %rsi       # 0x206f
leaq 0xa87(%rip), %rcx       # 0x207a
movl $0x36, %edx
callq 0x1070
jmp 0x1601
jmp 0x1601
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1619
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1110
nop