// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x8
popq %rdi
callq 0x4b380
movq %rax, %r14
movl $0xbb8, %r15d           # imm = 0xBB8
pushq $0x1
popq %r12
pushq $0x10
popq %r13
leaq 0x18(%rsp), %rbp
subq $0x1, %r15
jb 0x5850d
movq %r12, %rdi
movq %r13, %rsi
leaq 0x8215a(%rip), %rdx     # 0xda61d
movl $0x234, %ecx            # imm = 0x234
callq 0xce9a
movq %rax, 0x18(%rsp)
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x58dd2
movq %rax, %rbx
movq 0x18(%rsp), %rax
movq %rbx, (%rax)
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x58dd2
addq %rbx, %rax
movq 0x18(%rsp), %rcx
movq %rax, 0x8(%rcx)
movq %r14, %rdi
movq %rbp, %rsi
pushq $0x8
popq %rdx
callq 0x4b801
jmp 0x584b0
leaq -0x4b185(%rip), %rdi    # 0xd38f
callq 0x57bf5
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
cmpq $0xbb8, %rbx            # imm = 0xBB8
je 0x58555
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4b48e
movq (%rax), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
callq 0x57bc0
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x57f19
incq %rbx
jmp 0x58520
movq 0x10(%rsp), %rdi
callq 0x57c1f
xorl %r13d, %r13d
cmpq $0xbb8, %rax            # imm = 0xBB8
je 0x5859c
leaq 0x73be8(%rip), %rsi     # 0xcc159
leaq 0x821fb(%rip), %rdx     # 0xda773
leaq 0x82220(%rip), %rcx     # 0xda79f
leaq 0x82097(%rip), %r8      # 0xda61d
movq 0x8(%rsp), %rdi
movl $0x246, %r9d            # imm = 0x246
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %r13
leaq 0x18(%rsp), %rbx
leaq 0x82075(%rip), %r12     # 0xda61d
xorl %ebp, %ebp
testl %r13d, %r13d
jne 0x5869b
cmpq $0x493e0, %rbp          # imm = 0x493E0
jae 0x5869b
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x58dd2
movq %rax, %r15
movq %rax, 0x18(%rsp)
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x58dd2
addq %rax, %r15
movq %r15, 0x20(%rsp)
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %r15, %rdx
callq 0x57cd6
testq %rax, %rax
je 0x58613
movq 0x18(%rax), %rsi
movq %rbx, %rdi
callq 0x5d0a4
testb %al, %al
je 0x58665
xorl %r13d, %r13d
jmp 0x58693
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x4b988
cmpq %rax, %r15
jae 0x5860b
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b48e
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x5d0a4
incq %r15
testb %al, %al
je 0x58616
movq 0x8(%rsp), %rdi
leaq 0x73b0d(%rip), %rsi     # 0xcc159
leaq 0x8218a(%rip), %rdx     # 0xda7dd
leaq 0x82145(%rip), %rcx     # 0xda79f
movq %r12, %r8
movl $0x263, %r9d            # imm = 0x263
jmp 0x58688
movq 0x8(%rsp), %rdi
leaq 0x73ae8(%rip), %rsi     # 0xcc159
leaq 0x82142(%rip), %rdx     # 0xda7ba
leaq 0x82120(%rip), %rcx     # 0xda79f
movq %r12, %r8
movl $0x253, %r9d            # imm = 0x253
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %r13
incq %rbp
jmp 0x585aa
pushq $0x8
popq %rbx
leaq 0x18(%rsp), %r12
xorl %eax, %eax
testl %r13d, %r13d
jne 0x587e2
cmpq $0x270f, %rax           # imm = 0x270F
ja 0x587e2
movq %rax, 0x28(%rsp)
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x58dd2
movq %rax, %r15
movq %rax, 0x18(%rsp)
movl $0x1388, %edi           # imm = 0x1388
callq 0x58dd2
addq %r15, %rax
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0x4b380
movq %rax, %rbp
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rdi
movq %rax, %rcx
callq 0x57dbe
testq %rbp, %rbp
je 0x587bd
movq %rbx, %rdi
callq 0x4b380
movq %rax, %r15
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x4b988
cmpq %rax, %r13
jae 0x5875d
movq %r14, %rdi
movq %r13, %rsi
callq 0x4b48e
movq (%rax), %rdi
movq %rdi, 0x30(%rsp)
movq %r12, %rsi
callq 0x5d0a4
testb %al, %al
je 0x58758
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x4b801
incq %r13
jmp 0x5871c
movq %r15, %rdi
leaq 0x350(%rip), %r13       # 0x58ab7
movq %r13, %rsi
callq 0x4baed
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4baed
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4bbfe
testl %eax, %eax
je 0x587c2
movq 0x8(%rsp), %rdi
leaq 0x739c4(%rip), %rsi     # 0xcc159
leaq 0x82048(%rip), %rdx     # 0xda7e4
leaq 0x81ffc(%rip), %rcx     # 0xda79f
leaq 0x81e73(%rip), %r8      # 0xda61d
movl $0x282, %r9d            # imm = 0x282
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %r13
jmp 0x587c5
xorl %r13d, %r13d
jmp 0x587cd
xorl %r13d, %r13d
movq %r15, %rdi
callq 0x4c19d
movq %rbp, %rdi
callq 0x4c19d
movq 0x28(%rsp), %rax
incq %rax
jmp 0x586a5
movq 0x10(%rsp), %rdi
callq 0x580d2
xorl %edi, %edi
callq 0x57bf5
movq %rax, %r15
movq %r14, %rdi
callq 0x4ba50
pushq $-0x1
popq %rbp
testl %r13d, %r13d
jne 0x58896
xorl %ebx, %ebx
cmpq $0xbb8, %rbx            # imm = 0xBB8
je 0x5884b
movl $0x15f90, %edi          # imm = 0x15F90
callq 0x58dd2
movq %rax, %r12
movl $0x2bc, %edi            # imm = 0x2BC
callq 0x58dd2
leaq (%rax,%r12), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x57bc0
movq %r15, %rdi
movq %rax, %rsi
callq 0x57f19
incq %rbx
jmp 0x5880c
pushq $-0x1
popq %rbp
testl %r13d, %r13d
jne 0x58896
movq %r15, %rdi
callq 0x57c1f
xorl %ebp, %ebp
cmpq $0xbb8, %rax            # imm = 0xBB8
je 0x58896
leaq 0x738ed(%rip), %rsi     # 0xcc159
leaq 0x81f00(%rip), %rdx     # 0xda773
leaq 0x81f25(%rip), %rcx     # 0xda79f
leaq 0x81d9c(%rip), %r8      # 0xda61d
movq 0x8(%rsp), %rdi
movl $0x296, %r9d            # imm = 0x296
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %rbp
pushq $0x8
popq %rdi
callq 0x4b380
movq %rax, %r12
xorl %ebx, %ebx
testl %ebp, %ebp
jne 0x58a8e
cmpq $0xbb7, %rbx            # imm = 0xBB7
ja 0x58a8e
movq (%r15), %rsi
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
leaq 0x264(%rip), %rdx       # 0x58b2f
xorl %ecx, %ecx
movq %r12, %r9
callq 0x57e22
movq %r12, %rdi
callq 0x4b988
leaq -0x1(%rax), %rdi
callq 0x58dd2
movq %r12, %rdi
movq %rax, %rsi
callq 0x4b48e
movq (%rax), %r13
testq %r13, %r13
jne 0x58927
movq 0x8(%rsp), %rdi
leaq 0x73854(%rip), %rsi     # 0xcc159
leaq 0x81ef2(%rip), %rdx     # 0xda7fe
leaq 0x81e8c(%rip), %rcx     # 0xda79f
leaq 0x81d03(%rip), %r8      # 0xda61d
movl $0x2a4, %r9d            # imm = 0x2A4
xorl %eax, %eax
callq 0xc007
movq %r13, %rdi
callq 0x57c60
movq %rax, %rbp
movq %r15, %rdi
movq %r13, %rsi
callq 0x5815e
movq %r12, %rdi
callq 0x4ba50
testq %r13, %r13
movq %rbx, 0x10(%rsp)
je 0x589f2
movq 0x50(%r15), %r13
movl $0xbb7, %eax            # imm = 0xBB7
subq %rbx, %rax
cmpq %rax, %r13
jne 0x589c4
movq (%r15), %rsi
xorl %ebx, %ebx
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
leaq 0x1b6(%rip), %rdx       # 0x58b2f
xorl %ecx, %ecx
movq %r12, %r9
callq 0x57e22
movq %r12, %rdi
callq 0x4b988
cmpq %r13, %rax
je 0x58a14
movq 0x8(%rsp), %rdi
leaq 0x737b9(%rip), %rsi     # 0xcc159
leaq 0x81e98(%rip), %rdx     # 0xda83f
leaq 0x81df1(%rip), %rcx     # 0xda79f
leaq 0x81c68(%rip), %r8      # 0xda61d
movl $0x2ad, %r9d            # imm = 0x2AD
xorl %eax, %eax
callq 0xc007
jmp 0x58a0f
movq 0x8(%rsp), %rdi
leaq 0x73789(%rip), %rsi     # 0xcc159
leaq 0x81e34(%rip), %rdx     # 0xda80b
leaq 0x81dc1(%rip), %rcx     # 0xda79f
leaq 0x81c38(%rip), %r8      # 0xda61d
movl $0x2aa, %r9d            # imm = 0x2AA
xorl %eax, %eax
callq 0xc007
movq (%r15), %rsi
movl $0x1624c, %r8d          # imm = 0x1624C
movq %r15, %rdi
leaq 0x12a(%rip), %rdx       # 0x58b2f
xorl %ecx, %ecx
movq %r12, %r9
callq 0x57e22
pushq $-0x1
popq %rax
movl %eax, %ebx
xorl %r13d, %r13d
testl %ebx, %ebx
jne 0x58a7a
movq %r12, %rdi
callq 0x4b988
cmpq %rax, %r13
jae 0x58a7f
movq %r12, %rdi
movq %r13, %rsi
callq 0x4b48e
movq (%rax), %rdi
callq 0x57c60
xorl %ebx, %ebx
cmpq %rbp, %rax
jne 0x58a75
movq 0x8(%rsp), %rdi
leaq 0x7370b(%rip), %rsi     # 0xcc159
leaq 0x81e18(%rip), %rdx     # 0xda86d
leaq 0x81d43(%rip), %rcx     # 0xda79f
leaq 0x81bba(%rip), %r8      # 0xda61d
movl $0x2b1, %r9d            # imm = 0x2B1
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %rax
movl %eax, %ebx
incq %r13
jmp 0x58a17
pushq $-0x1
popq %rbp
jmp 0x58a81
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
incq %rbx
jmp 0x588a3
movq %r14, %rdi
callq 0x4c19d
movq %r12, %rdi
callq 0x4c19d
movq %r15, %rdi
callq 0x580d2
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq