// File: /workspace/github_c_makefile_star2_O2/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 0x508e6
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x88cdb(%rip), %rdx     # 0xd9474
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
pushq $0x67
popq %rcx
callq 0xce9a
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 0x50833
testq %rax, %rax
je 0x50913
movq (%rbx), %r8
testq %r8, %r8
je 0x50842
movq 0x10(%rcx), %rsi
movq 0x18(%rbx), %rdx
movq %r15, %rdi
callq *%r8
testl %eax, %eax
js 0x50877
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 0x50891
movq (%rcx), %r13
testq %r13, %r13
je 0x5099e
testq %r13, %r13
je 0x508b5
movq 0x10(%r13), %rdi
movq 0x18(%rbx), %rdx
movq %r15, %rsi
callq *(%rbx)
testl %eax, %eax
jle 0x50856
movq (%r13), %r13
jmp 0x50813
testq %rax, %rax
jne 0x50940
movq %r14, (%r13)
jmp 0x508a3
cmpq $0x0, 0x8(%rax)
jne 0x5096d
movq %r14, 0x8(%rax)
movq %rax, (%r14)
jmp 0x508a3
movq 0x8(%r13), %rax
testq %rax, %rax
je 0x509cf
leaq 0x8(%r13), %r12
movq %rax, 0x8(%r14)
movq %r13, (%r14)
movq 0x8(%r13), %rax
movq %r14, (%rax)
jmp 0x508a3
movq (%r13), %rax
cmpq $0x0, (%rax)
jne 0x509fd
movq %r14, (%rax)
movq %rax, 0x8(%r14)
movq %r13, %r12
jmp 0x508a3
cmpq $0x0, 0x8(%rcx)
jne 0x50a27
movq %r14, 0x8(%rcx)
movq %rcx, (%r14)
movq %r14, (%r12)
incq 0x20(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0xdd6fc(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x797a0(%rip), %rsi     # 0xca066
leaq 0x88c4a(%rip), %rdx     # 0xd9517
leaq 0x88be2(%rip), %rcx     # 0xd94b6
leaq 0x88b99(%rip), %r8      # 0xd9474
movl $0x91, %r9d
jmp 0x50a51
movq 0xdd6cb(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x7976f(%rip), %rsi     # 0xca066
leaq 0x88b87(%rip), %rdx     # 0xd9485
leaq 0x88bb1(%rip), %rcx     # 0xd94b6
leaq 0x88b68(%rip), %r8      # 0xd9474
pushq $0x66
jmp 0x50a4f
movq 0xdd69e(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x79742(%rip), %rsi     # 0xca066
leaq 0x88ba5(%rip), %rdx     # 0xd94d0
leaq 0x88b84(%rip), %rcx     # 0xd94b6
leaq 0x88b3b(%rip), %r8      # 0xd9474
pushq $0x70
jmp 0x50a4f
movq 0xdd671(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x79715(%rip), %rsi     # 0xca066
leaq 0x88b6b(%rip), %rdx     # 0xd94c3
leaq 0x88b57(%rip), %rcx     # 0xd94b6
leaq 0x88b0e(%rip), %r8      # 0xd9474
pushq $0x6b
jmp 0x50a4f
movq 0xdd644(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x796e8(%rip), %rsi     # 0xca066
leaq 0x88b7f(%rip), %rdx     # 0xd9504
leaq 0x88b2a(%rip), %rcx     # 0xd94b6
leaq 0x88ae1(%rip), %r8      # 0xd9474
movl $0x96, %r9d
jmp 0x50a51
movq 0xdd613(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x796b7(%rip), %rsi     # 0xca066
leaq 0x88b61(%rip), %rdx     # 0xd9517
leaq 0x88af9(%rip), %rcx     # 0xd94b6
leaq 0x88ab0(%rip), %r8      # 0xd9474
movl $0x84, %r9d
jmp 0x50a51
movq 0xdd5e2(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x79686(%rip), %rsi     # 0xca066
leaq 0x88b38(%rip), %rdx     # 0xd951f
leaq 0x88ac8(%rip), %rcx     # 0xd94b6
leaq 0x88a7f(%rip), %r8      # 0xd9474
movl $0x88, %r9d
jmp 0x50a51
movq 0xdd5b4(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x79658(%rip), %rsi     # 0xca066
leaq 0x88ad7(%rip), %rdx     # 0xd94ec
leaq 0x88a9a(%rip), %rcx     # 0xd94b6
leaq 0x88a51(%rip), %r8      # 0xd9474
pushq $0x75
jmp 0x50a4f
movq 0xdd58a(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x7962e(%rip), %rsi     # 0xca066
leaq 0x88ac5(%rip), %rdx     # 0xd9504
leaq 0x88a70(%rip), %rcx     # 0xd94b6
leaq 0x88a27(%rip), %r8      # 0xd9474
pushq $0x7c
popq %r9
xorl %eax, %eax
callq 0xb8c0
callq 0xb300