// File: /workspace/github_c_makefile_star2_O1/lh3[P]minigraph/gchain1.c
// Function: mg_gchain_gen
mg_gchains_t *mg_gchain_gen(void *km_dst, void *km, const gfa_t *g, const gfa_edseq_t *es, int32_t n_u, const uint64_t *u,
							mg_lchain_t *lc, const mg128_t *a, uint32_t hash, int32_t min_gc_cnt, int32_t min_gc_score,
							int32_t gdp_max_ed, int32_t n_seg, const char *qseq)
{
	mg_gchains_t *gc;
	int32_t i, j, k, st, kmer_size;
	bridge_aux_t aux;

	// preallocate gc->gc and gc->a
	KCALLOC(km_dst, gc, 1);
	for (i = 0, st = 0; i < n_u; ++i) {
		int32_t m = 0, nui = (int32_t)u[i];
		for (j = 0; j < nui; ++j) m += lc[st + j].cnt; // m is the number of anchors in this gchain
		if (m >= min_gc_cnt && u[i]>>32 >= min_gc_score)
			gc->n_gc++, gc->n_a += m;
		st += nui;
	}
	if (gc->n_gc == 0) return gc;
	gc->km = km_dst;
	KCALLOC(km_dst, gc->gc, gc->n_gc);
	KMALLOC(km_dst, gc->a, gc->n_a);

	// core loop
	memset(&aux, 0, sizeof(aux));
	aux.km = km, aux.g = g, aux.es = es, aux.n_seg = n_seg, aux.qseq = qseq;
	kmer_size = a[0].y>>32&0xff;
	for (i = k = 0, st = 0, aux.n_a = 0; i < n_u; ++i) {
		int32_t n_a0 = aux.n_a, n_llc0 = aux.n_llc, m = 0, nui = (int32_t)u[i];
		for (j = 0; j < nui; ++j) m += lc[st + j].cnt;
		if (m >= min_gc_cnt && u[i]>>32 >= min_gc_score) {
			uint32_t h = hash;
			int32_t j0;
			gc->gc[k].score = u[i]>>32;
			gc->gc[k].off = n_llc0;
			for (j = 0; j < nui; ++j) {
				const mg_lchain_t *p = &lc[st + j];
				h += kh_hash_uint32(p->qs) + kh_hash_uint32(p->re) + kh_hash_uint32(p->v);
			}
			gc->gc[k].hash = kh_hash_uint32(h);

			for (j = 1; j < nui; ++j)
				resolve_overlap(&lc[st + j - 1], &lc[st + j], a);

			if (aux.n_llc == aux.m_llc) KEXPAND(aux.km, aux.llc, aux.m_llc);
			copy_lchain(&aux.llc[aux.n_llc++], &lc[st], &aux.n_a, gc->a, a, -1); // copy the first lchain
			for (j0 = 0, j = 1; j < nui; ++j) {
				const mg_lchain_t *l0 = &lc[st + j0], *l1 = &lc[st + j];
				if (l1->cnt > 0) {
					int32_t ret, t;
					ret = bridge_lchains(gc, &aux, kmer_size, gdp_max_ed, l0, l1, a);
					if (ret < 0) {
						for (t = j0; t < j; ++t) {
							ret = bridge_lchains(gc, &aux, kmer_size, gdp_max_ed, &lc[st + t], &lc[st + t + 1], a);
							assert(ret >= 0);
						}
					}
					j0 = j;
				}
			}

			gc->gc[k].cnt = aux.n_llc - n_llc0;
			gc->gc[k].n_anchor = aux.n_a - n_a0;
			++k;
		}
		st += nui;
	}
	assert(aux.n_a <= gc->n_a);

	gc->n_a = aux.n_a;
	gc->n_lc = aux.n_llc;
	KMALLOC(km_dst, gc->lc, aux.n_llc);
	memcpy(gc->lc, aux.llc, aux.n_llc * sizeof(mg_llchain_t));
	kfree(km, aux.llc);

	mg_gchain_extra(g, gc);
	mg_gchain_sort_by_score(km, gc);
	return gc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r9, 0xa8(%rsp)
movl %r8d, %ebx
movq %rcx, %r14
movq %rdx, 0x80(%rsp)
movq %rsi, 0x88(%rsp)
movl 0x140(%rsp), %ebp
movl $0x1, %esi
movl $0x30, %edx
movq %rdi, 0x78(%rsp)
callq 0x3054
movslq %ebp, %rcx
movq %rcx, 0x98(%rsp)
movq %rax, %rbp
movl %ebx, %eax
movq %rax, 0xa0(%rsp)
testl %ebx, %ebx
jle 0x19f2d
movq 0x120(%rsp), %rax
addq $0x4, %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0xa8(%rsp), %rsi
movq (%rsi,%rcx,8), %rsi
movl $0x0, %edi
testl %esi, %esi
jle 0x19efe
movslq %edx, %rdi
movl %esi, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,4), %rdi
leaq (%rax,%rdi,8), %r9
xorl %edi, %edi
movl (%r9), %r10d
addl %r10d, %r10d
sarl %r10d
addl %r10d, %edi
addq $0x28, %r9
decq %r8
jne 0x19ee9
cmpl 0x138(%rsp), %edi
jl 0x19f1e
movq %rsi, %r8
shrq $0x20, %r8
cmpq 0x98(%rsp), %r8
jb 0x19f1e
incl 0x8(%rbp)
addl %edi, 0x10(%rbp)
addl %esi, %edx
incq %rcx
cmpq 0xa0(%rsp), %rcx
jne 0x19ebd
movslq 0x8(%rbp), %rsi
testq %rsi, %rsi
je 0x1a6b7
movq %rbp, %r13
movl 0x150(%rsp), %r15d
movq 0x128(%rsp), %r12
movq 0x78(%rsp), %rbp
movq %rbp, (%r13)
movl $0x68, %edx
movq %rbp, %rdi
callq 0x3054
movq %rax, 0x18(%r13)
movslq 0x10(%r13), %rsi
shlq $0x4, %rsi
movq %rbp, %rdi
callq 0x31c1
movq %r13, %rbp
movq %rax, 0x28(%r13)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r14, 0x50(%rsp)
movl %r15d, 0x60(%rsp)
movq 0x158(%rsp), %rax
movq %rax, 0x58(%rsp)
movzbl 0xc(%r12), %eax
movl %eax, 0x2c(%rsp)
movl $0x0, 0x6c(%rsp)
testl %ebx, %ebx
jle 0x1a645
movq 0x120(%rsp), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0xb8(%rsp)
addq $0x14, %rax
movq %rax, 0xb0(%rsp)
movq 0x128(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0xc8(%rsp)
addq $0x8, %rax
movq %rax, 0xd0(%rsp)
xorl %ecx, %ecx
movl $0x0, 0x24(%rsp)
movq $0x0, 0x18(%rsp)
movq 0xa8(%rsp), %rax
movq %rcx, 0xc0(%rsp)
movq (%rax,%rcx,8), %r8
movl $0x0, %eax
testl %r8d, %r8d
jle 0x1a086
movslq 0x18(%rsp), %rax
movl %r8d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rax,%rax,4), %rax
movq 0xb8(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
xorl %eax, %eax
movl (%rdx), %esi
addl %esi, %esi
sarl %esi
addl %esi, %eax
addq $0x28, %rdx
decq %rcx
jne 0x1a075
cmpl 0x138(%rsp), %eax
jl 0x1a61f
movq %r8, %rcx
shrq $0x20, %rcx
cmpq 0x98(%rsp), %rcx
jb 0x1a61f
movl 0x64(%rsp), %esi
movl 0x6c(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x18(%rbp), %rax
movslq 0x24(%rsp), %rdx
imulq $0x68, %rdx, %rdx
movl %ecx, 0x14(%rax,%rdx)
movq %rdx, 0x90(%rsp)
movq %rsi, 0x38(%rsp)
movl %esi, 0x8(%rax,%rdx)
movslq 0x18(%rsp), %rcx
movq %rcx, 0x30(%rsp)
movl 0x130(%rsp), %edi
movq %r8, 0x10(%rsp)
testl %r8d, %r8d
jle 0x1a1e0
movq 0x10(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %rdx
leaq (%rdx,%rdx,4), %rdx
movq 0xb0(%rsp), %rsi
leaq (%rsi,%rdx,8), %rdx
movl (%rdx), %esi
movl %esi, %r8d
shll $0xf, %r8d
notl %r8d
addl %esi, %r8d
movl %r8d, %esi
shrl $0xa, %esi
xorl %r8d, %esi
leal (%rsi,%rsi,8), %esi
movl %esi, %r8d
shrl $0x6, %r8d
xorl %esi, %r8d
movl %r8d, %r9d
shll $0xb, %r9d
notl %r9d
addl %r8d, %r9d
movl %r9d, %esi
shrl $0x10, %esi
xorl %r9d, %esi
addl %edi, %esi
movl -0xc(%rdx), %edi
movl -0x4(%rdx), %r8d
movl %r8d, %r9d
shll $0xf, %r9d
notl %r9d
addl %r8d, %r9d
movl %r9d, %r8d
shrl $0xa, %r8d
xorl %r9d, %r8d
leal (%r8,%r8,8), %r8d
movl %r8d, %r9d
shrl $0x6, %r9d
xorl %r8d, %r9d
movl %r9d, %r10d
shll $0xb, %r10d
notl %r10d
addl %r9d, %r10d
movl %r10d, %r8d
shrl $0x10, %r8d
xorl %r10d, %r8d
movl %edi, %r9d
shll $0xf, %r9d
notl %r9d
addl %edi, %r9d
movl %r9d, %edi
shrl $0xa, %edi
xorl %r9d, %edi
leal (%rdi,%rdi,8), %edi
movl %edi, %r9d
shrl $0x6, %r9d
xorl %edi, %r9d
movl %r9d, %r10d
shll $0xb, %r10d
notl %r10d
addl %r9d, %r10d
movl %r10d, %edi
shrl $0x10, %edi
xorl %r10d, %edi
addl %r8d, %edi
addl %esi, %edi
addq $0x28, %rdx
decq %rcx
jne 0x1a115
movl %edi, %ecx
shll $0xf, %ecx
notl %ecx
addl %edi, %ecx
movl %ecx, %edx
shrl $0xa, %edx
xorl %ecx, %edx
leal (%rdx,%rdx,8), %ecx
movl %ecx, %edx
shrl $0x6, %edx
xorl %ecx, %edx
movl %edx, %ecx
shll $0xb, %ecx
notl %ecx
addl %edx, %ecx
movl %ecx, %edx
shrl $0x10, %edx
xorl %ecx, %edx
movq 0x90(%rsp), %rcx
movl %edx, 0x38(%rax,%rcx)
cmpl $0x2, 0x10(%rsp)
jl 0x1a42b
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0xd8(%rsp)
movq 0x30(%rsp), %rax
leaq (%rax,%rax,4), %rax
movq 0x120(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0xe0(%rsp)
movl $0x1, %edx
leaq (%rdx,%rdx,4), %rax
movq 0xe0(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movslq (%rsi), %r9
shlq $0x4, %r9
movl -0x24(%rsi), %edi
leal (%rdi,%rdi), %r8d
sarl %r8d
movl %r8d, %r10d
testl %r8d, %r8d
jle 0x1a2da
movq 0x128(%rsp), %rax
movl (%rax,%r9), %r11d
movl 0x8(%rax,%r9), %ebx
movslq -0x28(%rsi), %rcx
movq %rdi, %r10
shlq $0x21, %r10
sarq $0x21, %r10
shlq $0x4, %rcx
addq 0xc8(%rsp), %rcx
movq %r10, %rax
shlq $0x4, %rax
addq %rcx, %rax
cmpl %ebx, (%rax)
jg 0x1a2c6
movl -0x20(%rsi), %ecx
cmpl 0x8(%rsi), %ecx
jne 0x1a2da
cmpl %r11d, -0x8(%rax)
jle 0x1a2da
decq %r10
leaq 0x1(%r10), %rcx
addq $-0x10, %rax
cmpq $0x1, %rcx
jg 0x1a2b4
xorl %r10d, %r10d
movl 0x4(%rsi), %eax
addl %eax, %eax
sarl %eax
testl %eax, %eax
jle 0x1a6cc
movl -0x28(%rsi), %r11d
leal (%r11,%r8), %ecx
subl %r10d, %r8d
movslq %ecx, %rcx
shlq $0x4, %rcx
movq 0x128(%rsp), %r10
movl -0x10(%r10,%rcx), %ebx
movl -0x8(%r10,%rcx), %r14d
movl %eax, %r12d
addq 0xd0(%rsp), %r9
movq %r12, %r13
negq %r13
movb $0x1, %al
movl $0x1, %ecx
xorl %r10d, %r10d
cmpl %r14d, (%r9)
jl 0x1a33d
movl -0x20(%rsi), %r15d
cmpl 0x8(%rsi), %r15d
jne 0x1a357
cmpl %ebx, -0x8(%r9)
jge 0x1a357
cmpq %r12, %rcx
setb %al
decq %r10
addq $0x10, %r9
incq %rcx
cmpq %r10, %r13
jne 0x1a328
jmp 0x1a6cc
testb $0x1, %al
je 0x1a6cc
testl %r8d, %r8d
jle 0x1a3a5
movl %edi, %eax
subl %r8d, %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %edi       # imm = 0x80000000
orl %ecx, %edi
movl %edi, -0x24(%rsi)
addl %eax, %eax
je 0x1a3a5
sarl %eax
addl %r11d, %eax
cltq
shlq $0x4, %rax
movq 0x128(%rsp), %rdi
movl -0x8(%rdi,%rax), %ecx
incl %ecx
movl %ecx, -0x10(%rsi)
movl -0x10(%rdi,%rax), %eax
incl %eax
movl %eax, -0x18(%rsi)
testq %r10, %r10
je 0x1a3ff
movslq (%rsi), %rax
subq %r10, %rax
movl %eax, (%rsi)
movl 0x4(%rsi), %ecx
addl %ecx, %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %r10d, %ecx
movl %ecx, 0x4(%rsi)
shlq $0x4, %rax
movq 0x128(%rsp), %r8
movq 0x8(%r8,%rax), %rcx
movq %rcx, %rdi
shrq $0x20, %rdi
movzbl %dil, %edi
subl %edi, %ecx
incl %ecx
movl %ecx, 0x14(%rsi)
movl (%r8,%rax), %ecx
movzbl 0xc(%r8,%rax), %eax
subl %eax, %ecx
incl %ecx
movl %ecx, 0xc(%rsi)
testl $0x7fffffff, -0x24(%rsi) # imm = 0x7FFFFFFF
jne 0x1a41a
movl 0xc(%rsi), %eax
movl 0x14(%rsi), %ecx
movl %ecx, -0x10(%rsi)
movl %ecx, -0x14(%rsi)
movl %eax, -0x18(%rsi)
movl %eax, -0x1c(%rsi)
incq %rdx
cmpq 0xd8(%rsp), %rdx
jne 0x1a255
movl 0x68(%rsp), %eax
cmpl %eax, 0x38(%rsp)
jne 0x1a469
movl %eax, %ecx
sarl %ecx
addl %eax, %ecx
cmpl $0x4, %eax
movl $0x10, %eax
cmovll %eax, %ecx
movl %ecx, 0x68(%rsp)
movq 0x40(%rsp), %rdi
movq 0x70(%rsp), %rsi
movslq %ecx, %rax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rdx
callq 0x32c4
movq %rax, 0x70(%rsp)
movslq 0x28(%rsp), %r14
movq 0x38(%rsp), %rcx
movslq %ecx, %rax
movq 0x70(%rsp), %r12
incl %ecx
movl %ecx, 0x64(%rsp)
leaq (%rax,%rax,4), %r13
movq 0x30(%rsp), %rax
leaq (%rax,%rax,4), %rbx
movq 0x120(%rsp), %rcx
movl 0x4(%rcx,%rbx,8), %edx
leal (%rdx,%rdx), %eax
sarl %eax
movq %r14, %rdi
shlq $0x4, %rdi
addq 0x28(%rbp), %rdi
movl %eax, 0x4(%r12,%r13,4)
movl 0x8(%rcx,%rbx,8), %eax
movl %eax, 0x8(%r12,%r13,4)
movl 0x1c(%rcx,%rbx,8), %eax
movl %eax, 0xc(%r12,%r13,4)
movl $0xffffffff, 0x10(%r12,%r13,4) # imm = 0xFFFFFFFF
movslq (%rcx,%rbx,8), %rsi
shlq $0x4, %rsi
addq 0x128(%rsp), %rsi
shlq $0x21, %rdx
sarq $0x21, %rdx
shlq $0x4, %rdx
callq 0x2230
movl %r14d, (%r12,%r13,4)
addl 0x4(%r12,%r13,4), %r14d
movl %r14d, 0x6c(%rsp)
movq 0x10(%rsp), %r8
cmpl $0x2, %r8d
jl 0x1a5f7
movl %r8d, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq 0x120(%rsp), %rax
leaq (%rax,%rbx,8), %rbx
xorl %r12d, %r12d
movl $0x1, %r14d
leaq (%r14,%r14,4), %rax
movl 0x4(%rbx,%rax,8), %ecx
addl %ecx, %ecx
testl %ecx, %ecx
jle 0x1a5eb
leaq (%rbx,%rax,8), %r9
movq 0x18(%rsp), %rax
addl %r12d, %eax
cltq
leaq (%rax,%rax,4), %rax
movq 0x120(%rsp), %rcx
leaq (%rcx,%rax,8), %r8
movq 0x128(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl 0x148(%rsp), %ecx
callq 0x1a729
testl %eax, %eax
sets %al
movslq %r12d, %r13
cmpq %r13, %r14
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1a5e3
leaq (,%r13,4), %rax
addq %r13, %rax
leaq (%rbx,%rax,8), %r12
incq %r13
movq %r12, %r8
addq $0x28, %r12
movq 0x128(%rsp), %rax
movq %rax, (%rsp)
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movl 0x2c(%rsp), %edx
movl 0x148(%rsp), %ecx
movq %r12, %r9
callq 0x1a729
testl %eax, %eax
js 0x1a6eb
movl %r13d, %eax
incq %r13
cmpq %r14, %rax
jne 0x1a5a2
movl %r14d, %r12d
movq 0x10(%rsp), %r8
incq %r14
cmpq %r15, %r14
jne 0x1a527
movl 0x64(%rsp), %eax
subl 0x38(%rsp), %eax
movq 0x18(%rbp), %rcx
movq 0x90(%rsp), %rdx
movl %eax, 0xc(%rcx,%rdx)
movl 0x6c(%rsp), %eax
subl 0x28(%rsp), %eax
movl %eax, 0x10(%rcx,%rdx)
incl 0x24(%rsp)
movq 0x18(%rsp), %rax
addl %r8d, %eax
movq %rax, 0x18(%rsp)
movq 0xc0(%rsp), %rcx
incq %rcx
cmpq 0xa0(%rsp), %rcx
jne 0x1a037
movl 0x6c(%rsp), %eax
cmpl 0x10(%rbp), %eax
jg 0x1a70a
movl %eax, 0x10(%rbp)
movslq 0x64(%rsp), %rax
movl %eax, 0xc(%rbp)
shlq $0x2, %rax
leaq (%rax,%rax,4), %rbx
movq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x31c1
movq %rax, 0x20(%rbp)
movq 0x70(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2230
movq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x30f6
movq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0x19a71
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x1c3fe
movq %rbp, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf0e7(%rip), %rdi      # 0x297ba
leaq 0xed6e(%rip), %rsi      # 0x29448
leaq 0xf0ea(%rip), %rcx      # 0x297cb
movl $0x1aa, %edx            # imm = 0x1AA
callq 0x2160
leaq 0xefa8(%rip), %rdi      # 0x2969a
leaq 0xed4f(%rip), %rsi      # 0x29448
leaq 0xefa3(%rip), %rcx      # 0x296a3
movl $0x1f0, %edx            # imm = 0x1F0
callq 0x2160
leaq 0xf059(%rip), %rdi      # 0x2976a
leaq 0xed30(%rip), %rsi      # 0x29448
leaq 0xef84(%rip), %rcx      # 0x296a3
movl $0x1fd, %edx            # imm = 0x1FD
callq 0x2160