// File: /workspace/github_c_makefile_star2_O0/theck01[P]offbrand_lib/src/classes/obdeque.c
// Function: obdeque_recursive_sort
obdeque obdeque_recursive_sort(obdeque deque, int8_t order, ob_compare_fptr funct){

  uint64_t i, half_length;
  obdeque left_sorted, right_sorted;
  obdeque_node *curnode;

  /* base case, a deque of size 0 or 1 is sorted */
  if(deque.length < 2) return deque;

  half_length = deque.length/2;

  left_sorted.head = deque.head;
  left_sorted.tail = deque.head;

  /* iterate through half of the deque to split it in half */
  for(i=1; i<half_length; i++) left_sorted.tail = left_sorted.tail->next;

  right_sorted.head = left_sorted.tail->next;
  right_sorted.tail = deque.tail;

  /* separate right and left deques */
  right_sorted.head->prev = NULL;
  left_sorted.tail->next = NULL;

  left_sorted.length = half_length;
  right_sorted.length = deque.length - half_length;

  /* sort deque halves recursively */
  right_sorted = obdeque_recursive_sort(right_sorted, order, funct);
  left_sorted = obdeque_recursive_sort(left_sorted, order, funct);

  /* set the head of the combined list appropriately */
  if(funct(right_sorted.head->stored, left_sorted.head->stored) == order){
    deque.head = right_sorted.head;
    right_sorted.head = right_sorted.head->next;
  }
  else{
    deque.head = left_sorted.head;
    left_sorted.head = left_sorted.head->next;
  }

  curnode = deque.head;

  /* merge lists with proper sequencing */
  while(right_sorted.head && left_sorted.head){

    if(funct(right_sorted.head->stored, left_sorted.head->stored)
        == order){
      curnode->next = right_sorted.head;
      right_sorted.head->prev = curnode;
      right_sorted.head = right_sorted.head->next;
    }
    else{
      curnode->next = left_sorted.head;
      left_sorted.head->prev = curnode;
      left_sorted.head = left_sorted.head->next;
    }

    curnode = curnode->next;
  }

  /* merge in remenants of lists, after one has been depleted */
  while(right_sorted.head){
    curnode->next = right_sorted.head;
    right_sorted.head->prev = curnode;
    right_sorted.head = right_sorted.head->next;
    curnode = curnode->next;
  }

  while(left_sorted.head){
    curnode->next = left_sorted.head;
    left_sorted.head->prev = curnode;
    left_sorted.head = left_sorted.head->next;
    curnode = curnode->next;
  }

  /* curnode should be the last node in the list, set appropriately */
  deque.tail = curnode;

  return deque;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0xc0(%rbp)
movb %sil, %cl
movq %rdi, -0xb8(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movb %cl, -0x1(%rbp)
movq %rdx, -0x10(%rbp)
cmpq $0x2, 0x18(%rax)
jae 0x2ad6
movq -0xc0(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
jmp 0x2de9
movq -0xb0(%rbp), %rax
movq 0x18(%rax), %rcx
shrq %rcx
movq %rcx, -0x20(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x1, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x2b24
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x2b00
movq -0xb0(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq %rcx, -0x58(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq -0x58(%rbp), %rcx
movq $0x0, 0x18(%rcx)
movq -0x30(%rbp), %rcx
movq $0x0, 0x10(%rcx)
movq -0x20(%rbp), %rcx
movq %rcx, -0x28(%rbp)
movq 0x18(%rax), %rax
subq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movb -0x1(%rbp), %al
movq -0x10(%rbp), %rdx
leaq -0x88(%rbp), %rdi
leaq -0x60(%rbp), %rcx
movq (%rcx), %rsi
movq %rsi, (%rsp)
movq 0x8(%rcx), %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rcx), %rsi
movq %rsi, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movsbl %al, %esi
callq 0x2a70
movq -0x88(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x48(%rbp)
movb -0x1(%rbp), %al
movq -0x10(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
leaq -0x40(%rbp), %rcx
movq (%rcx), %rsi
movq %rsi, (%rsp)
movq 0x8(%rcx), %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rcx), %rsi
movq %rsi, 0x10(%rsp)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rsp)
movsbl %al, %esi
callq 0x2a70
movq -0xa8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rsi
callq *%rax
movsbl %al, %eax
movsbl -0x1(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2c70
movq -0xb0(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x2c8b
movq -0xb0(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0xb0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0xc1(%rbp)
je 0x2cb7
cmpq $0x0, -0x38(%rbp)
setne %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x2cc3
jmp 0x2d3f
movq -0x10(%rbp), %rax
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rsi
callq *%rax
movsbl %al, %eax
movsbl -0x1(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2d0a
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x68(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x2d2e
movq -0x38(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x2c9a
jmp 0x2d41
cmpq $0x0, -0x58(%rbp)
je 0x2d7a
movq -0x58(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x68(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x2d41
jmp 0x2d7c
cmpq $0x0, -0x38(%rbp)
je 0x2db5
movq -0x38(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x2d7c
movq -0xc0(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq -0x68(%rbp), %rdx
movq %rdx, 0x10(%rcx)
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movq 0x18(%rcx), %rcx
movq %rcx, 0x18(%rax)
movq -0xb8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)