// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r13
movq 0x276284(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x21d766(%rip), %rsi    # 0x23c4cc
leaq 0x21e755(%rip), %rdx    # 0x23d4c2
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x22b0
pushq $0x1
popq %r15
pushq $0x30
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %rbx
pushq $0x40
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
movq %rax, 0x28(%rbx)
movl %ebp, 0x38(%rax)
movq (%r13), %rcx
testq %rcx, %rcx
je 0x1ee98
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x10(%r13), %rdx
pushq $0x1
popq %rbp
xorl %r12d, %r12d
pushq $0x2
popq %r14
xorl %eax, %eax
xorl %esi, %esi
imulq $0x30, %rsi, %rbx
cmpb $0x0, 0x28(%rdx,%rbx)
js 0x1ee36
cmpq 0x20(%r15), %rax
jne 0x1ee06
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0x20(%r15)
shlq $0x4, %rsi
movq %r12, %rdi
callq 0x2370
movq %rax, %r12
movq %rax, 0x28(%r15)
movq 0x18(%r15), %rax
movq (%r13), %rcx
movq 0x10(%r13), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x18(%r15)
shlq $0x4, %rax
movl 0x8(%rdx,%rbx), %edi
movl 0x14(%rdx,%rbx), %r8d
shlq $0x20, %rdi
orq %rdi, %r8
movq %r8, (%r12,%rax)
movsd 0x20(%rdx,%rbx), %xmm0
movsd %xmm0, 0x8(%r12,%rax)
movq %rsi, %rax
movl %ebp, %esi
incl %ebp
cmpq %rsi, %rcx
ja 0x1edc7
xorl %esi, %esi
testq %rax, %rax
je 0x1ee9c
pushq $0x1
popq %rcx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %r14
movq 0x28(%r15), %rdi
shlq $0x4, %rdx
movsd 0x8(%rdi,%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x1ee6f
jnp 0x1ee87
addq %rdi, %rdx
movl %esi, %eax
shlq $0x4, %rax
movupd (%rdx), %xmm1
movupd %xmm1, (%rdi,%rax)
incl %esi
movq 0x18(%r15), %rax
movl %ecx, %edx
incl %ecx
cmpq %rdx, %rax
ja 0x1ee59
movq 0x28(%r15), %r12
movl %esi, %esi
jmp 0x1eea6
xorl %esi, %esi
jmp 0x1eea6
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %r14
movq %rsi, 0x18(%r15)
shlq $0x4, %rsi
addq %r12, %rsi
movq %r12, %rdi
callq 0x16695f
movq %rbx, %rdi
callq 0x16710b
movq %r15, %rdi
callq 0x168a9c
movq %r15, %rdi
callq 0x168951
movq 0x8(%r14), %r15
movq %r15, (%rbx)
movq %r15, 0x8(%rbx)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x10(%rbx)
testq %r15, %r15
je 0x1ef1f
movq (%r14), %rcx
xorl %edx, %edx
movl (%rcx), %esi
leal -0x1(%rsi), %edi
cmpl $0x1, %edi
ja 0x1ef11
cmpl $0x1, %esi
setne %sil
negb %sil
orb $0x1, %sil
movb %sil, (%rax,%rdx)
incq %rdx
movl %edx, %esi
addq $0x20, %rcx
cmpq %rsi, %r15
ja 0x1eef5
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq