// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, 0x18(%rsp)
cmpl $0x0, 0xc(%rdi)
je 0x1d0227
movq %r8, %r13
movq %rsi, %r15
movq %rdi, %rbx
movl 0x10(%rdi), %r14d
xorl %eax, %eax
movabsq $0x1ffffffff, %rsi      # imm = 0x1FFFFFFFF
xorl %edx, %edx
cmpq %rax, %r14
je 0x1cfe88
movq (%rcx), %rdi
movq 0x18(%rbx), %r8
movq (%r8,%rax,8), %r9
movq %r9, %r10
shrq $0x21, %r10
imulq $0x78, %r10, %r10
movl (%rdi,%r10), %r11d
shlq $0x21, %r11
andq %rsi, %r9
orq %r11, %r9
addl 0x4(%rdi,%r10), %edx
movq %r9, (%r8,%rax,8)
incq %rax
jmp 0x1cfe51
movabsq $0x100000000, %r12      # imm = 0x100000000
movl %edx, %edi
shlq $0x3, %rdi
callq 0x2280
movq %rax, %rbp
movq %r13, 0x10(%rsp)
andq $0x0, (%r13)
xorl %r13d, %r13d
xorl %esi, %esi
movq %rbx, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq %rax, 0x30(%rsp)
movl %r14d, %eax
cmpq %rax, %r13
jae 0x1d0177
movq 0x18(%rbx), %rax
movq (%rax,%r13,8), %rdx
movq %rdx, %rcx
shrq $0x21, %rcx
movq 0x10(%r15), %rdi
imulq $0x28, %rcx, %r8
leaq (%rdi,%r8), %rcx
movq %rsi, 0x38(%rsp)
movl %esi, %esi
leaq (,%rsi,8), %rsi
addq %rbp, %rsi
movl 0x10(%rdi,%r8), %ebp
testq %r12, %rdx
jne 0x1cff19
xorl %edi, %edi
cmpq %rdi, %rbp
je 0x1cff48
movq 0x18(%rcx), %r8
movq (%r8,%rdi,8), %r8
movq %r8, (%rsi,%rdi,8)
incq %rdi
jmp 0x1cff03
leaq (,%rbp,8), %rdi
leal -0x1(%rbp), %r8d
xorl %r9d, %r9d
cmpq %r9, %rdi
je 0x1cff48
movq 0x18(%rcx), %r10
movq (%r10,%r9), %r10
xorq %r12, %r10
movl %r8d, %r11d
movq %r10, (%rsi,%r11,8)
addq $0x8, %r9
decl %r8d
jmp 0x1cff28
testq %r13, %r13
je 0x1d0160
movl -0x4(%rax,%r13,8), %esi
shrq $0x20, %rdx
movq 0x18(%r15), %rdi
callq 0x1de62d
testq %rax, %rax
jne 0x1d0160
movq 0x18(%rbx), %rsi
movq -0x8(%rsi,%r13,8), %r8
movq 0x10(%r15), %rax
movq %r8, %rcx
shrq $0x21, %rcx
imulq $0x28, %rcx, %rcx
andq %r12, %r8
jne 0x1cff94
leaq (%rax,%rcx), %rdx
movl 0x10(%rdx), %edx
decl %edx
jmp 0x1cff96
xorl %edx, %edx
movq (%rsi,%r13,8), %r14
movq %r14, %rsi
shrq $0x21, %rsi
imulq $0x28, %rsi, %rsi
andq %r12, %r14
jne 0x1cffae
xorl %edi, %edi
jmp 0x1cffb7
leaq (%rax,%rsi), %rdi
movl 0x10(%rdi), %edi
decl %edi
movq 0x18(%rax,%rcx), %rcx
movq (%rcx,%rdx,8), %rbx
movq 0x18(%rax,%rsi), %rax
xorq (%rax,%rdi,8), %r14
movq 0x10(%rsp), %r15
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x1d000a
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r15)
imulq $0x18, %rdx, %rsi
movq %rax, %rdi
movq %r8, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %r8
movq %rax, 0x10(%r15)
movq (%r15), %rcx
shrq $0x20, %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
imulq $0x18, %rcx, %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax,%rcx)
movq %rbx, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
xorq %r8, %rdx
movq %rdx, (%rax,%rcx)
movq 0x18(%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)
movl %r14d, 0x8(%rax,%rcx)
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rcx
movq -0x8(%rcx,%r13,8), %rax
movq (%rcx,%r13,8), %r15
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rcx
movq %r15, %rdx
shrq $0x21, %rdx
imulq $0x28, %rdx, %rsi
movq 0x18(%rcx,%rsi), %rdx
andq %r12, %r15
jne 0x1d008e
xorl %esi, %esi
jmp 0x1d0096
addq %rcx, %rsi
movl 0x10(%rsi), %esi
decl %esi
movq (%rdx,%rsi,8), %rdi
movq %rax, %rdx
shrq $0x21, %rdx
imulq $0x28, %rdx, %rsi
movq 0x18(%rcx,%rsi), %rdx
testq %r12, %rax
jne 0x1d00b9
addq %rsi, %rcx
movl 0x10(%rcx), %ecx
decl %ecx
jmp 0x1d00bb
xorl %ecx, %ecx
xorl %ebx, %ebx
testq %r12, %rax
sete %bl
xorl 0x4(%rdx,%rcx,8), %ebx
movq 0x10(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x1d0108
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r14)
imulq $0x18, %rdx, %rsi
movq %rdi, 0x8(%rsp)
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movq %rdi, %rdx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
andq %rsi, %rdx
xorq %r12, %r15
xorq %rdx, %r15
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
imulq $0x18, %rcx, %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax,%rcx)
movq %r15, (%rax,%rcx)
movq 0x18(%rsp), %rdx
movq 0x20(%rdx), %rdx
shrq $0x21, %rdi
movl (%rdx,%rdi,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
orq %r15, %rdx
movq %rdx, (%rax,%rcx)
movl %ebx, 0x8(%rax,%rcx)
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r15
addl 0x38(%rsp), %ebp
incq %r13
movl 0x10(%rbx), %r14d
movl %ebp, %esi
movq 0x30(%rsp), %rbp
jmp 0x1cfebe
testl %esi, %esi
je 0x1d0227
xorl %r8d, %r8d
cmpl $0x1, %r14d
jne 0x1d01a3
movq 0x10(%r15), %rax
movq 0x18(%rbx), %rcx
movq (%rcx), %rcx
shrq $0x21, %rcx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %r8d
shrl $0x1f, %r8d
leaq 0x40(%rsp), %r9
movq %rbp, %rdi
movq %rsi, %r14
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0xcfa82
cmpl $0x1, 0x10(%rbx)
movq 0x18(%rbx), %rdi
jne 0x1d01e0
movq 0x10(%r15), %rax
movq (%rdi), %rcx
shrq $0x21, %rcx
imulq $0x28, %rcx, %rcx
cmpl $0x0, (%rax,%rcx)
jns 0x1d01e0
orb $-0x80, 0x3(%rbx)
callq 0x2220
movq %rbp, 0x18(%rbx)
movl %r14d, 0xc(%rbx)
movl %r14d, 0x10(%rbx)
movl (%rbx), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x40(%rsp), %ecx
movl %eax, %edx
andl $0x80000000, %edx       # imm = 0x80000000
orl %ecx, %edx
movl %edx, (%rbx)
testl %eax, %eax
js 0x1d0222
movl 0x4(%rbp), %eax
movl %eax, 0x4(%rbx)
decl %r14d
movl 0x4(%rbp,%r14,8), %eax
xorl $0x1, %eax
movl %eax, 0x8(%rbx)
jmp 0x1d0227
orq $-0x1, 0x4(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq