// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_utg_attributes(ma_ug_t*, asg_t*, ma_sub_t*, ma_hit_t_alloc*, R_to_U*)
uint8_t* get_utg_attributes(ma_ug_t *ug, asg_t* read_g, ma_sub_t* coverage_cut, 
ma_hit_t_alloc* sources, R_to_U* ruIndex)
{
    asg_t* nsg = ug->g;
    uint32_t v, n_vtx = nsg->n_seq, k, j, rId, available_reads = 0, tn, is_Unitig;
    ma_utg_t* u = NULL;
    ma_hit_t *h;
    long long R_bases = 0, C_bases = 0, C_bases_primary = 0, C_bases_alter = 0;
    uint8_t* r_flag = (uint8_t*)calloc(read_g->n_seq, sizeof(uint8_t));
    uint8_t* u_flag = (uint8_t*)calloc(n_vtx, sizeof(uint8_t));
    for (v = 0; v < n_vtx; ++v) 
    {
        if(nsg->seq[v].del) continue;
        u = &(ug->u.a[v]);
        if(u->m == 0) continue;
        available_reads = 0;
        for (k = 0; k < u->n; k++)
        {
            rId = u->a[k]>>33;
            r_flag[rId] = 1;
        }

        for (k = 0; k < u->n; k++)
        {
            rId = u->a[k]>>33;
            C_bases = C_bases_primary = C_bases_alter = 0;
            R_bases = coverage_cut[rId].e - coverage_cut[rId].s;
            for (j = 0; j < (uint64_t)(sources[rId].length); j++)
            {
                h = &(sources[rId].buffer[j]);
                if(h->el != 1) continue;
                tn = Get_tn((*h));
                if(read_g->seq[tn].del == 1)
                {
                    ///get the id of read that contains it 
                    get_R_to_U(ruIndex, tn, &tn, &is_Unitig);
                    if(tn == (uint32_t)-1 || is_Unitig == 1 || read_g->seq[tn].del == 1) continue;
                }
                if(read_g->seq[tn].del == 1) continue;
                if(r_flag[tn])
                {
                    C_bases_primary += Get_qe((*h)) - Get_qs((*h));
                }
                else
                {
                    C_bases_alter += Get_qe((*h)) - Get_qs((*h));
                }
            }

            C_bases = C_bases_primary + C_bases_alter;
            if(C_bases_alter < C_bases * ALTER_COV_THRES) continue;

            C_bases = C_bases/R_bases;
            if(C_bases >= asm_opt.recover_atg_cov_min && C_bases <= asm_opt.recover_atg_cov_max)
            {
                available_reads++;
            }
        }


        if(available_reads < (u->n * 0.8) || available_reads == 0)
        {
            u_flag[v] = 0;
        }
        else
        {
            u_flag[v] = 1;
        }

        for (k = 0; k < u->n; k++)
        {
            rId = u->a[k]>>33;
            r_flag[rId] = 0;
        }
    }

    free(r_flag);
    return u_flag;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x88(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x90(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x12063a
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x12031e
jmp 0x12062c
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x120343
jmp 0x12062c
movl $0x0, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x12038c
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq -0x88(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x120351
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x12059e
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x20(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x12051d
movq -0x20(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x1, %eax
je 0x120455
jmp 0x12050f
movq -0x60(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x1204af
movq -0x28(%rbp), %rdi
movl -0x4c(%rbp), %esi
leaq -0x4c(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x4c(%rbp)
je 0x1204ab
cmpl $0x1, -0x50(%rbp)
je 0x1204ab
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x1204ad
jmp 0x12050f
jmp 0x1204af
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x1204c7
jmp 0x12050f
movq -0x88(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpb $0x0, (%rax,%rcx)
je 0x1204f3
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x12050d
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x12050f
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x120407
movq -0x78(%rbp), %rax
addq -0x80(%rbp), %rax
movq %rax, -0x70(%rbp)
cvtsi2sdq -0x80(%rbp), %xmm1
cvtsi2sdq -0x70(%rbp), %xmm0
movsd 0x261d2b(%rip), %xmm2   # 0x382268
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x120549
jmp 0x120590
movq -0x70(%rbp), %rax
cqto
idivq -0x68(%rbp)
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
leaq 0x2a4296(%rip), %rcx    # 0x3c47f8
movslq 0x13c(%rcx), %rcx
cmpq %rcx, %rax
jl 0x12058e
movq -0x70(%rbp), %rax
leaq 0x2a427f(%rip), %rcx    # 0x3c47f8
movslq 0x140(%rcx), %rcx
cmpq %rcx, %rax
jg 0x12058e
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x120590
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x120393
movl -0x48(%rbp), %eax
cvtsi2sd %rax, %xmm1
movq -0x58(%rbp), %rax
movl 0x10(%rax), %eax
cvtsi2sd %rax, %xmm0
movsd 0x261c76(%rip), %xmm2   # 0x382230
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
ja 0x1205ca
cmpl $0x0, -0x48(%rbp)
jne 0x1205da
movq -0x90(%rbp), %rax
movl -0x34(%rbp), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x1205e8
movq -0x90(%rbp), %rax
movl -0x34(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x12062a
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x21, %rax
movl %eax, -0x44(%rbp)
movq -0x88(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1205ef
jmp 0x12062c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1202f7
movq -0x88(%rbp), %rdi
callq 0x2210
movq -0x90(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)