// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq (%rdi), %rax
movq (%rax), %r13
testq %r13, %r13
jne 0x2af6
xorl %r8d, %r8d
xorl %ebx, %ebx
jmp 0x2dfb
movl %r8d, 0x14(%rsp)
movq 0x8(%rdi), %rdi
movq 0x10(%rax), %r10
xorl %r9d, %r9d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq %r13, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movl %esi, 0x18(%rsp)
movq %r9, %r11
shlq $0x5, %r11
movl 0x10(%r10,%r11), %r15d
testl %r15d, %r15d
sets %al
cmpl %edx, %r15d
setae %r8b
orb %al, %r8b
jne 0x2c79
cmpl %esi, %r15d
jae 0x2b56
leaq (%r10,%r11), %rax
addq $0x10, %rax
orl $0x80000000, %r15d      # imm = 0x80000000
movl %r15d, (%rax)
jmp 0x2c79
movq %r11, 0x28(%rsp)
orl $-0x1, 0xc(%rsp)
orl $-0x1, 0x10(%rsp)
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %rdx
movq %rdx, 0x38(%rsp)
movq %r9, 0x30(%rsp)
leaq (%r9,%r9), %r11
movq 0x38(%rdi), %r9
addq $0x20, %rax
movq %rax, 0x40(%rsp)
movb $0x1, %sil
leaq 0x10(%rsp), %r14
xorl %eax, %eax
orq %r11, %rax
movq (%r9,%rax,8), %r13
testq %r13, %r13
je 0x2c35
movq 0x38(%rsp), %rdx
imulq $0x30, (%rdx,%rax,8), %rbx
addq 0x40(%rsp), %rbx
movq %rbx, %r12
movq %r13, %rax
movq %r13, %rdx
movl (%r12), %r8d
addl %r8d, %r8d
sarl $0x1f, %r8d
movslq %r8d, %r8
addq %r8, %rdx
addq $0x30, %r12
decq %rax
jne 0x2bba
testq %rdx, %rdx
je 0x2c35
andl $0x0, (%r14)
movl (%rbx), %r12d
btl $0x1e, %r12d
jb 0x2c23
andl $0x3fffffff, %r12d      # imm = 0x3FFFFFFF
cmpl %ecx, %r12d
jb 0x2c23
movq -0x18(%rbx), %rax
shlq $0x4, %rax
andq $-0x20, %rax
movl 0x10(%r10,%rax), %eax
andl %ebp, %eax
movl %r15d, %edx
cmpl %eax, %r15d
jb 0x2c10
movl %eax, %edx
cvtsi2sd %r12d, %xmm1
cvtsi2sd %edx, %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jae 0x2c2e
addq $0x30, %rbx
decq %r13
jne 0x2bdd
jmp 0x2c35
movl $0x1, (%r14)
leaq 0xc(%rsp), %r14
pushq $0x1
popq %rax
testb $0x1, %sil
movl $0x0, %esi
jne 0x2b92
cmpl $0x0, 0x10(%rsp)
movq 0x20(%rsp), %r13
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %esi
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %r11
je 0x2b3f
cmpl $0x0, 0xc(%rsp)
je 0x2b3f
incq %r9
cmpq %r13, %r9
jne 0x2b18
leaq 0x10(%r10), %rax
xorl %r8d, %r8d
movq %r13, %rcx
xorl %ebx, %ebx
movl %r8d, %edx
movl (%rax), %esi
movl %esi, %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
cmpl %edx, %r8d
cmovbel %edx, %r8d
movl %esi, %r9d
shrl $0x1f, %r9d
addq %r9, %rbx
testl %esi, %esi
cmovnsl %edx, %r8d
addq $0x20, %rax
decq %rcx
jne 0x2c91
cmpl $0x0, 0x14(%rsp)
je 0x2dfb
xorl %eax, %eax
movq %rax, %rcx
shlq $0x5, %rcx
cmpl $0x0, 0x10(%r10,%rcx)
jns 0x2def
movq 0x10(%rdi), %rcx
imulq $0x28, %rax, %rdx
orl $0x40000000, 0x20(%rcx,%rdx) # imm = 0x40000000
leaq (%rax,%rax), %rcx
movq 0x38(%rdi), %r9
movq %rax, %r14
shlq $0x4, %r14
movq (%r9,%r14), %rsi
movq 0x28(%rdi), %rdx
movq 0x30(%rdi), %r11
testq %rsi, %rsi
je 0x2d7e
imulq $0x30, (%r11,%r14), %r9
addq %r9, %rdx
xorl %r9d, %r9d
imulq $0x30, %r9, %r11
orb $0x40, 0x23(%rdx,%r11)
movq 0x8(%rdx,%r11), %r14
xorq $0x1, %r14
movq 0x38(%rdi), %r11
movq (%r11,%r14,8), %r11
testq %r11, %r11
je 0x2d6a
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 %rcx, %r15
cmpq $0x1, %r15
jne 0x2d61
orb $0x40, 0x3(%r14)
addq $0x30, %r14
decq %r11
jne 0x2d4f
incq %r9
cmpq %rsi, %r9
jne 0x2d1b
movq 0x38(%rdi), %r9
movq 0x28(%rdi), %rdx
movq 0x30(%rdi), %r11
movq 0x8(%r9,%rcx,8), %rsi
testq %rsi, %rsi
je 0x2def
imulq $0x30, 0x8(%r11,%rcx,8), %r9
orq $0x1, %rcx
addq %r9, %rdx
xorl %r9d, %r9d
imulq $0x30, %r9, %r11
orb $0x40, 0x23(%rdx,%r11)
movq 0x8(%rdx,%r11), %r14
xorq $0x1, %r14
movq 0x38(%rdi), %r11
movq (%r11,%r14,8), %r11
testq %r11, %r11
je 0x2de7
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 %rcx, %r15
cmpq $0x1, %r15
jne 0x2dde
orb $0x40, 0x3(%r14)
addq $0x30, %r14
decq %r11
jne 0x2dcc
incq %r9
cmpq %rsi, %r9
jne 0x2d98
incq %rax
cmpq %r13, %rax
jne 0x2ccd
movq 0x231ee(%rip), %rax     # 0x25ff0
movq (%rax), %rdi
leaq 0x1d914(%rip), %rsi     # 0x20720
leaq 0x1d946(%rip), %rdx     # 0x20759
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2280
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq