// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movl %edx, 0x24(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %rbx
movl 0x38(%r14), %edx
movq %r15, %rdi
movq %r14, (%rsp)
movq %r14, %rsi
callq 0x1617d7
movq %rax, %r14
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movl $0x1, %edi
movl $0x40, %esi
callq 0x2120
movq %rax, %r15
movq %rbx, 0x48(%rsp)
movq %rax, 0x8(%rbx)
movl 0x30(%r14), %eax
movl %eax, 0x38(%r15)
xorps %xmm1, %xmm1
movups %xmm1, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm1, (%r15)
cmpq $0x0, 0x30(%r14)
je 0x161c8b
xorl %r8d, %r8d
xorl %edi, %edi
movq %r14, 0x38(%rsp)
movq 0x40(%r14), %rcx
imulq $0x38, %r8, %rax
xorl %edx, %edx
movb %dl, 0x11(%rcx,%rax)
movq 0x40(%r14), %rcx
movb %dl, 0x10(%rcx,%rax)
movq 0x10(%r14), %rcx
movq %rcx, 0x28(%rsp)
movq 0x40(%r14), %rcx
movl 0x4(%rcx,%rax), %edx
movq %rdx, 0x50(%rsp)
movl 0x8(%rcx,%rax), %r9d
movl 0xc(%rcx,%rax), %edx
movq %rdx, 0x30(%rsp)
movq %r9, 0x60(%rsp)
testq %r9, %r9
movq %rdi, 0x40(%rsp)
je 0x161b4b
movl (%rcx,%rax), %eax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x58(%rsp)
movq %r8, %r9
shlq $0x20, %r9
xorl %ecx, %ecx
movq %r9, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rcx, 0x8(%rsp)
movl (%rax,%rcx,4), %eax
movq (%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x161b38
movq (%rsp), %rcx
movq 0x28(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %ebp
shlq $0x4, %rdx
leaq (%rcx,%rdx), %r11
addq $0x8, %r11
shlq $0x4, %rbp
xorl %r13d, %r13d
movq %r11, 0x18(%rsp)
movl -0x8(%r11,%r13), %ebx
movq 0x28(%r14), %rax
movl (%rax,%rbx,4), %r12d
shrl %r12d
cmpl %edi, %r12d
je 0x161b2b
movq 0x20(%r15), %rax
cmpq %rax, 0x18(%r15)
jne 0x161aef
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x20(%r15)
movq 0x28(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %r8, %r14
callq 0x2370
movq 0x18(%rsp), %r11
movq 0x10(%rsp), %r9
movq %r14, %r8
movq 0x40(%rsp), %rdi
xorps %xmm1, %xmm1
movq 0x38(%rsp), %r14
movq %rax, 0x28(%r15)
orq %r9, %r12
movq 0x18(%r15), %rax
movq 0x28(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%r15)
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %rax
movq %r12, (%rax)
movups %xmm1, 0x8(%rax)
movups %xmm1, 0x18(%rax)
movsd (%r11,%r13), %xmm0
movq 0x28(%r14), %rcx
movl (%rcx,%rbx,4), %ecx
andl $0x1, %ecx
movsd %xmm0, 0x8(%rax,%rcx,8)
addq $0x10, %r13
cmpq %r13, %rbp
jne 0x161a86
movq 0x8(%rsp), %rcx
incq %rcx
cmpq 0x60(%rsp), %rcx
jne 0x161a3c
cmpq $0x0, 0x30(%rsp)
je 0x161c7c
movq 0x28(%rsp), %rax
movq 0x50(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0x8(%rsp)
shlq $0x20, %r8
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rsp)
movl (%rax,%rcx,4), %eax
movq (%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x161c69
movq (%rsp), %rcx
movq 0x28(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %r9d
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rbp
addq $0x8, %rbp
shlq $0x4, %r9
xorl %r13d, %r13d
movq %r9, 0x18(%rsp)
movl -0x8(%rbp,%r13), %ebx
movq 0x28(%r14), %rax
movl (%rax,%rbx,4), %r12d
shrl %r12d
cmpl %edi, %r12d
je 0x161c5c
movq 0x20(%r15), %rax
cmpq %rax, 0x18(%r15)
jne 0x161c1f
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x20(%r15)
movq 0x28(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %r8, %r14
callq 0x2370
movq 0x18(%rsp), %r9
movq %r14, %r8
movq 0x40(%rsp), %rdi
xorps %xmm1, %xmm1
movq 0x38(%rsp), %r14
movq %rax, 0x28(%r15)
orq %r8, %r12
movq 0x18(%r15), %rax
movq 0x28(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%r15)
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %rax
movq %r12, (%rax)
movups %xmm1, 0x8(%rax)
movups %xmm1, 0x18(%rax)
movsd (%rbp,%r13), %xmm0
movq 0x28(%r14), %rcx
movl (%rcx,%rbx,4), %ecx
andl $0x1, %ecx
movsd %xmm0, 0x18(%rax,%rcx,8)
addq $0x10, %r13
cmpq %r13, %r9
jne 0x161bbb
movq 0x10(%rsp), %rcx
incq %rcx
cmpq 0x30(%rsp), %rcx
jne 0x161b70
incl %edi
movq %rdi, %r8
cmpq %rdi, 0x30(%r14)
ja 0x1619d0
movq 0x18(%r15), %rax
movq 0x28(%r15), %rdi
leaq (%rax,%rax,4), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1602c4
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x1608cd
movq %r15, %rdi
callq 0x161cd6
cmpl $0x0, 0x24(%rsp)
je 0x161cc4
movq %r15, %rdi
callq 0x161db7
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq