// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movsd %xmm0, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x1ae43
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x1ac06
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x10(%rbp), %eax
jb 0x1ac0b
jmp 0x1ae32
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0xc(%rbp), %eax
jae 0x1ac4d
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x10(%rax)
jmp 0x1ae32
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x6c(%rbp)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x78(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x58(%rbp)
cmpq $0x2, -0x58(%rbp)
jae 0x1ae03
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x48(%rbp), %rdx
shlq %rdx
orq -0x58(%rbp), %rdx
imulq $0x30, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq %rsi
orq -0x58(%rbp), %rsi
callq 0x1af70
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1acdc
movq -0x58(%rbp), %rax
movl $0x0, -0x78(%rbp,%rax,4)
jmp 0x1ace1
jmp 0x1adf2
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x48(%rbp), %rcx
shlq %rcx
orq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x68(%rbp), %rax
jae 0x1adf0
movq -0x40(%rbp), %rax
imulq $0x30, -0x50(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1ad31
jmp 0x1addf
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
imulq $0x30, -0x50(%rbp), %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x70(%rbp)
movq -0x40(%rbp), %rax
imulq $0x30, -0x50(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cmpl -0x14(%rbp), %eax
jb 0x1addd
movq -0x40(%rbp), %rax
imulq $0x30, -0x50(%rbp), %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x90(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jae 0x1ada6
movl -0x6c(%rbp), %eax
movl %eax, -0x94(%rbp)
jmp 0x1adaf
movl -0x70(%rbp), %eax
movl %eax, -0x94(%rbp)
movsd -0x90(%rbp), %xmm0
movl -0x94(%rbp), %eax
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd -0x20(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x1addd
movq -0x58(%rbp), %rax
movl $0x1, -0x78(%rbp,%rax,4)
jmp 0x1adf0
jmp 0x1addf
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1ad04
jmp 0x1adf2
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1ac7d
cmpl $0x0, -0x78(%rbp)
je 0x1ae0f
cmpl $0x0, -0x74(%rbp)
jne 0x1ae30
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x10(%rax)
jmp 0x1ae32
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1abc2
movq $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x1aed9
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1aec9
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x84(%rbp), %eax
jbe 0x1aebd
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x84(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x1aecb
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1ae5d
cmpl $0x0, -0x24(%rbp)
je 0x1af2f
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x1af2d
movq -0x38(%rbp), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x1af1d
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl $0x1, %edx
callq 0x1b010
jmp 0x1af1f
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1aee7
jmp 0x1af2f
movq 0x190c2(%rip), %rax     # 0x33ff8
movq (%rax), %rdi
movq -0x80(%rbp), %rcx
movl -0x84(%rbp), %r8d
leaq 0x1365d(%rip), %rsi     # 0x2e5a8
leaq 0x1368f(%rip), %rdx     # 0x2e5e1
movb $0x0, %al
callq 0x2290
movq -0x80(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)