// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/rcut.cpp
// Function: to_mc_g_t(kv_u_trans_t*, kv_gg_status*, unsigned int)
mc_g_t* to_mc_g_t(kv_u_trans_t *ta, kv_gg_status *s, uint32_t un)
{
	fprintf(stderr, "[M::%s]\n", __func__);
	uint32_t i, k;
	mc_edge_t *ma = NULL;
	mc_g_t *mg = NULL; CALLOC(mg, 1);
    

	CALLOC(mg->e, 1);
	mg->e->n_seq = un;
	kv_init(mg->e->idx); kv_init(mg->e->ma); 
	// double sc = get_w_scale(ta);
	// fprintf(stderr, "sc: %f\n", sc);
	for (i = 0; i < ta->n; ++i)
	{
		if(ta->a[i].del) continue;
		kv_pushp(mc_edge_t, mg->e->ma, &ma);
		ma->x = (uint64_t)ta->a[i].qn << 32 | ta->a[i].tn;
		// ma->w = w_cast((ta->a[i].nw*sc));
		ma->w = w_cast((ta->a[i].nw));
	}
	

	for (i = k = 0; i < mg->e->ma.n; i++)
    {
		if(mg->e->ma.a[i].w == 0) continue;
		mg->e->ma.a[k] = mg->e->ma.a[i];
        k++;
    }
    mg->e->ma.n = k;
	
	radix_sort_mce(mg->e->ma.a, mg->e->ma.a + mg->e->ma.n);
	mc_merge_dup(mg);
	mc_edges_idx(mg->e);
	mc_edges_symm(mg->e);

	kv_init(mg->s); 
	mg->s.m = mg->s.n = s->n; CALLOC(mg->s.a, mg->s.n);
	for (i = 0; i < mg->s.n; ++i)
	{
		if(s->a[i].s != 1 && s->a[i].s != 2) continue;
		mg->s.a[i] = (s->a[i].s == 1? 1:-1);
	}
	return mg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r12
movq 0x125a6b(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xc0e3d(%rip), %rsi     # 0x1ee3bc
leaq 0xc1dfc(%rip), %rdx     # 0x1ef382
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x22b0
pushq $0x1
popq %r15
pushq $0x30
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r14
pushq $0x40
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
movq %r14, (%rsp)
movq %rax, 0x28(%r14)
movl %ebp, 0x38(%rax)
xorl %eax, %eax
xorl %r14d, %r14d
movl %r14d, %r14d
cmpq %r14, (%r12)
jbe 0x12d645
movq 0x10(%r12), %rcx
imulq $0x30, %r14, %rbp
cmpb $0x0, 0x28(%rcx,%rbp)
js 0x12d63d
cmpq 0x20(%r15), %rax
jne 0x12d60d
leaq (%rax,%rax), %rsi
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x20(%r15)
shlq $0x4, %rsi
movq %r13, %rdi
callq 0x2370
movq %rax, %r13
movq %rax, 0x28(%r15)
movq 0x18(%r15), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x18(%r15)
shlq $0x4, %rax
movl 0x8(%rcx,%rbp), %esi
movl 0x14(%rcx,%rbp), %edi
shlq $0x20, %rsi
orq %rsi, %rdi
movq %rdi, (%r13,%rax)
movsd 0x20(%rcx,%rbp), %xmm0
movsd %xmm0, 0x8(%r13,%rax)
movq %rdx, %rax
incl %r14d
jmp 0x12d5c0
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movq (%rsp), %r14
movl %ecx, %ecx
movl %edx, %esi
cmpq %rcx, %rax
jbe 0x12d68f
movq 0x28(%r15), %rdi
movq %rcx, %r8
shlq $0x4, %r8
movsd 0x8(%rdi,%r8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x12d674
jnp 0x12d68b
addq %rdi, %r8
shlq $0x4, %rsi
movupd (%r8), %xmm1
movupd %xmm1, (%rdi,%rsi)
incl %edx
movq 0x18(%r15), %rax
incl %ecx
jmp 0x12d651
movq %rsi, 0x18(%r15)
movq 0x28(%r15), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x122033
movq %r14, %rdi
callq 0x1226d6
movq %r15, %rdi
callq 0x123f79
movq %r15, %rdi
callq 0x123de4
movq 0x8(%rbx), %r15
movq %r15, (%r14)
movq %r15, 0x8(%r14)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x10(%r14)
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %r15
jbe 0x12d705
movq (%rbx), %rdx
movq %rcx, %rsi
shlq $0x5, %rsi
movl (%rdx,%rsi), %edx
leal -0x1(%rdx), %esi
cmpl $0x1, %esi
ja 0x12d701
cmpl $0x1, %edx
setne %dl
negb %dl
orb $0x1, %dl
movb %dl, (%rax,%rcx)
incl %ecx
jmp 0x12d6d7
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq