// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movq %rsi, %r14
movq %rdi, %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %rbx
movl 0x38(%r15), %edx
movq %r14, %rdi
movq %r15, 0x8(%rsp)
movq %r15, %rsi
callq 0x1680c2
movq %rax, %r14
movq %rax, (%rbx)
movl $0x1, %edi
movl $0x40, %esi
callq 0x2120
movq %rax, 0x8(%rbx)
movq 0x30(%r14), %rcx
movq %rax, (%rsp)
movl %ecx, 0x38(%rax)
xorl %edx, %edx
testq %rcx, %rcx
je 0x168589
movq %r14, %rdi
movl %ebp, 0x2c(%rsp)
movq %rbx, 0x50(%rsp)
xorps %xmm1, %xmm1
xorl %r9d, %r9d
xorl %r8d, %r8d
movq %r14, 0x40(%rsp)
movq 0x40(%rdi), %rcx
imulq $0x38, %r9, %rax
movb %dl, 0x11(%rcx,%rax)
movq 0x40(%rdi), %rcx
movb %dl, 0x10(%rcx,%rax)
movq 0x10(%rdi), %rcx
movq %rcx, 0x30(%rsp)
movq 0x40(%rdi), %rcx
movl 0x4(%rcx,%rax), %edx
movq %rdx, 0x58(%rsp)
movl 0x8(%rcx,%rax), %esi
movl 0xc(%rcx,%rax), %edx
movq %rdx, 0x38(%rsp)
movq %rsi, 0x10(%rsp)
testq %rsi, %rsi
movq %r8, 0x48(%rsp)
je 0x168421
movl (%rcx,%rax), %eax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
movq %rax, 0x60(%rsp)
movq %r9, %r12
shlq $0x20, %r12
xorl %ecx, %ecx
movq 0x60(%rsp), %rax
movq %rcx, 0x18(%rsp)
movl (%rax,%rcx,4), %eax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x16840e
movq 0x8(%rsp), %rcx
movq 0x28(%rcx), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %r11d
movq 0x28(%rdi), %rcx
shlq $0x4, %rsi
leaq (%rdx,%rsi), %r15
addq $0x8, %r15
shlq $0x4, %r11
xorl %ebp, %ebp
movq %r15, 0x20(%rsp)
movl -0x8(%r15,%rbp), %r13d
movl (%rcx,%r13,4), %ebx
shrl %ebx
cmpl %r8d, %ebx
je 0x168401
movq (%rsp), %rsi
movq 0x18(%rsi), %rdx
movq 0x28(%rsi), %rax
cmpq 0x20(%rsi), %rdx
jne 0x1683cc
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq (%rsp), %rdx
movq %rcx, 0x20(%rdx)
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %rax, %rdi
movq %r9, %r15
movq %r11, %r14
callq 0x2370
movq %r14, %r11
movq (%rsp), %rcx
movq %r15, %r9
movq 0x20(%rsp), %r15
movq 0x48(%rsp), %r8
xorps %xmm1, %xmm1
movq 0x40(%rsp), %rdi
movq %rax, 0x28(%rcx)
movq 0x18(%rcx), %rdx
movq 0x28(%rdi), %rcx
orq %r12, %rbx
leaq 0x1(%rdx), %rsi
movq (%rsp), %r14
movq %rsi, 0x18(%r14)
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %rax
movq %rbx, (%rax)
movups %xmm1, 0x8(%rax)
movups %xmm1, 0x18(%rax)
movsd (%r15,%rbp), %xmm0
movl (%rcx,%r13,4), %edx
andl $0x1, %edx
movsd %xmm0, 0x8(%rax,%rdx,8)
addq $0x10, %rbp
cmpq %rbp, %r11
jne 0x168350
movq 0x18(%rsp), %rcx
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x168300
cmpq $0x0, 0x38(%rsp)
je 0x16855d
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rcx
leaq (%rax,%rcx,4), %rax
movq %rax, 0x10(%rsp)
shlq $0x20, %r9
xorl %ecx, %ecx
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rsp)
movl (%rax,%rcx,4), %eax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x16854a
movq 0x8(%rsp), %rcx
movq 0x28(%rcx), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %r12d
movq 0x28(%rdi), %rcx
shlq $0x4, %rsi
leaq (%rdx,%rsi), %r11
addq $0x8, %r11
shlq $0x4, %r12
xorl %ebp, %ebp
movq %r11, 0x20(%rsp)
movl -0x8(%r11,%rbp), %r13d
movl (%rcx,%r13,4), %ebx
shrl %ebx
cmpl %r8d, %ebx
je 0x16853d
movq (%rsp), %rsi
movq 0x18(%rsi), %rdx
movq 0x28(%rsi), %rax
cmpq 0x20(%rsi), %rdx
jne 0x168508
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq (%rsp), %r14
movq %rcx, 0x20(%r14)
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rsi
movq %rax, %rdi
movq %r9, %r15
callq 0x2370
movq 0x20(%rsp), %r11
movq %r15, %r9
movq 0x48(%rsp), %r8
xorps %xmm1, %xmm1
movq 0x40(%rsp), %rdi
movq %rax, 0x28(%r14)
movq 0x18(%r14), %rdx
movq 0x28(%rdi), %rcx
orq %r9, %rbx
leaq 0x1(%rdx), %rsi
movq (%rsp), %r14
movq %rsi, 0x18(%r14)
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %rax
movq %rbx, (%rax)
movups %xmm1, 0x8(%rax)
movups %xmm1, 0x18(%rax)
movsd (%r11,%rbp), %xmm0
movl (%rcx,%r13,4), %edx
andl $0x1, %edx
movsd %xmm0, 0x18(%rax,%rdx,8)
addq $0x10, %rbp
cmpq %rbp, %r12
jne 0x168496
movq 0x18(%rsp), %rcx
incq %rcx
cmpq 0x38(%rsp), %rcx
jne 0x168446
incl %r8d
movq %r8, %r9
cmpq %r8, 0x30(%rdi)
movl $0x0, %edx
ja 0x16829c
movq (%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x28(%rax), %rdi
movq 0x50(%rsp), %rbx
movl 0x2c(%rsp), %ebp
jmp 0x16858b
xorl %edi, %edi
leaq (%rdx,%rdx,4), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x166bed
movq %rbx, %rdi
callq 0x1671e9
movq (%rsp), %rdi
callq 0x1685c8
testl %ebp, %ebp
je 0x1685b6
movq (%rsp), %rdi
callq 0x1686b3
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq