// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq %rdi, %r15
cmpl $0x1, %esi
ja 0x2422
shll $0x3, %r14d
movq %r14, %rdi
callq 0x10c0
testq %rax, %rax
je 0x2564
movq %rax, %r14
movq (%r15), %rax
movq %rax, (%r14)
jmp 0x2552
movq %rcx, %r13
movl %r14d, %r12d
shrl %r12d
movl %edx, 0x1c(%rsp)
movsbl %dl, %ebx
movq %r15, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x23e6
movq %rax, 0x8(%rsp)
leaq (%r15,%r12,8), %rdi
movl %r14d, %ebp
movq %r12, 0x10(%rsp)
subl %r12d, %ebp
movl %ebp, %esi
movl %ebx, %edx
movq %r13, 0x20(%rsp)
movq %r13, %rcx
callq 0x23e6
movq %rax, (%rsp)
movl %r14d, %edi
shlq $0x3, %rdi
callq 0x10c0
testq %rax, %rax
je 0x2583
movq %rax, %r14
xorl %r13d, %r13d
xorl %r12d, %r12d
movl %ebp, %ebx
movq %r14, %r15
movl %r13d, %ebp
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
movl %r12d, %r14d
movq (%rsp), %rax
movq (%rax,%r14,8), %rsi
callq *0x20(%rsp)
cmpb 0x1c(%rsp), %al
je 0x24c9
movq (%rsp), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x24c9
leal (%r12,%r13), %ecx
movq %r15, %r14
movq %rax, (%r15,%rcx,8)
incl %r12d
jmp 0x24e0
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rax
leal (%r12,%r13), %ecx
movq %r15, %r14
movq %rax, (%r15,%rcx,8)
incl %r13d
cmpl 0x10(%rsp), %r13d
movl %ebx, %ebp
jae 0x24ee
cmpl %ebp, %r12d
jb 0x2486
cmpl 0x10(%rsp), %r13d
jne 0x251b
cmpl %ebp, %r12d
jae 0x253f
movl %r12d, %eax
movl %ebp, %ecx
movl %r13d, %edx
movq (%rsp), %rsi
movq (%rsi,%rax,8), %rsi
leal (%rdx,%rax), %edi
movq %rsi, (%r14,%rdi,8)
incq %rax
cmpq %rcx, %rax
jb 0x2502
jmp 0x253f
jae 0x253f
movl %r13d, %eax
movl 0x10(%rsp), %ecx
movl %r12d, %edx
movq 0x8(%rsp), %rsi
movq (%rsi,%rax,8), %rsi
leal (%rdx,%rax), %edi
movq %rsi, (%r14,%rdi,8)
incq %rax
cmpq %rax, %rcx
jne 0x2527
movq 0x8(%rsp), %rdi
callq 0x1030
movq (%rsp), %rdi
callq 0x1030
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15a6(%rip), %rdi      # 0x3b11
leaq 0x129e(%rip), %rsi      # 0x3810
leaq 0x15a7(%rip), %rcx      # 0x3b20
movl $0xf2, %edx
callq 0x1060
leaq 0x1587(%rip), %rdi      # 0x3b11
leaq 0x127f(%rip), %rsi      # 0x3810
leaq 0x1588(%rip), %rcx      # 0x3b20
movl $0xff, %edx
callq 0x1060