// File: /workspace/github_c_makefile_star2_O0/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:
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rax
movq %rdi, -0x10(%rsp)
movq %rsi, -0x18(%rsp)
movl %edx, -0x1c(%rsp)
movl %ecx, -0x20(%rsp)
movq %r8, -0x28(%rsp)
movq %r9, -0x30(%rsp)
movq -0x10(%rsp), %rax
movl -0x20(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movw (%rax,%rcx,2), %ax
movw %ax, -0x32(%rsp)
movl $0x0, -0x38(%rsp)
movl $0x0, -0x3c(%rsp)
movl $0x0, -0x40(%rsp)
movl -0x1c(%rsp), %eax
movl %eax, -0x44(%rsp)
movl -0x44(%rsp), %eax
cmpl -0x20(%rsp), %eax
jae 0xefa8
movq -0x10(%rsp), %rax
movl -0x44(%rsp), %ecx
movzwl (%rax,%rcx,2), %eax
movzwl -0x32(%rsp), %ecx
cmpl %ecx, %eax
jle 0xef02
movq -0x10(%rsp), %rax
movl -0x44(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq -0x28(%rsp), %rax
movl -0x38(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq -0x18(%rsp), %rax
movl -0x44(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq 0x10(%rsp), %rax
movl -0x38(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rsp)
jmp 0xef96
movq -0x10(%rsp), %rax
movl -0x44(%rsp), %ecx
movzwl (%rax,%rcx,2), %eax
movzwl -0x32(%rsp), %ecx
cmpl %ecx, %eax
jne 0xef57
movq -0x10(%rsp), %rax
movl -0x44(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq -0x30(%rsp), %rax
movl -0x3c(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq -0x18(%rsp), %rax
movl -0x44(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq 0x18(%rsp), %rax
movl -0x3c(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rsp)
jmp 0xef94
movq -0x10(%rsp), %rax
movl -0x44(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq 0x8(%rsp), %rax
movl -0x40(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq -0x18(%rsp), %rax
movl -0x44(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq 0x20(%rsp), %rax
movl -0x40(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rsp)
jmp 0xef96
jmp 0xef98
movl -0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rsp)
jmp 0xee9c
cmpl $0x0, -0x38(%rsp)
jne 0xefc3
cmpl $0x0, -0x40(%rsp)
jne 0xefc3
movl $0x0, -0x4(%rsp)
jmp 0xf119
movl $0x0, -0x48(%rsp)
cmpl $0x0, -0x38(%rsp)
setne %al
andb $0x1, %al
movb %al, -0x49(%rsp)
movb $0x1, -0x4a(%rsp)
movl -0x1c(%rsp), %eax
movl %eax, -0x50(%rsp)
movl -0x50(%rsp), %eax
cmpl -0x20(%rsp), %eax
jae 0xf0fa
testb $0x1, -0x49(%rsp)
je 0xf050
movq -0x28(%rsp), %rax
movl -0x48(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq -0x10(%rsp), %rax
movl -0x50(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq 0x10(%rsp), %rax
movl -0x48(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x18(%rsp), %rax
movl -0x50(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rsp)
cmpl -0x38(%rsp), %eax
jne 0xf04b
movb $0x0, -0x49(%rsp)
movl $0x0, -0x48(%rsp)
jmp 0xf0e8
testb $0x1, -0x4a(%rsp)
je 0xf0a9
movq -0x30(%rsp), %rax
movl -0x48(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq -0x10(%rsp), %rax
movl -0x50(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq 0x18(%rsp), %rax
movl -0x48(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x18(%rsp), %rax
movl -0x50(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rsp)
cmpl -0x3c(%rsp), %eax
jne 0xf0a7
movb $0x0, -0x4a(%rsp)
movl $0x0, -0x48(%rsp)
jmp 0xf0e6
movq 0x8(%rsp), %rax
movl -0x48(%rsp), %ecx
movw (%rax,%rcx,2), %dx
movq -0x10(%rsp), %rax
movl -0x50(%rsp), %ecx
movw %dx, (%rax,%rcx,2)
movq 0x20(%rsp), %rax
movl -0x48(%rsp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x18(%rsp), %rax
movl -0x50(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rsp)
jmp 0xf0e8
jmp 0xf0ea
movl -0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rsp)
jmp 0xefe6
movl -0x1c(%rsp), %ecx
addl -0x38(%rsp), %ecx
addl -0x3c(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, (%rax)
movl -0x1c(%rsp), %eax
addl -0x38(%rsp), %eax
movl %eax, -0x4(%rsp)
movl -0x4(%rsp), %eax
retq
nop