// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/syncerr.c
// Function: find_error_syncmers
int64_t find_error_syncmers(scg_t *g, uint32_t err_mer_c, uint32_t max_err_c, uint32_t err_arc_c, double max_arc_f, int del_err)
{
    asmg_t *asmg;
    syncmer_t *scm;
    asmg_arc_t *a;
    size_t i, j, k, n_scm, n_arc;
    uint32_t nv, nw;
    int b[2];

    asmg = g->utg_asmg;
    n_scm = g->scm_db->n;
    scm = g->scm_db->a;

    for (i = 0; i < n_scm; ++i) {
        if (scm[i].del || scm[i].cov >= max_err_c)
            continue;
        if (scm[i].cov < err_mer_c) {
            scm[i].del = 1;
            continue;
        }
        nv = scm[i].cov;
        b[0] = b[1] = -1;
        for (k = 0; k < 2; ++k) {
            a = asmg_arc_a(asmg, i << 1 | k);
            n_arc = asmg_arc_n1(asmg, i << 1 | k);
            if (n_arc) b[k] = 0;
            else continue;
            n_arc = asmg_arc_n(asmg, i << 1 | k);
            for (j = 0; j < n_arc; ++j) {
                if (a[j].del) continue;
                nw = scm[a[j].w >> 1].cov;
                if (a[j].cov >= err_arc_c && a[j].cov >= MIN(nv, nw) * max_arc_f) {
                    // good arc found
                    b[k] = 1;
                    break;
                }
            }
        }
        if (!b[0] || !b[1]) scm[i].del = 1;
    }

    int64_t n_err = 0;
    uint32_t max_c = 0;
    for (i = 0; i < n_scm; ++i) {
        if (scm[i].del) {
            if (scm[i].cov > max_c)
                max_c = scm[i].cov;
            ++n_err;
#ifdef DEBUG_FIND_SYNCERR
            fprintf(stderr, "[DEBUG_FIND_SYNCERR::%s] error syncmer: %lu %u\n", __func__, i, scm[i].cov);
            if (scm[i].cov > err_mer_c) {
                for (k = 0; k < 2; ++k) {
                    a = asmg_arc_a(asmg, i << 1 | k);
                    n_arc = asmg_arc_n(asmg, i << 1 | k);
                    for (j = 0; j < n_arc; ++j) {
                        if (a[j].del || a[j].comp) continue;
                        fprintf(stderr, "[DEBUG_FIND_SYNCERR::%s] error syncmer arc list: "
                                "%lu %lu%c -> %lu%c v_cov = %u w_cov = %u arc_cov = %u\n", 
                                __func__, j, 
                                a[j].v>>1, "+-"[a[j].v&1], 
                                a[j].w>>1, "+-"[a[j].w&1], 
                                scm[a[j].v>>1].cov, scm[a[j].w>>1].cov, a[j].cov);
                    }
                }
            }
#endif
        }
    }
    
    if (del_err) {
        for (i = 0; i < n_scm; ++i)
            if (scm[i].del)
                asmg_vtx_del(asmg, i, 1);
    }

    fprintf(stderr, "[M::%s] error syncmer candidates: num = %ld, max_c = %u\n", __func__, n_err, max_c);

    return n_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq (%rdi), %rax
movq 0x8(%rdi), %rdi
movq (%rax), %r13
movq 0x10(%rax), %r10
testq %r13, %r13
jne 0x2b0d
xorl %ebx, %ebx
xorl %eax, %eax
jmp 0x2cb8
movl %r8d, 0xc(%rsp)
xorl %eax, %eax
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq %r13, 0x18(%rsp)
movl %edx, 0x14(%rsp)
movl %esi, 0x10(%rsp)
movq %rax, %r14
shlq $0x5, %r14
movl 0x10(%r10,%r14), %ebx
testl %ebx, %ebx
sets %r8b
cmpl %edx, %ebx
setae %r9b
orb %r8b, %r9b
jne 0x2c70
cmpl %esi, %ebx
jae 0x2b62
leaq (%r10,%r14), %r8
addq $0x10, %r8
orl $0x80000000, %ebx       # imm = 0x80000000
movl %ebx, (%r8)
jmp 0x2c70
movq %r14, 0x20(%rsp)
orq $-0x1, 0x4(%rsp)
movq 0x28(%rdi), %rdx
movq 0x30(%rdi), %rsi
movq %rsi, 0x28(%rsp)
leaq (%rax,%rax), %r13
movq 0x38(%rdi), %rbp
addq $0x20, %rdx
movq %rdx, 0x30(%rsp)
xorl %r9d, %r9d
leaq (%r9,%r13), %rdx
movq (%rbp,%rdx,8), %r12
testq %r12, %r12
je 0x2c38
movq 0x28(%rsp), %rsi
imulq $0x30, (%rsi,%rdx,8), %rsi
addq 0x30(%rsp), %rsi
movq %rsi, %r14
movq %r12, %rdx
movq %r12, %r8
movl (%r14), %r15d
addl %r15d, %r15d
sarl $0x1f, %r15d
movslq %r15d, %r15
addq %r15, %r8
addq $0x30, %r14
decq %rdx
jne 0x2bb8
testq %r8, %r8
je 0x2c38
andl $0x0, 0x4(%rsp,%r9,4)
movl (%rsi), %r14d
btl $0x1e, %r14d
jb 0x2c24
andl $0x3fffffff, %r14d      # imm = 0x3FFFFFFF
cmpl %ecx, %r14d
jb 0x2c24
movq -0x18(%rsi), %rdx
shlq $0x4, %rdx
andq $-0x20, %rdx
movl 0x10(%r10,%rdx), %edx
andl %r11d, %edx
movl %ebx, %r8d
cmpl %edx, %ebx
jb 0x2c10
movl %edx, %r8d
cvtsi2sd %r14d, %xmm1
cvtsi2sd %r8d, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x2c2f
addq $0x30, %rsi
decq %r12
jne 0x2bdc
jmp 0x2c38
movl $0x1, 0x4(%rsp,%r9,4)
leaq 0x1(%r9), %rdx
testq %r9, %r9
movq %rdx, %r9
je 0x2b8e
cmpl $0x0, 0x4(%rsp)
movq 0x18(%rsp), %r13
movl 0x14(%rsp), %edx
movl 0x10(%rsp), %esi
movq 0x20(%rsp), %r14
je 0x2b4c
cmpl $0x0, 0x8(%rsp)
je 0x2b4c
incq %rax
cmpq %r13, %rax
jne 0x2b27
leaq 0x10(%r10), %rcx
xorl %eax, %eax
movq %r13, %rdx
xorl %ebx, %ebx
movl 0xc(%rsp), %r8d
movl (%rcx), %esi
movl %esi, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
cmpl %eax, %r11d
cmovbel %eax, %r11d
movl %esi, %r9d
shrl $0x1f, %r9d
addq %r9, %rbx
testl %esi, %esi
cmovsl %r11d, %eax
addq $0x20, %rcx
decq %rdx
jne 0x2c8c
testl %r8d, %r8d
sete %cl
testq %r13, %r13
sete %dl
orb %cl, %dl
jne 0x2df6
xorl %ecx, %ecx
movq %rcx, %rdx
shlq $0x5, %rdx
cmpl $0x0, 0x10(%r10,%rdx)
jns 0x2dea
movq 0x10(%rdi), %rdx
imulq $0x28, %rcx, %rsi
orl $0x40000000, 0x20(%rdx,%rsi) # imm = 0x40000000
leaq (%rcx,%rcx), %rdx
movq 0x38(%rdi), %rsi
movq %rcx, %r8
shlq $0x4, %r8
movq (%rsi,%r8), %rsi
testq %rsi, %rsi
je 0x2d70
movq 0x30(%rdi), %r9
imulq $0x30, (%r9,%r8), %r8
addq 0x28(%rdi), %r8
xorl %r9d, %r9d
imulq $0x30, %r9, %r11
orb $0x40, 0x23(%r8,%r11)
movq 0x8(%r8,%r11), %r14
xorq $0x1, %r14
movq 0x38(%rdi), %r11
movq (%r11,%r14,8), %r11
testq %r11, %r11
je 0x2d68
movq 0x28(%rdi), %r15
movq 0x30(%rdi), %r12
imulq $0x30, (%r12,%r14,8), %r14
addq %r15, %r14
addq $0x20, %r14
movq -0x18(%r14), %r15
xorq %rdx, %r15
cmpq $0x1, %r15
jne 0x2d5f
orb $0x40, 0x3(%r14)
addq $0x30, %r14
decq %r11
jne 0x2d4d
incq %r9
cmpq %rsi, %r9
jne 0x2d19
movq 0x38(%rdi), %rsi
movq 0x8(%rsi,%rdx,8), %rsi
testq %rsi, %rsi
je 0x2dea
movq 0x30(%rdi), %r8
imulq $0x30, 0x8(%r8,%rdx,8), %r8
orq $0x1, %rdx
addq 0x28(%rdi), %r8
xorl %r9d, %r9d
imulq $0x30, %r9, %r11
orb $0x40, 0x23(%r8,%r11)
movq 0x8(%r8,%r11), %r14
xorq $0x1, %r14
movq 0x38(%rdi), %r11
movq (%r11,%r14,8), %r11
testq %r11, %r11
je 0x2de2
movq 0x28(%rdi), %r15
movq 0x30(%rdi), %r12
imulq $0x30, (%r12,%r14,8), %r14
addq %r15, %r14
addq $0x20, %r14
movq -0x18(%r14), %r15
xorq %rdx, %r15
cmpq $0x1, %r15
jne 0x2dd9
orb $0x40, 0x3(%r14)
addq $0x30, %r14
decq %r11
jne 0x2dc7
incq %r9
cmpq %rsi, %r9
jne 0x2d93
incq %rcx
cmpq %r13, %rcx
jne 0x2cce
movq 0x211f3(%rip), %rcx     # 0x23ff0
movq (%rcx), %rdi
leaq 0x1b889(%rip), %rsi     # 0x1e690
leaq 0x1b8bb(%rip), %rdx     # 0x1e6c9
movq %rbx, %rcx
movl %eax, %r8d
xorl %eax, %eax
callq 0x2290
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq