// File: /workspace/github_c_makefile_star2_O3/jsh58[P]Genrich/Genrich.c
// Function: johnPartition
uint32_t johnPartition(uint16_t* qual, uint32_t* order,
    uint32_t low, uint32_t high, uint16_t* qual0,
    uint16_t* qual1, uint16_t* qual2, uint32_t* order0,
    uint32_t* order1, uint32_t* order2,
    uint32_t* idxHigh) {

  // separate qual values into temp arrays --
  //   qual0 for higher values, qual1 equal, qual2 lower
  uint16_t pivot = qual[high - 1];  // pivot value: last elt
  uint32_t idx0 = 0, idx1 = 0, idx2 = 0; // indexes into temp arrays
  for (uint32_t j = low; j < high; j++) {
    if (qual[j] > pivot) {
      qual0[idx0] = qual[j];
      order0[idx0] = order[j];
      idx0++;
    } else if (qual[j] == pivot) {
      qual1[idx1] = qual[j];
      order1[idx1] = order[j];
      idx1++;
    } else {
      qual2[idx2] = qual[j];
      order2[idx2] = order[j];
      idx2++;
    }
  }

  if (! idx0 && ! idx2)
    return 0; // all equal values, no need to shuffle

  // recombine temp arrays back into qual/order
  uint32_t i = 0;
  bool val0 = (bool) idx0, val1 = true;
  for (uint32_t j = low; j < high; j++) {
    if (val0) {
      qual[j] = qual0[i];
      order[j] = order0[i];
      if (++i == idx0) {
        val0 = false;
        i = 0;
      }
    } else if (val1) {
      qual[j] = qual1[i];
      order[j] = order1[i];
      if (++i == idx1) {
        val1 = false;
        i = 0;
      }
    } else {
      qual[j] = qual2[i];
      order[j] = order2[i];
      i++;
    }
  }

  // return low/high indexes
  *idxHigh = low + idx0 + idx1;
  return low + idx0;
}

// Assembly:
cmpl %ecx, %edx
jae 0xa497
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leal -0x1(%rcx), %eax
movzwl (%rdi,%rax,2), %r10d
movl %edx, -0x4(%rsp)
movl %edx, %ebx
movl %ecx, %r13d
xorl %r11d, %r11d
movq %rbx, %r12
xorl %ebp, %ebp
xorl %eax, %eax
movzwl (%rdi,%r12,2), %r15d
cmpw %r10w, %r15w
jbe 0xa398
movl %eax, %r14d
movw %r15w, (%r8,%r14,2)
movl (%rsi,%r12,4), %r15d
movq 0x40(%rsp), %rdx
movl %r15d, (%rdx,%r14,4)
incl %eax
jmp 0xa3d0
jne 0xa3b3
movl %ebp, %r14d
movw %r10w, (%r9,%r14,2)
movl (%rsi,%r12,4), %r15d
movq 0x48(%rsp), %rdx
movl %r15d, (%rdx,%r14,4)
incl %ebp
jmp 0xa3d0
movl %r11d, %r14d
movq 0x38(%rsp), %rdx
movw %r15w, (%rdx,%r14,2)
movl (%rsi,%r12,4), %r15d
movq 0x50(%rsp), %rdx
movl %r15d, (%rdx,%r14,4)
incl %r11d
incq %r12
cmpq %r12, %r13
jne 0xa374
testl %eax, %eax
setne %r10b
orl %eax, %r11d
je 0xa49a
movl -0x4(%rsp), %edx
cmpl %ecx, %edx
jae 0xa48a
xorl %r14d, %r14d
movb $0x1, %r12b
xorl %r11d, %r11d
movl %r11d, %ecx
testb $0x1, %r10b
je 0xa42d
movzwl (%r8,%rcx,2), %r10d
movw %r10w, (%rdi,%rbx,2)
movq 0x40(%rsp), %r10
movl (%r10,%rcx,4), %r10d
movl %r10d, (%rsi,%rbx,4)
leal 0x1(%rcx), %r11d
cmpl %eax, %r11d
setne %r10b
cmovel %r14d, %r11d
jmp 0xa47e
leal 0x1(%rcx), %r11d
testb $0x1, %r12b
je 0xa45d
movzwl (%r9,%rcx,2), %r10d
movw %r10w, (%rdi,%rbx,2)
movq 0x48(%rsp), %r10
movl (%r10,%rcx,4), %ecx
movl %ecx, (%rsi,%rbx,4)
xorl %r10d, %r10d
cmpl %ebp, %r11d
setne %r12b
cmovel %r10d, %r11d
jmp 0xa47e
movq 0x38(%rsp), %r10
movzwl (%r10,%rcx,2), %r10d
movw %r10w, (%rdi,%rbx,2)
movq 0x50(%rsp), %r10
movl (%r10,%rcx,4), %ecx
movl %ecx, (%rsi,%rbx,4)
xorl %r10d, %r10d
xorl %r12d, %r12d
incq %rbx
cmpq %rbx, %r13
jne 0xa3fc
addl %edx, %eax
addl %eax, %ebp
movq 0x58(%rsp), %rcx
movl %ebp, (%rcx)
jmp 0xa49c
xorl %eax, %eax
retq
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq