// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movl %ecx, %r10d
movq %rdi, 0x18(%rsp)
movq 0x480(%rsp), %rcx
movq %r9, 0x28(%rsp)
movq (%r9), %rax
movl (%rcx), %r11d
movl $0xfffffffe, %r9d       # imm = 0xFFFFFFFE
leal 0x2(%r9), %ecx
movl $0x1, %edi
shll %cl, %edi
incl %r9d
cmpl %esi, %edi
jle 0x3eca
movq $-0x1, %rdi
movl %r9d, %ecx
shlq %cl, %rdi
movl %r9d, 0x48(%rsp)
notq %rdi
movq %rdi, 0x40(%rsp)
movl $0x0, 0x4c(%rsp)
movl %esi, 0x8(%rsp)
movslq %esi, %rcx
movq %rcx, 0x38(%rsp)
movq %rdx, 0x10(%rsp)
leaq 0x4(%rdx), %rcx
movq %rcx, 0x30(%rsp)
xorl %ebx, %ebx
movl $0x1, %r13d
leaq 0x40(%rsp), %rsi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl %r10d, 0xc(%rsp)
leal -0x1(%r13), %ecx
movl %ecx, 0x4(%rsp)
movslq %r13d, %rbp
shlq $0x4, %rbp
movq -0x10(%rbp,%rsi), %r12
movslq -0x8(%rbp,%rsi), %r15
cmpq $0x3, %r15
jg 0x4005
movl %r15d, %ecx
shrq %cl, %r12
shlq %cl, %r12
incb %r15b
movl $0x1, %edx
movl %r15d, %ecx
shlq %cl, %rdx
leal (%r12,%rdx), %ebp
decl %ebp
movl 0x8(%rsp), %ecx
cmpl %ecx, %ebp
cmovgel %ecx, %ebp
cmpl %r12d, %ebp
jle 0x40c6
movslq %r12d, %r15
shlq $0x4, %r15
addq 0x30(%rsp), %r15
cmpl %r8d, -0x4(%r15)
jae 0x40c6
movl (%r15), %ecx
andl %r9d, %ecx
cmpl %r10d, %ecx
jle 0x3ff4
cmpl %r11d, %ebx
jne 0x3feb
movl %r11d, %r13d
sarl %r13d
addl %r11d, %r13d
cmpl $0x4, %r11d
movl $0x10, %ecx
cmovll %ecx, %r13d
movslq %r13d, %rdx
shlq $0x2, %rdx
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movl %r8d, %r14d
callq 0x31ed
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
leaq 0x40(%rsp), %rsi
movl 0xc(%rsp), %r10d
movl %r14d, %r8d
movl %r13d, %r11d
movslq %ebx, %rcx
incl %ebx
movl %r12d, (%rax,%rcx,4)
incl %r12d
addq $0x10, %r15
cmpl %r12d, %ebp
jne 0x3f8e
jmp 0x40c6
leaq (%rsi,%rbp), %rdi
addq $-0x4, %rdi
cmpl $0x0, (%rdi)
je 0x40cc
cmpq 0x38(%rsp), %r12
jge 0x40c6
movq %r12, %rcx
shlq $0x4, %rcx
movq 0x10(%rsp), %rdx
cmpl %r8d, (%rdx,%rcx)
jae 0x40c6
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
andl %r9d, %ecx
cmpl %r10d, %ecx
jle 0x40a4
cmpl %r11d, %ebx
jne 0x409b
movl %r11d, %r14d
sarl %r14d
addl %r11d, %r14d
cmpl $0x4, %r11d
movl $0x10, %ecx
cmovll %ecx, %r14d
movslq %r14d, %rdx
shlq $0x2, %rdx
movq %rdi, 0x20(%rsp)
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movl %r8d, 0x4(%rsp)
callq 0x31ed
movq 0x20(%rsp), %rdi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
leaq 0x40(%rsp), %rsi
movl 0xc(%rsp), %r10d
movl 0x4(%rsp), %r8d
movl %r14d, %r11d
movslq %ebx, %rcx
incl %ebx
movl %r12d, (%rax,%rcx,4)
decl %r15d
movl $0x1, %edx
movl %r15d, %ecx
shlq %cl, %rdx
leaq (%rsi,%rbp), %rcx
addq $-0x10, %rcx
movl %r15d, 0x8(%rcx)
addq %r12, %rdx
movq %rdx, (%rcx)
jmp 0x411c
movl 0x4(%rsp), %ecx
jmp 0x4125
decl %r15d
movq $-0x1, %rdx
movl %r15d, %ecx
shlq %cl, %rdx
addq %r12, %rdx
movl $0x1, (%rdi)
movq %rdx, %rcx
shlq $0x20, %rcx
cmpl 0x8(%rsp), %edx
jge 0x4105
movq %rcx, %rdx
sarq $0x1c, %rdx
movq 0x10(%rsp), %rdi
cmpl %r10d, 0x8(%rdi,%rdx)
jle 0x4122
incl %r13d
leaq (%rsp,%rbp), %rdi
addq $0x4c, %rdi
movl %r15d, -0x4(%rdi)
sarq $0x20, %rcx
movq %rcx, -0xc(%rdi)
movl $0x0, (%rdi)
movl %r13d, %ecx
movl %ecx, %r13d
testl %ecx, %ecx
jne 0x3f30
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq 0x480(%rsp), %rax
movl %r11d, (%rax)
movl %ebx, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq