// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bntseq.c
// Function: bns_cnt_ambi
int bns_cnt_ambi(const bntseq_t *bns, int64_t pos_f, int len, int *ref_id)
{
	int left, mid, right, nn;
	if (ref_id) *ref_id = bns_pos2rid(bns, pos_f);
	left = 0; right = bns->n_holes; nn = 0;
	while (left < right) {
		mid = (left + right) >> 1;
		if (pos_f >= bns->ambs[mid].offset + bns->ambs[mid].len) left = mid + 1;
		else if (pos_f + len <= bns->ambs[mid].offset) right = mid;
		else { // overlap
			if (pos_f >= bns->ambs[mid].offset) {
				nn += bns->ambs[mid].offset + bns->ambs[mid].len < pos_f + len?
					bns->ambs[mid].offset + bns->ambs[mid].len - pos_f : len;
			} else {
				nn += bns->ambs[mid].offset + bns->ambs[mid].len < pos_f + len?
					bns->ambs[mid].len : len - (bns->ambs[mid].offset - pos_f);
			}
			break;
		}
	}
	return nn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x17c23
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x179d0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x17e15
movl -0x24(%rbp), %eax
addl -0x2c(%rbp), %eax
sarl %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq -0x8(%rbp), %rdx
movq 0x20(%rdx), %rdx
movslq -0x28(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rdx
movslq 0x8(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jl 0x17c99
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x17e10
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jg 0x17cc7
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x17e0e
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jl 0x17d7c
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jge 0x17d61
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
subq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x17d69
movslq -0x14(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
jmp 0x17e0c
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jge 0x17dd9
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x17dfe
movslq -0x14(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rcx
movslq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subq -0x10(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
jmp 0x17e15
jmp 0x17e10
jmp 0x17c3b
movl -0x30(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop