// File: /workspace/github_c_makefile_star2_O3/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 0x24c4
shll $0x3, %r15d
movq %r15, %rdi
callq 0x10c0
testq %rax, %rax
je 0x25fc
movq %rax, %r14
movq (%r12), %rax
movq %rax, (%r14)
jmp 0x25ea
movq %rcx, %r14
movl %r15d, %ebx
shrl %ebx
movl %edx, 0x1c(%rsp)
movsbl %dl, %ebp
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2487
movq %rax, 0x10(%rsp)
leaq (%r12,%rbx,8), %rdi
movl %r15d, %r12d
subl %ebx, %r12d
movl %r12d, %esi
movl %ebp, %edx
movq %r14, 0x20(%rsp)
movq %r14, %rcx
callq 0x2487
movq %rax, 0x8(%rsp)
movl %r15d, %edi
shlq $0x3, %rdi
callq 0x10c0
testq %rax, %rax
je 0x261b
movq %rax, %r14
xorl %ebp, %ebp
xorl %r13d, %r13d
movl %r12d, 0x18(%rsp)
movq %rbx, %r12
movl %ebp, %ebx
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movl %r13d, %r15d
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rsi
callq *0x20(%rsp)
cmpb 0x1c(%rsp), %al
je 0x2567
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x2567
leal (%rbp,%r13), %ecx
movq %rax, (%r14,%rcx,8)
incl %r13d
jmp 0x257b
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rax
leal (%rbp,%r13), %ecx
movq %rax, (%r14,%rcx,8)
incl %ebp
movq %r12, %rbx
cmpl %ebx, %ebp
movl 0x18(%rsp), %r12d
jae 0x258c
cmpl %r12d, %r13d
jb 0x2527
cmpl %ebx, %ebp
jne 0x25b5
cmpl %r12d, %r13d
jae 0x25d6
movl %r13d, %eax
movl %r12d, %ecx
movq 0x8(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
leal (%rbx,%rax), %esi
movq %rdx, (%r14,%rsi,8)
incq %rax
cmpq %rcx, %rax
jb 0x259b
jmp 0x25d6
cmpl %ebx, %ebp
jae 0x25d6
movl %ebp, %eax
movl %r13d, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
leal (%rcx,%rax), %esi
movq %rdx, (%r14,%rsi,8)
incq %rax
cmpq %rax, %rbx
jne 0x25be
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1536(%rip), %rdi      # 0x3b39
leaq 0x122e(%rip), %rsi      # 0x3838
leaq 0x1537(%rip), %rcx      # 0x3b48
movl $0xf2, %edx
callq 0x1060
leaq 0x1517(%rip), %rdi      # 0x3b39
leaq 0x120f(%rip), %rsi      # 0x3838
leaq 0x1518(%rip), %rcx      # 0x3b48
movl $0xff, %edx
callq 0x1060