// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/interval_tree.c
// Function: gt_interval_tree_unit_test
int gt_interval_tree_unit_test(GT_UNUSED GtError *err)
{
  GtIntervalTree *it = NULL;
  GtIntervalTreeNode *res = NULL;
  GtUword i = 0;
  int had_err = 0, num_testranges = 3000,
      num_samples = 300000, num_find_all_samples = 10000,
      gt_range_max_basepos = 90000, width = 700,
      query_width = 5000;
  GtRange *res_rng = NULL, qrange;
  GtArray *arr = NULL, *narr = NULL;

  arr = gt_array_new(sizeof (GtRange*));

  /* generate test ranges */
  for (i = 0;i<num_testranges;i++)
  {
    GtUword start;
    GtRange *rng;
    rng  = gt_calloc(1, sizeof (GtRange));
    start = gt_rand_max(gt_range_max_basepos);
    rng->start = start;
    rng->end = start + gt_rand_max(width);
    gt_array_add(arr, rng);
  }

  it = gt_interval_tree_new(gt_free_func);

  /* insert ranges */
  for (i = 0; i < num_testranges && !had_err; i++)
  {
    GtIntervalTreeNode *new_node;
    GtRange *rng;
    rng = *(GtRange**) gt_array_get(arr, i);
    new_node = gt_interval_tree_node_new(rng, rng->start, rng->end);
    gt_interval_tree_insert(it, new_node);
  }
  gt_ensure(gt_interval_tree_size(it) == num_testranges);

  /* perform test queries */
  for (i = 0; i < num_samples && !had_err; i++)
  {
    GtUword start = gt_rand_max(gt_range_max_basepos);
    qrange.start = start;
    qrange.end = start + gt_rand_max(width);
    res = gt_interval_tree_find_first_overlapping(it, qrange.start, qrange.end);
    if (res)
    {
      /* we have a hit, check if really overlapping */
      res_rng = (GtRange*) gt_interval_tree_node_get_data(res);
      gt_ensure(gt_range_overlap(&qrange, res_rng));
    } else {
      /* no hit, check whether there really is no overlapping
         interval in tree */
      GtRange *this_rng;
      GtUword j;
      bool found = false;
      for (j = 0; j < gt_array_size(arr); j++)
      {
        this_rng = *(GtRange**) gt_array_get(arr, j);
        if (gt_range_overlap(this_rng, &qrange))
        {
          found = true;
          break;
        }
      }
      gt_ensure(!found);
    }
  }

  /* test searching for all overlapping intervals */
  for (i = 0; i < num_find_all_samples && !had_err; i++)
  {
    GtUword start = gt_rand_max(gt_range_max_basepos);
    qrange.start = start;
    qrange.end = start + gt_rand_max(query_width);
    GtArray *res = gt_array_new(sizeof (GtRange*));
    gt_interval_tree_find_all_overlapping(it, qrange.start, qrange.end, res);
    if (res)
    {
      /* generate reference overlapping interval list by linear search */
      GtArray *ref;
      GtUword j;
      ref = gt_array_new(sizeof (GtRange*));
      for (j = 0; j < gt_array_size(arr); j++)
      {
        GtRange *this_rng;
        this_rng = *(GtRange**) gt_array_get(arr, j);
        if (gt_range_overlap(this_rng, &qrange))
        {
          gt_array_add(ref, this_rng);
        }
      }
      /* compare reference with interval tree query result */
      gt_array_sort_stable(ref, range_ptr_compare);
      gt_array_sort_stable(res, range_ptr_compare);
      /* must be equal */
      gt_ensure(gt_array_cmp(ref, res)==0);
      gt_array_delete(ref);
    }
    gt_array_delete(res);
  }
  gt_interval_tree_delete(it);

  it = gt_interval_tree_new(NULL);
  gt_array_reset(arr);

  /* generate test ranges */
  for (i = 0;i<num_testranges && !had_err;i++)
  {
    GtUword start;
    GtIntervalTreeNode *new_node;
    start = gt_rand_max(gt_range_max_basepos);
    new_node = gt_interval_tree_node_new((void*) i, start,
                                          start + gt_rand_max(width));
    gt_interval_tree_insert(it, new_node);
  }
  gt_ensure(gt_interval_tree_size(it) == num_testranges);

  narr = gt_array_new(sizeof (GtIntervalTreeNode*));
  for (i = 0; i < num_testranges && !had_err; i++) {
    GtUword idx, n, val;
    GtIntervalTreeNode *node = NULL;

    /* get all nodes referenced by the interval tree */
    interval_tree_find_all_internal(it, it->root, itree_test_get_node, 0,
                                    gt_range_max_basepos+width, narr);

    /* remove a random node */
    idx = gt_rand_max(gt_array_size(narr)-1);
    node = *(GtIntervalTreeNode**) gt_array_get(narr, idx);
    gt_ensure(node != NULL);
    val = (GtUword) gt_interval_tree_node_get_data(node);
    gt_interval_tree_remove(it, node);
    gt_array_reset(narr);

    /* make sure that the node has disappeared */
    gt_ensure(gt_interval_tree_size(it) == num_testranges - (i+1));
    interval_tree_find_all_internal(it, it->root, itree_test_get_node, 0,
                                    gt_range_max_basepos+width, narr);
    gt_ensure(gt_array_size(narr) == num_testranges - (i+1));
    for (n = 0; !had_err && n < gt_array_size(narr); n++) {
      GtIntervalTreeNode *onode = *(GtIntervalTreeNode**) gt_array_get(narr, n);
      gt_ensure((GtUword) gt_interval_tree_node_get_data(onode)
                           != val);
    }
  }

  gt_array_delete(arr);
  gt_array_delete(narr);
  gt_interval_tree_delete(it);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x8(%rsp)
movl $0x8, %edi
callq 0x6ef7c
movq %rax, %rbx
movl $0xbb8, %r13d           # imm = 0xBB8
leaq 0x77c24(%rip), %r14     # 0xf166d
leaq 0x10(%rsp), %r15
movl $0x1, %edi
movl $0x10, %esi
movq %r14, %rdx
movl $0x234, %ecx            # imm = 0x234
callq 0x359a6
movq %rax, 0x10(%rsp)
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x7a51d
movq %rax, %r12
movq 0x10(%rsp), %rax
movq %r12, (%rax)
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x7a51d
addq %r12, %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x8(%rcx)
movl $0x8, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6f240
decq %r13
jne 0x79a4e
leaq 0x77bbc(%rip), %r14     # 0xf166d
movl $0x1, %edi
movl $0x60, %esi
movq %r14, %rdx
movl $0x3e, %ecx
callq 0x359a6
movq %rax, %r15
leaq -0x43dec(%rip), %rax    # 0x35ce6
movq %rax, 0x58(%r15)
leaq 0x8(%r15), %rax
movq %rax, 0x48(%r15)
movq %rax, (%r15)
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6f037
movq (%rax), %r13
movups (%r13), %xmm0
movaps %xmm0, 0x20(%rsp)
movl $0x1, %edi
movl $0x40, %esi
movq %r14, %rdx
movl $0x34, %ecx
callq 0x359a6
movaps 0x20(%rsp), %xmm0
movups %xmm0, 0x28(%rax)
movq %r13, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x794f6
incq %r12
cmpq $0xbb8, %r12            # imm = 0xBB8
jne 0x79ae4
movq %r15, %rdi
callq 0x792f3
cmpq $0xbb8, %rax            # imm = 0xBB8
jne 0x79bf1
xorl %r13d, %r13d
leaq 0x10(%rsp), %r14
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x7a51d
movq %rax, %r12
movq %rax, 0x10(%rsp)
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x7a51d
addq %rax, %r12
movq %r12, 0x18(%rsp)
movq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x7934a
testq %rax, %rax
je 0x79bb5
movq 0x18(%rax), %rsi
movq %r14, %rdi
callq 0x7e1b2
testb %al, %al
je 0x7a009
leaq 0x1(%r13), %rax
cmpq $0x493df, %r13          # imm = 0x493DF
movq %rax, %r13
jb 0x79b53
jmp 0x79eb5
movq %rbx, %rdi
callq 0x6f310
testq %rax, %rax
je 0x79ba0
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6f037
movq (%rax), %rdi
movq %r14, %rsi
callq 0x7e1b2
testb %al, %al
jne 0x79c1c
incq %r12
movq %rbx, %rdi
callq 0x6f310
cmpq %rax, %r12
jb 0x79bc5
jmp 0x79ba0
leaq 0x69561(%rip), %rsi     # 0xe3159
leaq 0x77bc4(%rip), %rdx     # 0xf17c3
leaq 0x77be9(%rip), %rcx     # 0xf17ef
leaq 0x77a60(%rip), %r8      # 0xf166d
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
movl $0x246, %r9d            # imm = 0x246
jmp 0x79c45
leaq 0x69536(%rip), %rsi     # 0xe3159
leaq 0x77c03(%rip), %rdx     # 0xf182d
leaq 0x77bbe(%rip), %rcx     # 0xf17ef
leaq 0x77a35(%rip), %r8      # 0xf166d
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
movl $0x263, %r9d            # imm = 0x263
xorl %eax, %eax
callq 0x34f1f
movq %r15, %rdi
callq 0x79696
leaq 0x77a12(%rip), %rdx     # 0xf166d
movl $0x1, %edi
movl $0x60, %esi
movl $0x3e, %ecx
callq 0x359a6
movq %rax, %r15
movq $0x0, 0x58(%rax)
addq $0x8, %rax
movq %rax, 0x48(%r15)
movq %rax, (%r15)
movq %rbx, %rdi
callq 0x6f349
testb %bpl, %bpl
je 0x79e4a
movq $-0x1, %rbp
leaq 0x779c9(%rip), %r14     # 0xf166d
incq %rbp
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x7a51d
movq %rax, %r12
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x7a51d
movq %rax, %r13
addq %r12, %r13
movl $0x1, %edi
movl $0x40, %esi
movq %r14, %rdx
movl $0x34, %ecx
callq 0x359a6
movq %r12, 0x28(%rax)
movq %r13, 0x30(%rax)
movq %rbp, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x794f6
cmpq $0xbb7, %rbp            # imm = 0xBB7
jb 0x79ca4
movq %r15, %rdi
callq 0x792f3
cmpq $0xbb8, %rax            # imm = 0xBB8
jne 0x79e1c
movl $0x8, %edi
callq 0x6ef7c
movq %rax, %r12
movq $0x0, 0x20(%rsp)
leaq 0x3d6(%rip), %rdx       # 0x7a102
movq (%r15), %rsi
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
movq %rdx, %r13
xorl %ecx, %ecx
movq %r12, %r9
callq 0x79430
movq %r12, %rdi
callq 0x6f310
leaq -0x1(%rax), %rdi
callq 0x7a51d
movq %r12, %rdi
movq %rax, %rsi
callq 0x6f037
movq (%rax), %rsi
testq %rsi, %rsi
je 0x7a0b3
movq 0x18(%rsi), %rbp
movq %r15, %rdi
callq 0x79722
movq %r12, %rdi
callq 0x6f349
movq 0x50(%r15), %r14
movl $0xbb7, %eax            # imm = 0xBB7
subq 0x20(%rsp), %rax
cmpq %rax, %r14
jne 0x7a037
movq (%r15), %rsi
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
movq %r12, %r9
callq 0x79430
movq %r12, %rdi
callq 0x6f310
cmpq %r14, %rax
jne 0x7a087
movq %r12, %rdi
callq 0x6f310
testq %rax, %rax
je 0x79dfa
xorl %r14d, %r14d
movq %r12, %rdi
movq %r14, %rsi
callq 0x6f037
movq (%rax), %rdi
callq 0x79303
cmpq %rbp, %rax
je 0x79e59
incq %r14
movq %r12, %rdi
callq 0x6f310
cmpq %rax, %r14
jb 0x79dd2
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %rax
xorl %ebp, %ebp
cmpq $0xbb7, %rcx            # imm = 0xBB7
movq %rax, 0x20(%rsp)
movq %r13, %rdx
jb 0x79d2c
jmp 0x79e8c
leaq 0x69336(%rip), %rsi     # 0xe3159
leaq 0x77999(%rip), %rdx     # 0xf17c3
leaq 0x779be(%rip), %rcx     # 0xf17ef
leaq 0x77835(%rip), %r8      # 0xf166d
movq 0x8(%rsp), %rdi
movl $0x296, %r9d            # imm = 0x296
xorl %eax, %eax
callq 0x34f1f
movl $0x8, %edi
callq 0x6ef7c
movq %rax, %r12
jmp 0x79e87
leaq 0x692f9(%rip), %rsi     # 0xe3159
leaq 0x77a56(%rip), %rdx     # 0xf18bd
leaq 0x77981(%rip), %rcx     # 0xf17ef
leaq 0x777f8(%rip), %r8      # 0xf166d
movq 0x8(%rsp), %rdi
movl $0x2b1, %r9d            # imm = 0x2B1
xorl %eax, %eax
callq 0x34f1f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x6f768
movq %r12, %rdi
callq 0x6f768
movq %r15, %rdi
callq 0x79696
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %r13
xorl %r12d, %r12d
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x7a51d
movq %rax, %r14
movq %rax, 0x10(%rsp)
movl $0x1388, %edi           # imm = 0x1388
callq 0x7a51d
addq %r14, %rax
movq %rax, 0x18(%rsp)
movl $0x8, %edi
callq 0x6ef7c
movq %rax, %r14
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r15, %rdi
movq %rax, %rcx
callq 0x793ff
testq %r14, %r14
je 0x79fdb
movq %r12, 0x20(%rsp)
movl $0x8, %edi
callq 0x6ef7c
movq %rax, %r12
movq %rbx, %rdi
callq 0x6f310
testq %rax, %rax
je 0x79f6e
xorl %ebp, %ebp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x6f037
movq (%rax), %rdi
movq %rdi, 0x30(%rsp)
movq %r13, %rsi
callq 0x7e1b2
testb %al, %al
je 0x79f5e
movl $0x8, %edx
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x6f240
incq %rbp
movq %rbx, %rdi
callq 0x6f310
cmpq %rax, %rbp
jb 0x79f2d
movq %r12, %rdi
leaq 0x145(%rip), %rbp       # 0x7a0bd
movq %rbp, %rsi
callq 0x6f383
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6f383
movq %r12, %rdi
movq %r14, %rsi
callq 0x6f3fb
testl %eax, %eax
sete %bpl
je 0x79fcc
movq 0x8(%rsp), %rdi
leaq 0x691af(%rip), %rsi     # 0xe3159
leaq 0x77883(%rip), %rdx     # 0xf1834
leaq 0x77837(%rip), %rcx     # 0xf17ef
leaq 0x776ae(%rip), %r8      # 0xf166d
movl $0x282, %r9d            # imm = 0x282
xorl %eax, %eax
callq 0x34f1f
movq %r12, %rdi
callq 0x6f768
movq 0x20(%rsp), %r12
jmp 0x79fde
movb $0x1, %bpl
movq %r14, %rdi
callq 0x6f768
testb %bpl, %bpl
je 0x79c4c
leaq 0x1(%r12), %rax
cmpq $0x270f, %r12           # imm = 0x270F
movq %rax, %r12
jb 0x79ebd
jmp 0x79c4c
leaq 0x69149(%rip), %rsi     # 0xe3159
leaq 0x777f3(%rip), %rdx     # 0xf180a
leaq 0x777d1(%rip), %rcx     # 0xf17ef
leaq 0x77648(%rip), %r8      # 0xf166d
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
movl $0x253, %r9d            # imm = 0x253
jmp 0x79c45
leaq 0x6911b(%rip), %rsi     # 0xe3159
leaq 0x77816(%rip), %rdx     # 0xf185b
leaq 0x777a3(%rip), %rcx     # 0xf17ef
leaq 0x7761a(%rip), %r8      # 0xf166d
movq 0x8(%rsp), %rdi
movl $0x2aa, %r9d            # imm = 0x2AA
xorl %eax, %eax
callq 0x34f1f
movq (%r15), %rsi
leaq 0x93(%rip), %rdx        # 0x7a102
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
xorl %ecx, %ecx
movq %r12, %r9
callq 0x79430
jmp 0x79e87
leaq 0x690cb(%rip), %rsi     # 0xe3159
leaq 0x777fa(%rip), %rdx     # 0xf188f
leaq 0x77753(%rip), %rcx     # 0xf17ef
leaq 0x775ca(%rip), %r8      # 0xf166d
movq 0x8(%rsp), %rdi
movl $0x2ad, %r9d            # imm = 0x2AD
jmp 0x79e80
movq 0x8(%rsp), %rdi
callq 0x1ca7c