// File: /workspace/github_c_makefile_star2_O2/lh3[P]minigraph/gfa-bbl.c
// Function: gfa_bubble
gfa_bubble_t *gfa_bubble(const gfa_t *g, int32_t *n_bb_)
{
	uint32_t i, *vs, *vmin, *vtmp = 0;
	int32_t n_bb = 0, m_bb = 0, m_vtmp = 0;
	gfa_bubble_t *bb = 0;
	gfa_scbuf_t *scbuf;

	GFA_MALLOC(vs, g->n_sseq);
	GFA_MALLOC(vmin, g->n_sseq);
	for (i = 0; i < g->n_sseq; ++i)
		vs[i] = (uint32_t)-1, vmin[i] = UINT32_MAX;
	for (i = 0; i < g->n_seg; ++i) {
		const gfa_seg_t *s = &g->seg[i];
		if (s->rank != 0 || s->snid < 0) continue;
		if ((uint32_t)s->soff < vmin[s->snid])
			vmin[s->snid] = s->soff, vs[s->snid] = i<<1;
	}
	free(vmin);

	scbuf = gfa_scbuf_init(g);
	for (i = 0; i < g->n_sseq; ++i) {
		gfa_sub_t *sub;
		int32_t j, jst, max_a, max_soff;
		bb_aux_t *ba;

		if (vs[i] == (uint32_t)-1) continue;
		#if 0
		sub = gfa_sub_from(0, g, vs[i], 0);
		#else
		sub = gfa_scc1(0, g, scbuf, vs[i]);
		#endif
		//gfa_sub_print(stderr, g, sub);
		GFA_CALLOC(ba, sub->n_v);
		for (j = 0; j < sub->n_v; ++j)
			ba[j].sd = INT32_MAX, ba[j].lp = ba[j].sp = -1;
		ba[0].sd = 0;
		for (j = 0; j < sub->n_v; ++j) {
			gfa_subv_t *t = &sub->v[j];
			int32_t k;
			for (k = 0; k < t->n; ++k) {
				uint64_t a = sub->a[t->off + k];
				int32_t jv = (int32_t)(a>>32);
				int32_t l = (int32_t)g->arc[(uint32_t)a].v_lv;
				if (jv <= j) continue; // skip loop or cycle
				if (ba[jv].sd >= ba[j].sd + l)
					ba[jv].sd = ba[j].sd + l, ba[jv].sp = j;
				if (ba[jv].ld < ba[j].ld + l)
					ba[jv].ld = ba[j].ld + l, ba[jv].lp = j;
			}
		}
		for (j = 0, jst = 0, max_a = max_soff = -1; j < sub->n_v; ++j) {
			gfa_subv_t *t = &sub->v[j];
			int32_t k;
			if (j == max_a && g->seg[t->v>>1].soff > max_soff) {
				const gfa_seg_t *sst = &g->seg[sub->v[jst].v>>1];
				const gfa_seg_t *sen = &g->seg[t->v>>1];
				if (sst->snid == i && sen->snid == i) {
					int32_t n, l;
					uint32_t *v;
					gfa_bubble_t *b;

					// basic information
					if (n_bb == m_bb) GFA_EXPAND(bb, m_bb);
					b = &bb[n_bb++];
					b->snid = i;
					b->vs = sub->v[jst].v;
					b->ve = t->v;
					b->ss = sst->soff + sst->len;
					b->se = sen->soff;
					b->len_min = ba[j].sd - ba[jst].sd - sst->len;
					b->len_max = ba[j].ld - ba[jst].ld - sst->len;
					b->n_paths = bb_n_paths(g, sub, jst, j);
					//fprintf(stderr, "X\t%s[%d]\tvs=%c%s\tve=%c%s\tlen_min=%d\n", g->sseq[i].name, i, "><"[b->vs&1], g->seg[b->vs>>1].name, "><"[b->ve&1], g->seg[b->ve>>1].name, b->len_min);
					assert(b->len_min >= 0);
					assert(b->len_max >= 0 && b->len_max >= b->len_min);
					b->n_seg = j - jst + 1;
					l = (b->len_min + 1) + (b->len_max + 1);
					l = (l + 3) / 4 + b->n_seg;
					GFA_CALLOC(b->v, l);
					b->seq_min = (char*)(b->v + b->n_seg);
					b->seq_max = b->seq_min + b->len_min + 1;
					for (k = jst; k <= j; ++k)
						b->v[k - jst] = sub->v[k].v;

					// test bubble involving both strands (mostly inversions)
					if (b->n_seg > m_vtmp) {
						m_vtmp = b->n_seg;
						kroundup32(m_vtmp);
						GFA_REALLOC(vtmp, m_vtmp);
					}
					for (k = 0; k < b->n_seg; ++k) vtmp[k] = b->v[k]>>1;
					radix_sort_gfa32(vtmp, vtmp + b->n_seg);
					for (k = 1; k < b->n_seg; ++k)
						if (vtmp[k] == vtmp[k-1]) break;
					b->is_bidir = (k < b->n_seg);

					// generate sequences and cf_min/cf_max
					GFA_MALLOC(v, j - jst);
					k = j, n = 0;
					while (k > jst) {
						if (k < j) v[n++] = sub->v[k].v;
						k = ba[k].sp;
					}
					bb_write_seq(g, n, v, b->len_min, b->seq_min);
					k = j, n = 0;
					while (k > jst) {
						if (k < j) v[n++] = sub->v[k].v;
						k = ba[k].lp;
					}
					bb_write_seq(g, n, v, b->len_max, b->seq_max);
					free(v);
				} // ~if(sst->snid==i&&sen->snid==i)
				max_a = max_soff = -1, jst = j;
			} // ~if(j==max_a)
			for (k = 0; k < t->n; ++k)
				if ((int32_t)(sub->a[t->off + k]>>32) > max_a)
					max_a = sub->a[t->off + k]>>32;
			if (g->seg[t->v>>1].snid == i && g->seg[t->v>>1].soff > max_soff)
				max_soff = g->seg[t->v>>1].soff;
		}
		free(ba);
		gfa_sub_destroy(sub);
	}
	free(vtmp);
	gfa_scbuf_destroy(scbuf);
	free(vs);
	*n_bb_ = n_bb;
	return bb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, 0x78(%rsp)
movq %rdi, %r13
movl 0x24(%rdi), %r14d
leaq (,%r14,4), %rbx
movq %rbx, %rdi
callq 0x2280
movq %rax, %r15
movq %rbx, %rdi
callq 0x2280
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x8f05
orl $-0x1, (%r15,%rcx,4)
orl $-0x1, (%rax,%rcx,4)
incq %rcx
jmp 0x8ef2
movl 0x4(%r13), %ecx
addq %rcx, %rcx
pushq $0x8
popq %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x8f4a
movq 0x10(%r13), %r8
cmpl $0x0, (%r8,%rdx,2)
je 0x8f2b
addq $0x2, %rsi
addq $0x20, %rdx
jmp 0x8f11
movslq -0x8(%r8,%rdx,2), %rdi
testq %rdi, %rdi
js 0x8f21
movl -0x4(%r8,%rdx,2), %r8d
cmpl (%rax,%rdi,4), %r8d
jae 0x8f21
movl %r8d, (%rax,%rdi,4)
movl %esi, (%r15,%rdi,4)
jmp 0x8f21
movq %rax, %rdi
callq 0x2040
movq %r13, %rdi
callq 0x881a
movq %rax, 0x68(%rsp)
xorl %edx, %edx
movq $0x0, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x14(%rsp)
xorl %edi, %edi
movq %r15, 0x80(%rsp)
movq %r13, 0x48(%rsp)
movl 0x24(%r13), %eax
cmpq %rax, %rdx
jae 0x959d
movl %ecx, 0x24(%rsp)
movl (%r15,%rdx,4), %ecx
cmpl $-0x1, %ecx
je 0x9591
movq %rdi, 0x28(%rsp)
movq %rdx, 0x50(%rsp)
xorl %edi, %edi
movq %r13, %rsi
movq 0x68(%rsp), %rdx
callq 0x888d
movq %rax, %rbp
movl (%rax), %r15d
movslq %r15d, %r14
movq %r14, %rdi
pushq $0x20
popq %rsi
callq 0x21e0
testl %r14d, %r14d
movl $0x0, %ecx
cmovlel %ecx, %r14d
movq %rax, %r12
movq %r14, %rax
shlq $0x5, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x9008
movl $0x7fffffff, 0x4(%r12,%rcx) # imm = 0x7FFFFFFF
orq $-0x1, 0xc(%r12,%rcx)
addq $0x20, %rcx
jmp 0x8fee
andl $0x0, 0x4(%r12)
xorl %eax, %eax
cmpq %r14, %rax
je 0x90aa
movq 0x10(%rbp), %rdx
movq %rax, %rsi
shlq $0x4, %rsi
leaq (%rdx,%rsi), %rcx
movl 0xc(%rdx,%rsi), %edx
movq %rax, %rsi
shlq $0x5, %rsi
addq %r12, %rsi
testl %edx, %edx
movl $0x0, %edi
cmovlel %edi, %edx
xorl %edi, %edi
cmpl %edi, %edx
je 0x90a2
movq 0x18(%rbp), %r8
movslq 0x8(%rcx), %r9
addq %rdi, %r9
movq (%r8,%r9,8), %r8
movq %r8, %r9
sarq $0x20, %r9
cmpq %r9, %rax
jge 0x909d
movq 0x48(%r13), %r10
movl %r8d, %r8d
shlq $0x5, %r8
movl (%r10,%r8), %r8d
shlq $0x5, %r9
leaq (%r12,%r9), %r10
movl 0x4(%rsi), %r11d
addl %r8d, %r11d
cmpl %r11d, 0x4(%r12,%r9)
jl 0x908e
movl %r11d, 0x4(%r10)
movl %eax, 0x10(%r10)
addl (%rsi), %r8d
cmpl %r8d, (%r10)
jge 0x909d
movl %r8d, (%r10)
movl %eax, 0xc(%r10)
incq %rdi
jmp 0x9042
incq %rax
jmp 0x9010
xorl %ebx, %ebx
pushq $-0x1
popq %rcx
movl %ecx, %eax
xorl %r14d, %r14d
movq 0x50(%rsp), %rdi
movslq %r15d, %rdx
cmpq %rdx, %rbx
jge 0x956f
movq 0x10(%rbp), %r8
movq %rbx, %r15
shlq $0x4, %r15
addq %r8, %r15
movl %ecx, %edx
cmpq %rdx, %rbx
jne 0x91ae
movq 0x10(%r13), %r11
movl (%r15), %edx
movl %edx, %r13d
shrl %r13d
shlq $0x6, %r13
movl 0xc(%r11,%r13), %esi
cmpl %eax, %esi
jle 0x91a9
movslq %r14d, %rax
movq %rax, %r10
shlq $0x4, %r10
movl (%r8,%r10), %r9d
movl %r9d, %ecx
shrl %ecx
shlq $0x6, %rcx
movq %rcx, 0x18(%rsp)
movl 0x8(%r11,%rcx), %ecx
cmpq %rcx, %rdi
jne 0x91a1
addq %r11, %r13
movl 0x8(%r13), %ecx
cmpq %rcx, %rdi
jne 0x91a1
movq %rax, 0x8(%rsp)
movq %r10, 0x70(%rsp)
movl 0x24(%rsp), %ecx
cmpl %ecx, 0x14(%rsp)
jne 0x9211
movl %ecx, %edx
sarl %edx
addl %ecx, %edx
testl %ecx, %ecx
pushq $0x10
popq %rax
cmovel %eax, %edx
movl %edx, 0x24(%rsp)
movslq %edx, %rax
imulq $0x48, %rax, %rsi
movq 0x38(%rsp), %rdi
movq %r11, 0x40(%rsp)
callq 0x22b0
movq 0x40(%rsp), %r11
movq 0x8(%rsp), %r10
movq 0x50(%rsp), %rdi
movq 0x10(%rbp), %rdx
movq %rdx, 0x60(%rsp)
movq 0x70(%rsp), %rcx
movl (%rdx,%rcx), %r9d
movl (%r15), %edx
movl 0xc(%r13), %esi
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
jmp 0x9226
pushq $-0x1
popq %rcx
movl %ecx, %eax
movl %ebx, %r14d
movq 0x48(%rsp), %r13
movl 0xc(%r15), %edx
testl %edx, %edx
movl $0x0, %esi
cmovlel %esi, %edx
xorl %esi, %esi
cmpl %esi, %edx
je 0x91dc
movq 0x18(%rbp), %rdi
movslq 0x8(%r15), %r8
addq %rsi, %r8
movl 0x4(%rdi,%r8,8), %edi
cmpl %edi, %ecx
cmovlel %edi, %ecx
incq %rsi
jmp 0x91be
movq 0x10(%r13), %rdx
movl (%r15), %esi
shrl %esi
shlq $0x6, %rsi
movl 0x8(%rdx,%rsi), %edi
movq 0x50(%rsp), %r8
cmpq %rdi, %r8
movq %r8, %rdi
jne 0x9205
addq %rsi, %rdx
movl 0xc(%rdx), %edx
cmpl %eax, %edx
cmovgl %edx, %eax
incq %rbx
movl (%rbp), %r15d
jmp 0x90b9
movq %r8, 0x60(%rsp)
movq 0x38(%rsp), %rax
movl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq 0x8(%rsp), %r10
addq 0x18(%rsp), %r11
movslq 0x14(%rsp), %rcx
imulq $0x48, %rcx, %rcx
leaq (%rax,%rcx), %r8
movq %r8, 0x18(%rsp)
movq %rax, %r8
movl %edi, (%rax,%rcx)
movl %r9d, 0xc(%rax,%rcx)
movl %edx, 0x10(%rax,%rcx)
movl (%r11), %eax
movl 0xc(%r11), %edx
addl %eax, %edx
movl %edx, 0x4(%r8,%rcx)
movl %esi, 0x8(%r8,%rcx)
movq %r8, 0x38(%rsp)
movq %rbx, %rdx
shlq $0x5, %rdx
movq %r10, %rsi
shlq $0x5, %rsi
movq (%r12,%rdx), %xmm0
movq (%r12,%rsi), %xmm1
movd %eax, %xmm2
pshufd $0x50, %xmm2, %xmm2     # xmm2 = xmm2[0,0,1,1]
paddd %xmm1, %xmm2
psubd %xmm2, %xmm0
movq %xmm0, 0x1c(%r8,%rcx)
movl %ebx, %eax
subl %r10d, %eax
movq %rax, 0x58(%rsp)
incl %eax
movslq %eax, %rdi
movq %rdi, 0x40(%rsp)
pushq $0x8
popq %rsi
callq 0x21e0
movq $0x1, (%rax)
movq 0x8(%rsp), %rcx
cmpq %rbx, %rcx
jge 0x933a
movq %rcx, %rsi
shlq $0x4, %rsi
movq 0x60(%rsp), %rdi
leaq (%rdi,%rsi), %rdx
movl 0xc(%rdi,%rsi), %esi
movq %rcx, %rdi
subq 0x8(%rsp), %rdi
testl %esi, %esi
movl $0x0, %r8d
cmovlel %r8d, %esi
xorl %r8d, %r8d
cmpl %r8d, %esi
je 0x9335
movq 0x18(%rbp), %r9
movslq 0x8(%rdx), %r10
addq %r8, %r10
movq (%r9,%r10,8), %r9
movq %r9, %r10
sarq $0x20, %r10
cmpq %r10, %rcx
jge 0x9330
cmpq %r10, %rbx
jl 0x9330
shrq $0x20, %r9
subl %r14d, %r9d
movslq %r9d, %r9
movq (%rax,%rdi,8), %r10
addq (%rax,%r9,8), %r10
cmpq %r13, %r10
cmovgeq %r13, %r10
movq %r10, (%rax,%r9,8)
incq %r8
jmp 0x92ee
incq %rcx
jmp 0x92be
movslq 0x58(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movq (%rax,%rcx,8), %r13
movq %rax, %rdi
callq 0x2040
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r13
cmovgeq %rax, %r13
movq 0x18(%rsp), %rcx
movl %r13d, 0x30(%rcx)
movslq 0x20(%rcx), %r13
testq %r13, %r13
js 0x95d6
movl 0x1c(%rcx), %eax
cmpl %r13d, %eax
jl 0x95f5
incl 0x14(%rsp)
movq 0x40(%rsp), %rdx
movl %edx, 0x18(%rcx)
movq %rdx, %rsi
addl %r13d, %eax
addl $0x5, %eax
cltd
pushq $0x4
popq %rcx
idivl %ecx
addl %esi, %eax
movslq %eax, %rdi
pushq $0x4
popq %rsi
callq 0x21e0
movq 0x18(%rsp), %rsi
movq %rax, 0x28(%rsi)
movq 0x40(%rsp), %rcx
leaq (%rax,%rcx,4), %rcx
movq %rcx, 0x40(%rsi)
addq %r13, %rcx
incq %rcx
movq %rcx, 0x38(%rsi)
movq 0x60(%rsp), %r8
addq 0x70(%rsp), %r8
xorl %ecx, %ecx
movq 0x48(%rsp), %r13
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %r9
cmpq %rbx, %r9
jg 0x93f6
movl (%r8,%rcx,4), %edx
movl %edx, (%rax,%rcx)
incq %r9
addq $0x4, %rcx
jmp 0x93e1
movl 0x18(%rsi), %eax
cmpl 0x34(%rsp), %eax
jle 0x943f
decl %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x34(%rsp)
leaq 0x4(,%rcx,4), %rsi
callq 0x22b0
movq 0x18(%rsp), %rsi
movq %rax, %rdi
xorl %eax, %eax
movslq 0x18(%rsi), %rcx
cmpq %rcx, %rax
jge 0x945b
movq 0x28(%rsi), %rcx
movl (%rcx,%rax,4), %ecx
shrl %ecx
movl %ecx, (%rdi,%rax,4)
incq %rax
jmp 0x9441
leaq (%rdi,%rcx,4), %rsi
movq %rdi, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x8519
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %rdi
movslq 0x18(%r8), %rax
pushq $0x1
popq %rdx
movq %rdx, %rcx
cmpq %rax, %rdx
jge 0x9494
movl (%rdi,%rcx,4), %esi
leaq 0x1(%rcx), %rdx
cmpl -0x4(%rdi,%rcx,4), %esi
jne 0x947f
xorl %edx, %edx
cmpq %rax, %rcx
setl %dl
movl %edx, 0x14(%r8)
movq 0x58(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x8(%rsp)
xorl %esi, %esi
movl %ebx, %eax
cmpl %r14d, %eax
jle 0x94ec
movslq %eax, %rcx
movl %eax, %eax
cmpq %rcx, %rbx
jle 0x94e1
movq 0x10(%rbp), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movl (%rcx,%rdx), %ecx
movslq %esi, %rdx
incl %esi
movq 0x8(%rsp), %rdi
movl %ecx, (%rdi,%rdx,4)
shlq $0x5, %rax
movl 0x10(%r12,%rax), %eax
jmp 0x94b7
movq 0x18(%rsp), %rax
movl 0x20(%rax), %ecx
movq 0x40(%rax), %r8
movq %r13, %rdi
movq 0x8(%rsp), %rdx
callq 0x9614
xorl %esi, %esi
movl %ebx, %eax
cmpl %r14d, %eax
jle 0x953e
movslq %eax, %rcx
movl %eax, %eax
cmpq %rcx, %rbx
jle 0x9533
movq 0x10(%rbp), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movl (%rcx,%rdx), %ecx
movslq %esi, %rdx
incl %esi
movq 0x8(%rsp), %rdi
movl %ecx, (%rdi,%rdx,4)
shlq $0x5, %rax
movl 0xc(%r12,%rax), %eax
jmp 0x9509
movq 0x18(%rsp), %rax
movl 0x1c(%rax), %ecx
movq 0x38(%rax), %r8
movq %r13, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x9614
movq %r14, %rdi
callq 0x2040
pushq $-0x1
popq %rcx
movl %ecx, %eax
movl %ebx, %r14d
jmp 0x91ae
movq %r12, %rdi
callq 0x2040
movq %rbp, %rdi
callq 0x8e7d
movq 0x50(%rsp), %rdx
movq 0x80(%rsp), %r15
movq 0x28(%rsp), %rdi
incq %rdx
movl 0x24(%rsp), %ecx
jmp 0x8f8b
callq 0x2040
movq 0x68(%rsp), %rdi
callq 0x8865
movq %r15, %rdi
callq 0x2040
movq 0x78(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a16d(%rip), %rdi     # 0x2374a
leaq 0x1a0d2(%rip), %rsi     # 0x236b6
leaq 0x1a16f(%rip), %rcx     # 0x2375a
movl $0x13d, %edx            # imm = 0x13D
callq 0x2160
leaq 0x1a191(%rip), %rdi     # 0x2378d
leaq 0x1a0b3(%rip), %rsi     # 0x236b6
leaq 0x1a150(%rip), %rcx     # 0x2375a
movl $0x13e, %edx            # imm = 0x13E
callq 0x2160