// File: /workspace/github_c_makefile_star2_O2/theck01[P]offbrand_lib/src/classes/obvector.c
// Function: obvector_recursive_sort
obj ** obvector_recursive_sort(obj **to_sort, uint32_t size, int8_t order,
                             ob_compare_fptr funct){

  uint32_t i,j, split;
  obj **left_sorted, **right_sorted;
  obj **sorted;

   /* base case, if the vector is of size one, its sorted */
  if(size <= 1){
    sorted = malloc(sizeof(obj *)*size);
    assert(sorted != NULL);
    *sorted = *to_sort;
    return sorted;
  }

  split = size/2;

  /* sort left half and right half of array */
  left_sorted = obvector_recursive_sort(to_sort, split, order, funct);
  right_sorted = obvector_recursive_sort(to_sort+split, size-split,
                                       order, funct);

  sorted = malloc(sizeof(obj *)*size);
  assert(sorted != NULL);

  /* merge sorted halves */
  i=0;
  j=0;

  /* while there are elements in both halves to be added to sorted */
  while(i < split && j < (size-split)){

    /* if the comparison of the left to the right matches the desired order,
     * then the next item to go in the sorted array is from the left. Ensure
     * that NULL is left at the tail of the sorted array as well */
    if(funct(left_sorted[i], right_sorted[j]) == order ||
        right_sorted[j] == NULL){
      sorted[i+j] = left_sorted[i];
      i++;
    }
    else{
      sorted[i+j] = right_sorted[j];
      j++;
    }
  }

  /* place remaining elements from remaining half in sorted */
  if(i == split){
    while(j<(size - split)){
      sorted[i+j] = right_sorted[j];
      j++;
    }
  }
  else{
    while(i<split){
      sorted[i+j] = left_sorted[i];
      i++;
    }
  }

  /* free sorted half arrays */
  free(left_sorted);
  free(right_sorted);

  return sorted;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r15d
movq %rdi, %r12
cmpl $0x1, %esi
ja 0x20b7
shll $0x3, %r15d
movq %r15, %rdi
callq 0x10c0
testq %rax, %rax
je 0x21ca
movq %rax, %r15
movq (%r12), %rax
movq %rax, (%r15)
jmp 0x21b8
movq %rcx, %r13
movl %r15d, %ebx
shrl %ebx
movl %edx, 0x1c(%rsp)
movsbl %dl, %ebp
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x207a
movq %rax, %r14
leaq (%r12,%rbx,8), %rdi
movl %r15d, %esi
subl %ebx, %esi
movl %esi, 0xc(%rsp)
movl %ebp, %edx
movq %r13, 0x20(%rsp)
movq %r13, %rcx
callq 0x207a
movq %rax, 0x10(%rsp)
movl %r15d, %edi
shlq $0x3, %rdi
callq 0x10c0
testq %rax, %rax
je 0x21e9
movq %rax, %r15
xorl %r13d, %r13d
xorl %ebp, %ebp
movl %r13d, %r12d
movl %ebp, %ebp
cmpl %ebx, %ebp
jae 0x2168
cmpl 0xc(%rsp), %r12d
jae 0x2168
movq (%r14,%rbp,8), %rdi
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rsi
callq *0x20(%rsp)
cmpb 0x1c(%rsp), %al
je 0x2148
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rax
testq %rax, %rax
jne 0x215a
movq (%r14,%rbp,8), %rax
leal (%r13,%rbp), %ecx
movq %rax, (%r15,%rcx,8)
incq %rbp
jmp 0x2118
leal (%r13,%rbp), %ecx
movq %rax, (%r15,%rcx,8)
incq %r13
jmp 0x2113
cmpl %ebp, %ebx
jne 0x218b
movl 0xc(%rsp), %eax
cmpq %rax, %r12
jae 0x21a6
movq 0x10(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
leal (%rbx,%r12), %edx
movq %rcx, (%r15,%rdx,8)
incq %r12
jmp 0x2170
addq %rbp, %r13
cmpq %rbx, %rbp
jae 0x21a6
movq (%r14,%rbp,8), %rax
movl %r13d, %ecx
movq %rax, (%r15,%rcx,8)
incq %rbp
incl %r13d
jmp 0x218e
movq %r14, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1940(%rip), %rdi      # 0x3b11
leaq 0x1638(%rip), %rsi      # 0x3810
leaq 0x1941(%rip), %rcx      # 0x3b20
movl $0xf2, %edx
callq 0x1060
leaq 0x1921(%rip), %rdi      # 0x3b11
leaq 0x1619(%rip), %rsi      # 0x3810
leaq 0x1922(%rip), %rcx      # 0x3b20
movl $0xff, %edx
callq 0x1060