// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movl 0x30(%rbp), %eax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
movl $0x30, %edx
callq 0x2540
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x280ba
movl $0x0, -0x94(%rbp)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x98(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x98(%rbp), %eax
jge 0x2805f
movq 0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shll %eax
sarl %eax
addl -0x94(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x28022
movl -0x94(%rbp), %eax
cmpl 0x28(%rbp), %eax
jl 0x280a0
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movslq 0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x280a0
movq -0x40(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movl -0x94(%rbp), %ecx
movq -0x40(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x98(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x27ff3
movq -0x40(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x280d1
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x286ab
movq -0x10(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq 0x8(%rax), %rsi
movl $0x68, %edx
callq 0x2540
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movslq 0x10(%rax), %rsi
shlq $0x4, %rsi
callq 0x2890
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x2190
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
movl 0x40(%rbp), %eax
movl %eax, -0x70(%rbp)
movq 0x48(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x28606
movl -0x64(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xa8(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x2820b
movq 0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
shll %eax
sarl %eax
addl -0xa4(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x281ce
movl -0xa4(%rbp), %eax
cmpl 0x28(%rbp), %eax
jl 0x285ec
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movslq 0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x285ec
movl 0x20(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x4c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movl -0xa0(%rbp), %ecx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x4c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x2831c
movq 0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl 0x14(%rax), %edi
callq 0x286c0
movl %eax, -0xd8(%rbp)
movq -0xb8(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x286c0
movl %eax, %ecx
movl -0xd8(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xd4(%rbp)
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x286c0
movl %eax, %ecx
movl -0xd4(%rbp), %eax
addl %ecx, %eax
addl -0xac(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2828b
movl -0xac(%rbp), %edi
callq 0x286c0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x4c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x38(%rax)
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x2838e
movq 0x10(%rbp), %rdi
movl -0x50(%rbp), %eax
addl -0x48(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0x28, %rax, %rax
addq %rax, %rdi
movq 0x10(%rbp), %rsi
movl -0x50(%rbp), %eax
addl -0x48(%rbp), %eax
cltq
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq 0x18(%rbp), %rdx
callq 0x28720
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x28346
movl -0x6c(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0x283e4
jmp 0x28398
cmpl $0x4, -0x68(%rbp)
jl 0x283b0
movl -0x68(%rbp), %eax
movl -0x68(%rbp), %ecx
sarl %ecx
addl %ecx, %eax
movl %eax, -0xdc(%rbp)
jmp 0x283bd
movl $0x10, %eax
movl %eax, -0xdc(%rbp)
jmp 0x283bd
movl -0xdc(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x90(%rbp), %rdi
movq -0x60(%rbp), %rsi
movslq -0x68(%rbp), %rax
imulq $0x14, %rax, %rdx
callq 0x2ae0
movq %rax, -0x60(%rbp)
jmp 0x283e4
movq -0x60(%rbp), %rdi
movl -0x6c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x6c(%rbp)
cltq
imulq $0x14, %rax, %rax
addq %rax, %rdi
movq 0x10(%rbp), %rsi
movslq -0x50(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq -0x90(%rbp), %rdx
addq $0x2c, %rdx
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rcx
movq 0x18(%rbp), %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x28aa0
movl $0x0, -0xb0(%rbp)
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jge 0x285a5
movq 0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0xb0(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq 0x10(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
sarl %eax
cmpl $0x0, %eax
jle 0x28595
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %edx
movl 0x38(%rbp), %ecx
movq -0xc0(%rbp), %r8
movq -0xc8(%rbp), %r9
movq 0x18(%rbp), %rax
leaq -0x90(%rbp), %rsi
movq %rax, (%rsp)
callq 0x28b50
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jge 0x2858c
movl -0xb0(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x2858a
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %edx
movl 0x38(%rbp), %ecx
movq 0x10(%rbp), %r8
movl -0x50(%rbp), %eax
addl -0xd0(%rbp), %eax
cltq
imulq $0x28, %rax, %rax
addq %rax, %r8
movq 0x10(%rbp), %r9
movl -0x50(%rbp), %eax
addl -0xd0(%rbp), %eax
addl $0x1, %eax
cltq
imulq $0x28, %rax, %rax
addq %rax, %r9
movq 0x18(%rbp), %rax
leaq -0x90(%rbp), %rsi
movq %rax, (%rsp)
callq 0x28b50
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jl 0x28555
jmp 0x28574
leaq 0x150aa(%rip), %rdi     # 0x3d606
leaq 0x14e51(%rip), %rsi     # 0x3d3b4
movl $0x1f0, %edx            # imm = 0x1F0
leaq 0x150a0(%rip), %rcx     # 0x3d60f
callq 0x2170
jmp 0x28576
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x284e8
jmp 0x2858c
movl -0x48(%rbp), %eax
movl %eax, -0xb0(%rbp)
jmp 0x28597
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2843e
movl -0x6c(%rbp), %ecx
subl -0xa0(%rbp), %ecx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x4c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x64(%rbp), %ecx
subl -0x9c(%rbp), %ecx
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x4c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0xa8(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2818d
movl -0x64(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jg 0x28614
jmp 0x28633
leaq 0x150bb(%rip), %rdi     # 0x3d6d6
leaq 0x14d92(%rip), %rsi     # 0x3d3b4
movl $0x1fd, %edx            # imm = 0x1FD
leaq 0x14fe1(%rip), %rcx     # 0x3d60f
callq 0x2170
movl -0x64(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x6c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rdi
movslq -0x6c(%rbp), %rax
imulq $0x14, %rax, %rsi
callq 0x2890
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x60(%rbp), %rsi
movslq -0x6c(%rbp), %rax
imulq $0x14, %rax, %rdx
callq 0x2230
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x2670
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x27980
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x2b4a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax,%rax)