// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/rangeTree.c
// Function: rangeTreeAddToCoverageDepth
void rangeTreeAddToCoverageDepth(struct rbTree *tree, int start, int end)
/* Add area from start to end to a tree that is being built up to store the
 * depth of coverage.  Recover coverage back out by looking at ptToInt(range->val)
 * on tree elements. */
{
struct range q;
q.start = start;
q.end = end;

struct range *r, *existing = rbTreeFind(tree, &q);
if (existing == NULL)
    {
    lmAllocVar(tree->lm, r);
    r->start = start;
    r->end = end;
    r->val = intToPt(1);
    rbTreeAdd(tree, r);
    }
else
    {
    if (existing->start <= start && existing->end >= end)
    /* The existing one completely encompasses us */
        {
	/* Make a new section for the bit before start. */
	if (existing->start < start)
	    {
	    lmAllocVar(tree->lm, r);
	    r->start = existing->start;
	    r->end = start;
	    r->val = existing->val;
	    existing->start = start;
	    rbTreeAdd(tree, r);
	    }
	/* Make a new section for the bit after end. */
	if (existing->end > end)
	    {
	    lmAllocVar(tree->lm, r);
	    r->start = end;
	    r->end = existing->end;
	    r->val = existing->val;
	    existing->end = end;
	    rbTreeAdd(tree, r);
	    }
	/* Increment existing section in overlapping area. */
        existing->val = (char *)(existing->val) + 1;
	}
    else
    /* In general case fetch list of regions that overlap us. 
       Remaining cases to handle are: 
	     r >> e     rrrrrrrrrrrrrrrrrrrr
			     eeeeeeeeee

	     e < r           rrrrrrrrrrrrrrr
			eeeeeeeeeeee

	     r < e      rrrrrrrrrrrr
			     eeeeeeeeeeeee
     */
        {
	struct range *existingList = rangeTreeAllOverlapping(tree, start, end);

#ifdef DEBUG
	/* Make sure that list is really sorted for debugging... */
	int lastStart = existingList->start;
	for (r = existingList; r != NULL; r = r->next)
	    {
	    int start = r->start;
	    if (start < lastStart)
	        internalErr();
	    }
#endif /* DEBUG */

	int s = start, e = end;
	for (existing = existingList; existing != NULL; existing = existing->next)
	    {
	    /* Deal with start of new range that comes before existing */
	    if (s < existing->start)
	        {
		lmAllocVar(tree->lm, r);
		r->start = s;
		r->end = existing->start;
		r->val = intToPt(1);
		s = existing->start;
		rbTreeAdd(tree, r);
		}
	    else if (s > existing->start)
	        {
		lmAllocVar(tree->lm, r);
		r->start = existing->start;
		r->end = s;
		r->val = existing->val;
		existing->start = s;
		rbTreeAdd(tree, r);
		}
	    existing->val = (char *)(existing->val) + 1;
	    s = existing->end;
	    }
	if (s < e)
	/* Deal with end of new range that doesn't overlap with anything. */
	    {
	    lmAllocVar(tree->lm, r);
	    r->start = s;
	    r->end = e;
	    r->val = intToPt(1);
	    rbTreeAdd(tree, r);
	    }
	}
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x54430
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x537d7
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movl -0xc(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x10(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x1, %edi
callq 0x47e00
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
jmp 0x53a55
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
jg 0x538d2
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x10(%rbp), %eax
jl 0x538d2
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0xc(%rbp), %eax
jge 0x53858
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0xc(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0xc(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x10(%rbp), %eax
jle 0x538b9
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movl -0x10(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x10(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x53a53
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x53a60
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x539fd
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x5396c
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x1, %edi
callq 0x47e00
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
jmp 0x539cf
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x539cd
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x44(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
jmp 0x539cf
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x538f9
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x53a51
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movl $0x18, %esi
callq 0x3de60
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x48(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x1, %edi
callq 0x47e00
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x53fe0
jmp 0x53a53
jmp 0x53a55
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)