// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/dlist.c
// Function: gt_dlist_add
void gt_dlist_add(GtDlist *dlist, void *data)
{
  GtDlistelem *oldelem, *newelem;
  gt_assert(dlist); /* data can be null */
  newelem = gt_calloc(1, sizeof (GtDlistelem));
  newelem->data = data;

  if (!dlist->first) {
    gt_assert(!dlist->last);
    dlist->first = newelem;
    dlist->last = newelem;
  }
  else {
    gt_assert(dlist->first && dlist->last);
    if (dlist->cmp_func) {
      /* compare function defined -> find place to add new element */
      if (dlist->cmp_func(data, dlist->first->data, dlist->data) < 0) {
        /* the new element is smaller then the first element */
        gt_assert(!dlist->first->previous);
        dlist->first->previous = newelem;
        newelem->next = dlist->first;
        dlist->first = newelem;
      }
      else if (dlist->cmp_func(dlist->last->data, data, dlist->data) <= 0) {
        /* the new element is larger or equal then the last element */
        gt_assert(!dlist->last->next);
        dlist->last->next = newelem;
        newelem->previous = dlist->last;
        dlist->last = newelem;
      }
      else {
        /* traverse list backwards to find a place to insert the new element */
        oldelem = dlist->last->previous;
        gt_assert(oldelem);
        while (oldelem) {
          if (dlist->cmp_func(oldelem->data, data, dlist->data) <= 0) {
            /* position found */
            gt_assert(oldelem->next);
            newelem->next = oldelem->next;
            newelem->previous = oldelem;
            oldelem->next->previous = newelem;
            oldelem->next = newelem;
            break;
          }
          oldelem = oldelem->previous;
        }
        gt_assert(oldelem); /* a position has been found */
      }
    }
    else {
      /* no compare function defined -> add new element to the end */
      gt_assert(!dlist->last->next);
      dlist->last->next = newelem;
      newelem->previous = dlist->last;
      dlist->last = newelem;
    }
  }
  dlist->size++;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x734d5
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x7d0f4(%rip), %rdx     # 0xf04c4
movl $0x1, %edi
movl $0x18, %esi
movl $0x67, %ecx
callq 0x359a6
movq %rax, %r14
movq %r15, 0x10(%rax)
leaq 0x8(%rbx), %r13
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rax
leaq 0x10(%rbx), %r12
testq %rcx, %rcx
je 0x73467
testq %rax, %rax
je 0x734da
movq (%rbx), %r8
testq %r8, %r8
je 0x73472
movq 0x10(%rcx), %rsi
movq 0x18(%rbx), %rdx
movq %r15, %rdi
callq *%r8
testl %eax, %eax
js 0x7349f
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rdx
movq 0x10(%rax), %rdi
movq %r15, %rsi
callq *(%rbx)
movq 0x10(%rbx), %rcx
testl %eax, %eax
jle 0x734b5
movq (%rcx), %r13
testq %r13, %r13
je 0x734e9
movq 0x10(%r13), %rdi
movq 0x18(%rbx), %rdx
movq %r15, %rsi
callq *(%rbx)
testl %eax, %eax
jle 0x73482
movq (%r13), %r13
testq %r13, %r13
jne 0x73448
callq 0x1a4f1
testq %rax, %rax
jne 0x734df
movq %r14, (%r13)
jmp 0x734c3
cmpq $0x0, 0x8(%rax)
jne 0x734e4
movq %r14, 0x8(%rax)
movq %rax, (%r14)
jmp 0x734c3
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x734ee
leaq 0x8(%r13), %r12
movq %rax, 0x8(%r14)
movq %r13, (%r14)
movq 0x8(%r13), %rax
movq %r14, (%rax)
jmp 0x734c3
movq (%r13), %rax
cmpq $0x0, (%rax)
jne 0x734f3
movq %r14, (%rax)
movq %rax, 0x8(%r14)
movq %r13, %r12
jmp 0x734c3
cmpq $0x0, 0x8(%rcx)
jne 0x734f8
movq %r14, 0x8(%rcx)
movq %rcx, (%r14)
movq %r14, (%r12)
incq 0x20(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x1a6b1
callq 0x1a643
callq 0x1a67a
callq 0x1a60a
callq 0x1a563
callq 0x1a52a
callq 0x1a5d3
callq 0x1a59c