// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/algo.c
// Function: mg_intv_overlap
int32_t mg_intv_overlap(void *km, int32_t n_a, const mg_intv_t *a, int32_t st, int32_t en, int32_t **b_, int32_t *m_b_)
{
	int32_t t = 0, h, *b = *b_, m_b = *m_b_, n = 0;
	istack_t stack[64], *p;

	for (h = 0; 1<<h <= n_a; ++h);
	--h;
	p = &stack[t++];
	p->k = h, p->x = (1LL<<p->k) - 1, p->w = 0; // push the root into the stack
	while (t) { // stack is not empyt
		istack_t z = stack[--t];
		if (z.k <= 3) { // the subtree is no larger than (1<<(z.k+1))-1; do a linear scan
			int32_t i, i0 = z.x >> z.k << z.k, i1 = i0 + (1LL<<(z.k+1)) - 1;
			if (i1 >= n_a) i1 = n_a;
			for (i = i0; i < i1 && a[i].st < en; ++i)
				if (st < a[i].en) {
					if (n == m_b) KEXPAND(km, b, m_b);
					b[n++] = i;
				}
		} else if (z.w == 0) { // if left child not processed
			int32_t y = z.x - (1LL<<(z.k-1));
			p = &stack[t++];
			p->k = z.k, p->x = z.x, p->w = 1;
			if (y >= n_a || a[y].far > st) {
				p = &stack[t++];
				p->k = z.k - 1, p->x = y, p->w = 0; // push the left child to the stack
			}
		} else if (z.x < n_a && a[z.x].st < en) {
			if (st < a[z.x].en) { // then z.x overlaps the query; write to the output array
				if (n == m_b) KEXPAND(km, b, m_b);
				b[n++] = z.x;
			}
			p = &stack[t++];
			p->k = z.k - 1, p->x = z.x + (1LL<<(z.k-1)), p->w = 0; // push the right child
		}
	}
	*b_ = b, *m_b_ = m_b;
	return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq 0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
cmpl -0xc(%rbp), %eax
jg 0x428a
jmp 0x427f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x426e
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq -0x440(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x448(%rbp)
movl -0x30(%rbp), %ecx
movq -0x448(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x448(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
subq $0x1, %rcx
movq -0x448(%rbp), %rax
movq %rcx, (%rax)
movq -0x448(%rbp), %rax
movl $0x0, 0xc(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x46e1
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
movslq %eax, %rcx
leaq -0x440(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x458(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x450(%rbp)
cmpl $0x3, -0x450(%rbp)
jg 0x4495
movq -0x458(%rbp), %rax
movl -0x450(%rbp), %ecx
sarq %cl, %rax
movl -0x450(%rbp), %ecx
shlq %cl, %rax
movl %eax, -0x460(%rbp)
movslq -0x460(%rbp), %rax
movl -0x450(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
addq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x464(%rbp)
movl -0x464(%rbp), %eax
cmpl -0xc(%rbp), %eax
jl 0x4399
movl -0xc(%rbp), %eax
movl %eax, -0x464(%rbp)
movl -0x460(%rbp), %eax
movl %eax, -0x45c(%rbp)
movl -0x45c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x464(%rbp), %ecx
movb %al, -0x469(%rbp)
jge 0x43db
movq -0x18(%rbp), %rax
movslq -0x45c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
setb %al
movb %al, -0x469(%rbp)
movb -0x469(%rbp), %al
testb $0x1, %al
jne 0x43ea
jmp 0x4490
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movslq -0x45c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jge 0x447a
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jne 0x445f
jmp 0x4416
cmpl $0x4, -0x3c(%rbp)
jl 0x442e
movl -0x3c(%rbp), %eax
movl -0x3c(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
movl %eax, -0x470(%rbp)
jmp 0x443b
movl $0x10, %eax
movl %eax, -0x470(%rbp)
jmp 0x443b
movl -0x470(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x2ae0
movq %rax, -0x38(%rbp)
jmp 0x445f
movl -0x45c(%rbp), %edx
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x447c
movl -0x45c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x45c(%rbp)
jmp 0x43a5
jmp 0x46dc
cmpl $0x0, -0x44c(%rbp)
jne 0x4599
movq -0x458(%rbp), %rax
movl -0x450(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq %rcx, %rax
movl %eax, -0x468(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq -0x440(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x448(%rbp)
movl -0x450(%rbp), %ecx
movq -0x448(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x458(%rbp), %rcx
movq -0x448(%rbp), %rax
movq %rcx, (%rax)
movq -0x448(%rbp), %rax
movl $0x1, 0xc(%rax)
movl -0x468(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x453f
movq -0x18(%rbp), %rax
movslq -0x468(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpl -0x1c(%rbp), %eax
jle 0x4594
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq -0x440(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x448(%rbp)
movl -0x450(%rbp), %ecx
subl $0x1, %ecx
movq -0x448(%rbp), %rax
movl %ecx, 0x8(%rax)
movslq -0x468(%rbp), %rcx
movq -0x448(%rbp), %rax
movq %rcx, (%rax)
movq -0x448(%rbp), %rax
movl $0x0, 0xc(%rax)
jmp 0x46da
movq -0x458(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpq %rcx, %rax
jge 0x46d8
movq -0x18(%rbp), %rax
movq -0x458(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
jae 0x46d8
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
movq -0x458(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jge 0x465d
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jne 0x463f
jmp 0x45f6
cmpl $0x4, -0x3c(%rbp)
jl 0x460e
movl -0x3c(%rbp), %eax
movl -0x3c(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
movl %eax, -0x474(%rbp)
jmp 0x461b
movl $0x10, %eax
movl %eax, -0x474(%rbp)
jmp 0x461b
movl -0x474(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x3c(%rbp), %rdx
shlq $0x2, %rdx
callq 0x2ae0
movq %rax, -0x38(%rbp)
jmp 0x463f
movq -0x458(%rbp), %rax
movl %eax, %edx
movq -0x38(%rbp), %rax
movl -0x40(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x40(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x2c(%rbp)
movslq %eax, %rcx
leaq -0x440(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x448(%rbp)
movl -0x450(%rbp), %ecx
subl $0x1, %ecx
movq -0x448(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x458(%rbp), %rax
movq %rax, -0x480(%rbp)
movl -0x450(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq -0x480(%rbp), %rcx
addq %rax, %rcx
movq -0x448(%rbp), %rax
movq %rcx, (%rax)
movq -0x448(%rbp), %rax
movl $0x0, 0xc(%rax)
jmp 0x46da
jmp 0x46dc
jmp 0x42f6
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x40(%rbp), %eax
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq
nopw %cs:(%rax,%rax)