// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
cmpl $0x0, 0xc(%rdi)
je 0x213cb4
movq %r8, %r15
movq %rdi, %rbp
movl 0x10(%rdi), %eax
xorl %edi, %edi
testq %rax, %rax
je 0x2138ca
movq (%rcx), %rcx
movq 0x18(%rbp), %rdx
movabsq $0x1ffffffff, %rsi      # imm = 0x1FFFFFFFF
xorl %r8d, %r8d
movq (%rdx,%r8,8), %r9
movq %r9, %r10
shrq $0x21, %r10
imulq $0x78, %r10, %r10
movl (%rcx,%r10), %r11d
shlq $0x21, %r11
andq %rsi, %r9
addl 0x4(%rcx,%r10), %edi
orq %r11, %r9
movq %r9, (%rdx,%r8,8)
incq %r8
cmpq %r8, %rax
jne 0x213896
movl %edi, %edi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %rbx
movq $0x0, (%r15)
cmpl $0x0, 0x10(%rbp)
je 0x213bef
xorl %r12d, %r12d
movabsq $0x100000000, %r13      # imm = 0x100000000
xorps %xmm0, %xmm0
xorl %r14d, %r14d
movq %rbp, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq 0x18(%rbp), %rcx
movq (%rcx,%r12,8), %r8
movq %r8, %rdx
shrq $0x21, %rdx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
leaq (%rdx,%rdx,4), %rdx
leaq (%rax,%rdx,8), %rdx
movl %r14d, %esi
leaq (%rbx,%rsi,8), %rsi
movl 0x10(%rdx), %edi
testq %r13, %r8
jne 0x21394d
testq %rdi, %rdi
je 0x213976
movq 0x18(%rdx), %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
movq %r10, (%rsi,%r9,8)
incq %r9
cmpq %r9, %rdi
jne 0x21393b
jmp 0x213976
testq %rdi, %rdi
je 0x213976
movq 0x18(%rdx), %r8
leal -0x1(%rdi), %r9d
xorl %r10d, %r10d
movq (%r8,%r10,8), %r11
xorq %r13, %r11
movl %r9d, %ebx
movq %r11, (%rsi,%rbx,8)
incq %r10
decl %r9d
cmpq %r10, %rdi
jne 0x21395d
addl 0x10(%rdx), %r14d
movq %r14, 0x28(%rsp)
testq %r12, %r12
je 0x213bce
movq -0x8(%rcx,%r12,8), %rbx
movq (%rcx,%r12,8), %r14
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rdi
movq 0x28(%rdi), %rcx
movq %rbx, %rdx
shrq $0x20, %rdx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0x2139ec
movq %r14, %rsi
shrq $0x20, %rsi
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rdi), %rdx
cmpl $0x0, 0xc(%rdx)
js 0x2139d8
cmpl %esi, 0x8(%rdx)
je 0x2139e3
addq $0x18, %rdx
decq %rcx
jne 0x2139cd
xorl %edx, %edx
testq %rdx, %rdx
jne 0x213bce
movq %rbx, %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
andq %r13, %rbx
jne 0x213a07
leaq (%rax,%rcx,8), %rdx
movl 0x10(%rdx), %edx
decl %edx
jmp 0x213a09
xorl %edx, %edx
movq %r14, %rsi
shrq $0x21, %rsi
leaq (%rsi,%rsi,4), %rsi
andq %r13, %r14
jne 0x213a1d
xorl %edi, %edi
jmp 0x213a26
leaq (%rax,%rsi,8), %rdi
movl 0x10(%rdi), %edi
decl %edi
movq 0x18(%rax,%rcx,8), %rcx
movq 0x18(%rax,%rsi,8), %rax
xorq (%rax,%rdi,8), %r14
movq (%rcx,%rdx,8), %rbp
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x213a6d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
xorps %xmm0, %xmm0
movq %rax, 0x10(%r15)
shrq $0x20, %r14
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
leaq (%rax,%rax,2), %rax
movups %xmm0, (%rcx,%rax,8)
movq $0x0, 0x10(%rcx,%rax,8)
movq %rbp, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
xorq %rbx, %rdx
movq %rdx, (%rcx,%rax,8)
movq 0x10(%rsp), %rsi
movq 0x20(%rsi), %rsi
shrq $0x21, %rbp
movl (%rsi,%rbp,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
orq %rdx, %rsi
movq %rsi, (%rcx,%rax,8)
movl %r14d, 0x8(%rcx,%rax,8)
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rcx,%r12,8), %rax
movq (%rcx,%r12,8), %rbx
movq 0x8(%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 0x213afd
xorl %esi, %esi
jmp 0x213b06
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 0x213b2a
leaq (%rcx,%rsi,8), %rcx
movl 0x10(%rcx), %ecx
decl %ecx
jmp 0x213b2c
xorl %ecx, %ecx
xorl %ebp, %ebp
testq %r13, %rax
sete %bpl
xorl 0x4(%rdx,%rcx,8), %ebp
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x213b6e
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
xorps %xmm0, %xmm0
movq %rax, 0x10(%r15)
movq %r14, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq %rcx, %rax
xorq %r13, %rbx
xorq %rax, %rbx
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
leaq (%rax,%rax,2), %rax
movups %xmm0, (%rcx,%rax,8)
movq $0x0, 0x10(%rcx,%rax,8)
movq %rbx, (%rcx,%rax,8)
movq 0x10(%rsp), %rdx
movq 0x20(%rdx), %rdx
shrq $0x21, %r14
movl (%rdx,%r14,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orq %rbx, %rdx
movq %rdx, (%rcx,%rax,8)
movl %ebp, 0x8(%rcx,%rax,8)
movq 0x18(%rsp), %rbp
incq %r12
movl 0x10(%rbp), %eax
cmpq %rax, %r12
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r14
jb 0x213900
cmpl $0x1, %eax
sete %al
jmp 0x213bf4
xorl %r14d, %r14d
xorl %eax, %eax
testl %r14d, %r14d
je 0x213cb4
xorl %r8d, %r8d
testb %al, %al
je 0x213c24
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %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 %rbx, %rdi
movl %r14d, %esi
movq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x10e9f4
cmpl $0x1, 0x10(%rbp)
jne 0x213c64
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, (%rax,%rcx,8)
jns 0x213c64
orb $-0x80, 0x3(%rbp)
movq 0x18(%rbp), %rdi
callq 0x2220
movq %rbx, 0x18(%rbp)
movl %r14d, 0xc(%rbp)
movl %r14d, 0x10(%rbp)
movl (%rbp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x30(%rsp), %ecx
movl %eax, %edx
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rbp)
testl %eax, %eax
js 0x213cac
movl 0x4(%rbx), %eax
movl %eax, 0x4(%rbp)
decl %r14d
movl 0x4(%rbx,%r14,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbp)
jmp 0x213cb4
movq $-0x1, 0x4(%rbp)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq