// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: init_mb_g_t(mc_match_t*, kv_u_trans_t*, unsigned int)
mb_g_t *init_mb_g_t(mc_match_t* e, kv_u_trans_t *ref, uint32_t is_sys)
{
	mc_edge_t *o = NULL;
	uint32_t i, k, m, n, a_n[2], *a[2], qn, tn, qb, tb;
	mb_edge_t *t = NULL;
	mb_g_t *p = NULL; CALLOC(p, 1);
	p->u = update_mb_nodes_t(ref, e, e->n_seq);
	p->e = NULL; CALLOC(p->e, 1);
	p->e->n_seq = p->u->u.n;
	kv_init(p->e->ma); kv_init(p->e->idx);
	for (i = 0; i < p->u->u.n; i++)///each block
	{
		qb = i;
		p->u->u.a[i].s[0] = p->u->u.a[i].s[1] = 0;
		decode_mb_node(p, i, &(a[0]), &(a_n[0]), NULL, &(a[1]), &(a_n[1]), NULL);
		for (k = 0; k < a_n[0]; k++)
		{
			qn = a[0][k];
			o = pt_a(*e, qn);
    		n = pt_n(*e, qn);
			for (m = 0; m < n; m++)
			{
				tn = ma_y(o[m]);
				tb = p->u->idx.a[tn]>>1;///tn is the unitig id; tb is the block id
				if(tb == qb)
				{
					continue;
				} 
				
				kv_pushp(mb_edge_t, p->e->ma, &t);
				t->x = (uint64_t)qb << 32 | tb;
				t->w[0] = t->w[1] = t->w[2] = t->w[3] = 0;
				t->w[p->u->idx.a[tn]&1] = o[m].w;
			}
		}

		for (k = 0; k < a_n[1]; k++)
		{
			qn = a[1][k];
			o = pt_a(*e, qn);
    		n = pt_n(*e, qn);
			for (m = 0; m < n; m++)
			{
				tn = ma_y(o[m]);
				tb = p->u->idx.a[tn]>>1;
				if(tb == qb)
				{
					continue;
				} 

				kv_pushp(mb_edge_t, p->e->ma, &t);
				t->x = (uint64_t)qb << 32 | tb;
				t->w[0] = t->w[1] = t->w[2] = t->w[3] = 0;
				t->w[(p->u->idx.a[tn]&1)+2] = o[m].w;
			}
		}
	}

	radix_sort_mbe(p->e->ma.a, p->e->ma.a + p->e->ma.n);
	mb_merge_dup(p); // MUST BE sorted
	mb_edges_idx(p->e);
	/*******************************for debug************************************/
	// debug_mb_edges_symm(p->e);
	/*******************************for debug************************************/
	if(is_sys) mb_edges_symm(p->e);

	return p;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0x14(%rsp)
movq %rsi, %r15
movq %rdi, %r14
pushq $0x1
popq %r12
pushq $0x10
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, %rbx
movl 0x38(%r14), %edx
movq %r15, %rdi
movq %r14, 0x20(%rsp)
movq %r14, %rsi
callq 0x12363a
movq %rax, %r15
movq %rax, (%rbx)
pushq $0x40
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x8(%rbx)
movq 0x30(%r15), %rcx
movl %ecx, 0x38(%rax)
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rcx
jbe 0x123a62
movq 0x40(%r15), %rax
imulq $0x38, %rsi, %rcx
xorl %edx, %edx
movb %dl, 0x11(%rax,%rcx)
movq (%rbx), %rax
movq 0x40(%rax), %rax
movb %dl, 0x10(%rax,%rcx)
movq %rbx, %rdi
leaq 0x30(%rsp), %rdx
leaq 0x18(%rsp), %rcx
movq %rsi, 0x8(%rsp)
xorl %r8d, %r8d
leaq 0x38(%rsp), %r9
pushq $0x0
leaq 0x24(%rsp), %rax
pushq %rax
callq 0x12e939
movq 0x18(%rsp), %rsi
addq $0x10, %rsp
movq %rsi, %r9
shlq $0x20, %r9
xorl %ecx, %ecx
movq %r9, 0x28(%rsp)
movl 0x18(%rsp), %eax
cmpq %rax, %rcx
jae 0x12394b
movq 0x30(%rsp), %rax
movq %rcx, (%rsp)
movl (%rax,%rcx,4), %eax
movq 0x20(%rsp), %rdx
movq 0x10(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq (%rcx,%rax,8), %rax
movl %eax, %r14d
shlq $0x4, %r14
shrq $0x1c, %rax
andq $-0x10, %rax
leaq (%rdx,%rax), %r13
addq $0x8, %r13
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x12393f
movl -0x8(%r13,%r12), %ebp
movq (%rbx), %rax
movq 0x28(%rax), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, %r15d
shrl %r15d
cmpl %esi, %r15d
je 0x123936
movq 0x8(%rbx), %rdx
movq 0x18(%rdx), %r8
cmpq 0x20(%rdx), %r8
jne 0x1238fe
leaq (%r8,%r8), %rax
testq %r8, %r8
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x20(%rdx)
movq 0x28(%rdx), %rdi
imulq $0x28, %rax, %rsi
callq 0x2370
movq 0x28(%rsp), %r9
movq 0x8(%rsp), %rsi
movq 0x8(%rbx), %rdx
movq %rax, 0x28(%rdx)
movq 0x18(%rdx), %r8
movq (%rbx), %rcx
movq 0x28(%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
jmp 0x123902
movq 0x28(%rdx), %rax
leaq 0x1(%r8), %rdi
movq %rdi, 0x18(%rdx)
imulq $0x28, %r8, %rdx
leaq (%rax,%rdx), %rdi
orq %r9, %r15
movq %r15, (%rax,%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax,%rdx)
movups %xmm0, 0x18(%rax,%rdx)
movsd (%r13,%r12), %xmm0
andl $0x1, %ecx
movsd %xmm0, 0x8(%rdi,%rcx,8)
addq $0x10, %r12
jmp 0x123888
movq (%rsp), %rcx
incq %rcx
jmp 0x123844
xorl %ecx, %ecx
movl 0x1c(%rsp), %eax
cmpq %rax, %rcx
jae 0x123a54
movq 0x38(%rsp), %rax
movq %rcx, (%rsp)
movl (%rax,%rcx,4), %eax
movq 0x20(%rsp), %rdx
movq 0x10(%rdx), %rcx
movq 0x28(%rdx), %rdx
movq (%rcx,%rax,8), %rax
movl %eax, %r14d
shlq $0x4, %r14
shrq $0x1c, %rax
andq $-0x10, %rax
leaq (%rdx,%rax), %r13
addq $0x8, %r13
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x123a48
movl -0x8(%r13,%r12), %ebp
movq (%rbx), %rax
movq 0x28(%rax), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, %r15d
shrl %r15d
cmpl %esi, %r15d
je 0x123a3f
movq 0x8(%rbx), %rdx
movq 0x18(%rdx), %r8
cmpq 0x20(%rdx), %r8
jne 0x123a07
leaq (%r8,%r8), %rax
testq %r8, %r8
pushq $0x2
popq %rcx
cmoveq %rcx, %rax
movq %rax, 0x20(%rdx)
movq 0x28(%rdx), %rdi
imulq $0x28, %rax, %rsi
callq 0x2370
movq 0x28(%rsp), %r9
movq 0x8(%rsp), %rsi
movq 0x8(%rbx), %rdx
movq %rax, 0x28(%rdx)
movq 0x18(%rdx), %r8
movq (%rbx), %rcx
movq 0x28(%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
jmp 0x123a0b
movq 0x28(%rdx), %rax
leaq 0x1(%r8), %rdi
movq %rdi, 0x18(%rdx)
imulq $0x28, %r8, %rdx
leaq (%rax,%rdx), %rdi
orq %r9, %r15
movq %r15, (%rax,%rdx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax,%rdx)
movups %xmm0, 0x18(%rax,%rdx)
movsd (%r13,%r12), %xmm0
andl $0x1, %ecx
movsd %xmm0, 0x18(%rdi,%rcx,8)
addq $0x10, %r12
jmp 0x123991
movq (%rsp), %rcx
incq %rcx
jmp 0x12394d
incl %esi
movq (%rbx), %r15
movq 0x30(%r15), %rcx
jmp 0x1237e2
movq 0x8(%rbx), %rax
movq 0x28(%rax), %rdi
imulq $0x28, 0x18(%rax), %rsi
addq %rdi, %rsi
callq 0x1222c0
movq %rbx, %rdi
callq 0x122795
movq 0x8(%rbx), %rdi
callq 0x123aaa
cmpl $0x0, 0x14(%rsp)
je 0x123a98
movq 0x8(%rbx), %rdi
callq 0x123b80
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq