// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: merge_hybrid_utg_content(ma_utg_t*, ma_ug_t*, asg_t*, usg_t*, kvec_asg_arc_t_warp*)
void merge_hybrid_utg_content(ma_utg_t* cc, ma_ug_t* raw, asg_t* rg, usg_t *ng, kvec_asg_arc_t_warp* edge)
{
    if(cc->m == 0) return;
    uint32_t i, j, index, uId, ori, uv, uw, bv, bw;
    uint64_t tot, z; asg_arc_t *p; 
    ma_utg_t* q = NULL;
    for (i = index = 0; i < cc->n; i++) {
        z = (ng->a[cc->a[i]>>33].mm<<1)|((cc->a[i]>>32)&1); z <<= 32; z += ((uint32_t)cc->a[i]);
        index += ng->a[cc->a[i]>>33].occ; cc->a[i] = z;
    }

    uint64_t *buffer, *aim = NULL; MALLOC(buffer, index);
    for (i = index = edge->a.n = 0; i < cc->n; i++) {
        uId = cc->a[i]>>33; ori = cc->a[i]>>32&1;
        q = &(raw->u.a[uId]); aim = buffer + index;
        if(ori == 1) {
            for (j = 0; j < q->n; j++) {
                aim[q->n - j - 1] = (q->a[j])^(uint64_t)(0x100000000);
            }
        } else {
            for (j = 0; j < q->n; j++) {
                aim[j] = q->a[j];
            }
        }
        index += q->n;
        if(i > 0) {
            uv = cc->a[i-1]>>32; uw = cc->a[i]>>32;
            p = get_specfic_edge(raw->g, uv, uw);
            if(!p) {
                uv = cc->a[i-1]>>32; uw = cc->a[i]>>32;
                bv = raw->u.a[uv>>1].a[((uv&1)?(0):(raw->u.a[uv>>1].n-1))]>>32; if(uv&1) bv ^= 1;
                bw = raw->u.a[uw>>1].a[((uw&1)?(raw->u.a[uw>>1].n-1):(0))]>>32; if(uw&1) bw ^= 1;
                kv_pushp(asg_arc_t, edge->a, &p); memset(p, 0, sizeof((*p)));
                p->ul = bv; p->ul <<= 32; p->ul += rg->seq[bv>>1].len; p->v = bw;

                uv = (cc->a[i]>>32)^1; uw = (cc->a[i-1]>>32)^1;
                bv = raw->u.a[uv>>1].a[((uv&1)?(0):(raw->u.a[uv>>1].n-1))]>>32; if(uv&1) bv ^= 1;
                bw = raw->u.a[uw>>1].a[((uw&1)?(raw->u.a[uw>>1].n-1):(0))]>>32; if(uw&1) bw ^= 1;
                kv_pushp(asg_arc_t, edge->a, &p); memset(p, 0, sizeof((*p)));
                p->ul = bv; p->ul <<= 32; p->ul += rg->seq[bv>>1].len; p->v = bw;
            }
        }
    }

    if(index == 0) return;

    fill_unitig(buffer, index, rg, edge, (cc->n == 1 && raw->u.a[cc->a[0]>>33].circ), &tot);

    ///important. must be here
    if(cc->n == 1 && raw->u.a[cc->a[0]>>33].circ) cc->circ = 1;
    
    free(cc->a);
    cc->a = buffer; cc->n = cc->m = index; cc->len = tot;
    if(!cc->circ) {
        cc->start = cc->a[0]>>32;
        cc->end = (cc->a[cc->n-1]>>32)^1;
    }
    else {
        cc->start = cc->end = UINT32_MAX;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
cmpl $0x0, 0xc(%rdi)
je 0x21f131
movl 0x10(%rdi), %ebx
testq %rbx, %rbx
je 0x21f0dc
movq %r8, 0x8(%rsp)
movq (%rcx), %rax
movq %rdi, (%rsp)
movq 0x18(%rdi), %rcx
xorl %edx, %edx
movabsq $0x1ffffffff, %rsi      # imm = 0x1FFFFFFFF
xorl %edi, %edi
movq (%rcx,%rdx,8), %r8
movq %r8, %r9
shrq $0x21, %r9
imulq $0x78, %r9, %r9
movl (%rax,%r9), %r10d
shlq $0x21, %r10
andq %rsi, %r8
addl 0x4(%rax,%r9), %edi
orq %r10, %r8
movq %r8, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rbx
jne 0x21ed15
movl %edi, %edi
shlq $0x3, %rdi
callq 0x2280
movq 0x8(%rsp), %r10
movq $0x0, (%r10)
testl %ebx, %ebx
movq (%rsp), %r11
je 0x21f131
movq %rax, %r15
xorl %r12d, %r12d
movabsq $0x100000000, %r13      # imm = 0x100000000
xorps %xmm0, %xmm0
xorl %ebp, %ebp
movq %rax, 0x18(%rsp)
movq 0x18(%r11), %rsi
movq (%rsi,%r12,8), %rdx
movq %rdx, %rax
shrq $0x21, %rax
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq (%rax,%rax,4), %rax
leaq (%rcx,%rax,8), %rax
movl %ebp, 0x2c(%rsp)
movl %ebp, %edi
leaq (%r15,%rdi,8), %rdi
movq %rdx, %r14
movl 0x10(%rax), %ebp
andq %r13, %r14
jne 0x21edd8
testq %rbp, %rbp
je 0x21ee11
movq 0x18(%rax), %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
movq %r10, (%rdi,%r9,8)
incq %r9
cmpq %r9, %rbp
jne 0x21edc1
movq 0x8(%rsp), %r10
jmp 0x21ee13
testq %rbp, %rbp
je 0x21ee11
movq 0x18(%rax), %r8
leal -0x1(%rbp), %r9d
xorl %r10d, %r10d
movq (%r8,%r10,8), %r11
xorq %r13, %r11
movl %r9d, %r15d
movq %r11, (%rdi,%r15,8)
incq %r10
decl %r9d
cmpq %r10, %rbp
jne 0x21ede8
movq (%rsp), %r11
movq 0x8(%rsp), %r10
movq 0x18(%rsp), %r15
jmp 0x21ee13
xorl %ebp, %ebp
testq %r12, %r12
je 0x21f055
movq -0x8(%rsi,%r12,8), %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq 0x28(%rsi), %rdi
movq %r15, %r8
shrq $0x20, %r8
movq (%rdi,%r8,8), %rdi
movq %rdi, %r8
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %r8
je 0x21ee85
shrq $0x20, %rdx
movq 0x8(%rsi), %r9
shrq $0x20, %rdi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%rdi,8), %rdi
addq $0xc, %rdi
xorl %r8d, %r8d
cmpl $0x0, (%rdi,%r8)
js 0x21ee7c
cmpl %edx, -0x4(%rdi,%r8)
je 0x21f050
addq $0x18, %r8
cmpq %r8, %rsi
jne 0x21ee6a
movq %r15, %rdx
shrq $0x21, %rdx
leaq (%rdx,%rdx,4), %rdx
andq %r13, %r15
jne 0x21eea0
leaq (%rcx,%rdx,8), %rsi
movl 0x10(%rsi), %esi
decl %esi
jmp 0x21eea2
xorl %esi, %esi
movq 0x18(%rcx,%rdx,8), %rcx
leal -0x1(%rbp), %edx
testq %r14, %r14
movq (%rcx,%rsi,8), %rbx
movq 0x18(%rax), %rax
cmoveq %r14, %rdx
xorq (%rax,%rdx,8), %r14
movq (%r10), %rcx
movq 0x10(%r10), %rax
cmpq 0x8(%r10), %rcx
jne 0x21ef01
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r10)
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r10
movq (%rsp), %r11
movq %rax, 0x10(%r10)
movq (%r10), %rcx
shrq $0x20, %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%r10)
leaq (%rcx,%rcx,2), %rcx
movups %xmm0, 0x8(%rax,%rcx,8)
movq %rbx, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
xorq %r15, %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x20(%rsp), %rsi
movq 0x20(%rsi), %rsi
shrq $0x21, %rbx
movl (%rsi,%rbx,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orq %rdx, %rsi
movq %rsi, (%rax,%rcx,8)
movl %r14d, 0x8(%rax,%rcx,8)
movq 0x18(%r11), %rcx
movq -0x8(%rcx,%r12,8), %rax
movq (%rcx,%r12,8), %rbx
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdx
shrq $0x21, %rdx
leaq (%rdx,%rdx,4), %rsi
movq 0x18(%rcx,%rsi,8), %rdx
andq %r13, %rbx
jne 0x21ef7d
xorl %esi, %esi
jmp 0x21ef86
leaq (%rcx,%rsi,8), %rsi
movl 0x10(%rsi), %esi
decl %esi
movq (%rdx,%rsi,8), %r14
movq %rax, %rdx
shrq $0x21, %rdx
leaq (%rdx,%rdx,4), %rsi
movq 0x18(%rcx,%rsi,8), %rdx
testq %r13, %rax
jne 0x21efaa
leaq (%rcx,%rsi,8), %rcx
movl 0x10(%rcx), %ecx
decl %ecx
jmp 0x21efac
xorl %ecx, %ecx
xorl %r15d, %r15d
testq %r13, %rax
sete %r15b
xorl 0x4(%rdx,%rcx,8), %r15d
movq (%r10), %rcx
movq 0x10(%r10), %rax
cmpq 0x8(%r10), %rcx
jne 0x21efff
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r10)
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r10
movq (%rsp), %r11
movq %rax, 0x10(%r10)
movq (%r10), %rcx
movq %r14, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
xorq %r13, %rbx
xorq %rdx, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r10)
leaq (%rcx,%rcx,2), %rcx
movups %xmm0, 0x8(%rax,%rcx,8)
movq %rbx, (%rax,%rcx,8)
movq 0x20(%rsp), %rdx
movq 0x20(%rdx), %rdx
shrq $0x21, %r14
movl (%rdx,%r14,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orq %rbx, %rdx
movq %rdx, (%rax,%rcx,8)
movl %r15d, 0x8(%rax,%rcx,8)
movl 0x10(%r11), %ebx
movq 0x18(%rsp), %r15
addl 0x2c(%rsp), %ebp
incq %r12
movl %ebx, %eax
cmpq %rax, %r12
jb 0x21ed80
testl %ebp, %ebp
je 0x21f131
xorl %r8d, %r8d
cmpl $0x1, %ebx
jne 0x21f097
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%r11), %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
movl (%rax,%rcx,8), %r8d
shrl $0x1f, %r8d
leaq 0x30(%rsp), %r9
movq %r15, %rdi
movl %ebp, %esi
movq 0x20(%rsp), %rdx
movq %r10, %rcx
callq 0x113fe2
movq (%rsp), %rbx
cmpl $0x1, 0x10(%rbx)
jne 0x21f0e5
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbx), %rdi
movq (%rdi), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, (%rax,%rcx,8)
jns 0x21f0e9
orb $-0x80, 0x3(%rbx)
jmp 0x21f0e9
movq $0x0, (%r8)
jmp 0x21f131
movq 0x18(%rbx), %rdi
callq 0x2220
movq %r15, 0x18(%rbx)
movl %ebp, 0xc(%rbx)
movl %ebp, 0x10(%rbx)
movl (%rbx), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x30(%rsp), %ecx
movl %eax, %edx
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rbx)
testl %eax, %eax
js 0x21f129
movl 0x4(%r15), %eax
movl %eax, 0x4(%rbx)
decl %ebp
movl 0x4(%r15,%rbp,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbx)
jmp 0x21f131
movq $-0x1, 0x4(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq