// File: /workspace/github_c_makefile_star2_O1/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 0x72efd
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x7d71c(%rip), %rdx     # 0xf0514
movl $0x1, %edi
movl $0x18, %esi
movl $0x67, %ecx
callq 0x3601f
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 0x72e8f
testq %rax, %rax
je 0x72f02
movq (%rbx), %r8
testq %r8, %r8
je 0x72e9a
movq 0x10(%rcx), %rsi
movq 0x18(%rbx), %rdx
movq %r15, %rdi
callq *%r8
testl %eax, %eax
js 0x72ec7
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 0x72edd
movq (%rcx), %r13
testq %r13, %r13
je 0x72f11
movq 0x10(%r13), %rdi
movq 0x18(%rbx), %rdx
movq %r15, %rsi
callq *(%rbx)
testl %eax, %eax
jle 0x72eaa
movq (%r13), %r13
testq %r13, %r13
jne 0x72e70
callq 0x1a546
testq %rax, %rax
jne 0x72f07
movq %r14, (%r13)
jmp 0x72eeb
cmpq $0x0, 0x8(%rax)
jne 0x72f0c
movq %r14, 0x8(%rax)
movq %rax, (%r14)
jmp 0x72eeb
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x72f16
leaq 0x8(%r13), %r12
movq %rax, 0x8(%r14)
movq %r13, (%r14)
movq 0x8(%r13), %rax
movq %r14, (%rax)
jmp 0x72eeb
movq (%r13), %rax
cmpq $0x0, (%rax)
jne 0x72f1b
movq %r14, (%rax)
movq %rax, 0x8(%r14)
movq %r13, %r12
jmp 0x72eeb
cmpq $0x0, 0x8(%rcx)
jne 0x72f20
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 0x1a706
callq 0x1a698
callq 0x1a6cf
callq 0x1a65f
callq 0x1a5b8
callq 0x1a57f
callq 0x1a628
callq 0x1a5f1