// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: deter_unitig_het_fly(ma_ug_t*, unsigned int, asg_t*, long, ma_hit_t_alloc*, R_to_U*, unsigned char*)
uint32_t deter_unitig_het_fly(ma_ug_t* ug, uint32_t uid, asg_t* sg, int64_t het_cov_thres,
ma_hit_t_alloc* sources, R_to_U* ruIndex, uint8_t* r_flag)
{
    ma_utg_t *u = &(ug->u.a[uid]);
    uint32_t k, i, j, rId, nv, tn, is_Unitig;
    asg_arc_t *av = NULL; ma_hit_t *h;
    int64_t R_bases = 0, C_bases = 0, cov;

    ///set
    u = &(ug->u.a[uid]);
    for (k = 0; k < u->n; k++) {
        rId = u->a[k]>>33;
        r_flag[rId] = 1;
    }
    for (i = 0; i < 2; i++) {
        nv = asg_arc_n(ug->g, (uid<<1)+i);
        av = asg_arc_a(ug->g, (uid<<1)+i);
        for (j = 0; j < nv; j++) {
            u = &(ug->u.a[av[j].v>>1]);
            for (k = 0; k < u->n; k++) {
                rId = u->a[k]>>33;
                r_flag[rId] = 2;
            }
        }
    }

    u = &(ug->u.a[uid]);
    for (k = 0; k < u->n; k++) {
        if(u->a[k] == (uint64_t)-1) continue;
        rId = u->a[k]>>33;
        R_bases += sg->seq[rId].len;
        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(sg->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 || sg->seq[tn].del == 1) continue;
            }
            if(sg->seq[tn].del == 1) continue;
            if(r_flag[tn] == 0) continue;
            if(r_flag[tn] == 1) {
                C_bases += (Get_qe((*h)) - Get_qs((*h)));
            }
            if(r_flag[tn] == 2) {
                C_bases += ((Get_qe((*h)) - Get_qs((*h)))/2);
            }
        }
    }

    ///reset
    u = &(ug->u.a[uid]);
    for (k = 0; k < u->n; k++) {
        rId = u->a[k]>>33;
        r_flag[rId] = 0;
    }
    for (i = 0; i < 2; i++) {
        nv = asg_arc_n(ug->g, (uid<<1)+i);
        av = asg_arc_a(ug->g, (uid<<1)+i);
        for (j = 0; j < nv; j++) {
            u = &(ug->u.a[av[j].v>>1]);
            for (k = 0; k < u->n; k++) {
                rId = u->a[k]>>33;
                r_flag[rId] = 0;
            }
        }
    }

    u = &(ug->u.a[uid]); cov = 0;
    if(R_bases > 0) cov = C_bases/R_bases;
    if(cov <= het_cov_thres) return 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, 0x60(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %r15
movq 0xa0(%rsp), %r13
movl %esi, %ecx
movq 0x10(%rdi), %rax
leaq (%rcx,%rcx,4), %rdi
cmpl $0x0, 0x10(%rax,%rdi,8)
je 0x14070f
leaq (%rax,%rdi,8), %rax
xorl %ecx, %ecx
movq 0x18(%rax), %rdx
movq (%rdx,%rcx,8), %rdx
shrq $0x21, %rdx
movb $0x1, (%r13,%rdx)
incq %rcx
movl 0x10(%rax), %edx
cmpq %rdx, %rcx
jb 0x1406f2
movq %rdi, 0x28(%rsp)
addl %esi, %esi
movb $0x1, %al
xorl %ecx, %ecx
movq 0x18(%r15), %rdx
shlq $0x3, %rcx
addq 0x28(%rdx), %rcx
movq (%rcx,%rsi,8), %rdi
testl %edi, %edi
je 0x14078f
movq %rdi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rdx), %rcx
movl %edi, %edx
xorl %r10d, %r10d
movq 0x10(%r15), %rdi
leaq (%r10,%r10,2), %r9
movl 0x8(%rcx,%r9,8), %r9d
shrl %r9d
leaq (%r9,%r9,4), %r9
cmpl $0x0, 0x10(%rdi,%r9,8)
je 0x140787
leaq (%rdi,%r9,8), %rdi
xorl %r11d, %r11d
movq 0x18(%rdi), %r9
movq (%r9,%r11,8), %r9
shrq $0x21, %r9
movb $0x2, (%r13,%r9)
incq %r11
movl 0x10(%rdi), %r9d
cmpq %r9, %r11
jb 0x140769
incq %r10
cmpq %rdx, %r10
jne 0x140746
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x14071a
movq 0x10(%r15), %rcx
movq 0x28(%rsp), %rdx
movl 0x10(%rcx,%rdx,8), %eax
testl %eax, %eax
je 0x140936
leaq (%rcx,%rdx,8), %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq %rsi, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x38(%rsp)
movq 0x18(%r9), %rcx
movq (%rcx,%r10,8), %rcx
cmpq $-0x1, %rcx
je 0x1408f3
shrq $0x21, %rcx
movq 0x20(%rdi), %rdx
movl (%rdx,%rcx,8), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq %rdx, %rbx
leaq (%rcx,%rcx,2), %rcx
cmpl $0x0, 0xc(%r8,%rcx,8)
je 0x1408f3
movq %r10, 0x50(%rsp)
movq %rbx, 0x58(%rsp)
leaq (%r8,%rcx,8), %r14
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r14), %r12
cmpb $0x1, 0x20(%r12,%rbx)
jne 0x1408ad
movl 0xc(%r12,%rbx), %esi
movl %esi, 0xc(%rsp)
movq 0x20(%rdi), %rax
cmpl $0x0, (%rax,%rsi,8)
js 0x14085b
movzbl (%r13,%rsi), %eax
cmpl $0x2, %eax
je 0x14089f
cmpl $0x1, %eax
jne 0x1408ad
movl 0x8(%r12,%rbx), %eax
subl (%r12,%rbx), %eax
jmp 0x1408aa
movq %r11, 0x30(%rsp)
movq 0x60(%rsp), %rdi
leaq 0xc(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0xa3c62
movl 0xc(%rsp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %rsi
je 0x1408ca
cmpl $0x1, 0x1c(%rsp)
movq 0x30(%rsp), %r11
je 0x1408c3
movq 0x10(%rsp), %rdi
movq 0x20(%rdi), %rax
cmpl $0x0, (%rax,%rsi,8)
jns 0x140840
jmp 0x1408ad
movl 0x8(%r12,%rbx), %eax
subl (%r12,%rbx), %eax
shrl %eax
addq %rax, %r11
incq %rbp
movl 0xc(%r14), %eax
addq $0x28, %rbx
cmpq %rax, %rbp
jb 0x14081e
jmp 0x1408d6
movq 0x10(%rsp), %rdi
jmp 0x1408ad
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %r11
jmp 0x1408ad
movq 0x38(%rsp), %r9
movl 0x10(%r9), %eax
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %r8
movq 0x58(%rsp), %rbx
movq 0x50(%rsp), %r10
incq %r10
movl %eax, %ecx
cmpq %rcx, %r10
jb 0x1407d6
movq 0x10(%r15), %rax
movq 0x28(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
je 0x14093b
leaq (%rax,%rcx,8), %rax
xorl %ecx, %ecx
movq 0x18(%rax), %rdx
movq (%rdx,%rcx,8), %rdx
shrq $0x21, %rdx
movb $0x0, (%r13,%rdx)
incq %rcx
movl 0x10(%rax), %edx
cmpq %rdx, %rcx
jb 0x140917
jmp 0x14093b
xorl %r11d, %r11d
xorl %ebx, %ebx
movb $0x1, %al
xorl %ecx, %ecx
movq 0x18(%r15), %rdx
shlq $0x3, %rcx
addq 0x28(%rdx), %rcx
movq (%rcx,%rsi,8), %rdi
testl %edi, %edi
je 0x1409b4
movq %rdi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x3, %rcx
addq 0x8(%rdx), %rcx
movl %edi, %edx
xorl %r10d, %r10d
movq 0x10(%r15), %rdi
leaq (%r10,%r10,2), %r8
movl 0x8(%rcx,%r8,8), %r8d
shrl %r8d
leaq (%r8,%r8,4), %r8
cmpl $0x0, 0x10(%rdi,%r8,8)
je 0x1409ac
leaq (%rdi,%r8,8), %rdi
xorl %r8d, %r8d
movq 0x18(%rdi), %r9
movq (%r9,%r8,8), %r9
shrq $0x21, %r9
movb $0x0, (%r13,%r9)
incq %r8
movl 0x10(%rdi), %r9d
cmpq %r9, %r8
jb 0x14098e
incq %r10
cmpq %rdx, %r10
jne 0x14096b
movl $0x1, %ecx
testb $0x1, %al
movl $0x0, %eax
jne 0x14093f
testq %rbx, %rbx
jle 0x1409d5
movq %r11, %rax
cqto
idivq %rbx
jmp 0x1409d7
xorl %eax, %eax
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
cmpq %rdx, %rax
setle %cl
movl %ecx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq