// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncasm.c
// Function: scg_unitig_consensus
int64_t scg_unitig_consensus(sr_db_t *sr_db, uint64_t *v, uint64_t n, syncmer_t *scm, kstring_t *c_seq, int hoco_seq)
{
    if (n == 0) return 0;

    uint64_t i;
    int64_t beg_pos, end_pos, l;
    int w;
    kh_generic_t *h;

    w = sr_db->k;
    h = kh_generic_init();
    int64_t *pos;
    MYMALLOC(pos, n);
    pos[0] = 0;
    for (i = 1; i < n; ++i) {
        syncmer_t *m1 = &scm[v[i-1]>>1];
        syncmer_t *m2 = &scm[v[i]>>1];
        pos[i] = pos[i-1] + calc_syncmer_overlap(sr_db, m1, v[i-1]&1, m2, v[i]&1, h);
    }

#ifdef DEBUG_KMER_OVERLAP
    for (i = 0; i < n; ++i)
        fprintf(stderr, "[DEBUG_KMER_OVERLAP::%s] overlap [%lu %lu]\n", __func__, i, pos[i]);
#endif

    beg_pos = end_pos = l = 0;
    for (i = 0; i < n; ++i) {
        while (i+1 < n && pos[i+1] <= end_pos) ++i;
        beg_pos = pos[i];
        l += scg_syncmer_consensus(sr_db, &scm[v[i]>>1], v[i]&1, end_pos - beg_pos, c_seq, hoco_seq);
#ifdef DEBUG_KMER_OVERLAP
        fprintf(stderr, "[DEBUG_KMER_OVERLAP::%s] consensus start position [%lu %lu%c %ld %lu]\n", 
                __func__, i, v[i]>>1, "+-"[v[i]&1], end_pos-beg_pos, scm[v[i]>>1].h);
#endif
        end_pos = beg_pos + w;
    }
    free(pos);
    kh_generic_destroy(h);

    assert(l >= 0 && (uint64_t) l == c_seq->l);

    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, 0x10(%rsp)
testq %rdx, %rdx
je 0x4d08
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movslq 0x18(%rdi), %rax
movq %rax, 0x28(%rsp)
callq 0x56cb
movq %rax, 0x8(%rsp)
leaq (,%r15,8), %rdi
callq 0x2310
movq %rax, %rbp
andq $0x0, (%rax)
pushq $0x1
popq %rbx
xorl %r13d, %r13d
cmpq %rbx, %r15
je 0x4c4b
movq -0x8(%r12,%rbx,8), %rdx
movq (%r12,%rbx,8), %r8
movq %rdx, %rsi
shlq $0x4, %rsi
andq $-0x20, %rsi
addq %r14, %rsi
movq %r8, %rcx
shlq $0x4, %rcx
andq $-0x20, %rcx
addq %r14, %rcx
andl $0x1, %edx
andl $0x1, %r8d
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %r9
callq 0x4d1c
cltq
addq %rax, %r13
movq %r13, (%rbp,%rbx,8)
incq %rbx
jmp 0x4bfc
movq %r14, 0x30(%rsp)
leaq -0x1(%r15), %rax
movq %rax, 0x20(%rsp)
xorl %ebx, %ebx
xorl %ecx, %ecx
xorl %eax, %eax
cmpq %r15, %rax
jae 0x4cc8
movq 0x18(%rsp), %rdi
leaq 0x1(%rax), %r13
cmpq %r15, %r13
jae 0x4c82
cmpq %rcx, 0x8(%rbp,%rax,8)
movq %r13, %rax
jle 0x4c69
leaq -0x1(%r13), %rax
jmp 0x4c8a
movq 0x20(%rsp), %rax
movq %r15, %r13
movq (%rbp,%rax,8), %r14
movq (%r12,%rax,8), %rdx
movq %rdx, %rsi
shlq $0x4, %rsi
andq $-0x20, %rsi
addq 0x30(%rsp), %rsi
andl $0x1, %edx
subq %r14, %rcx
movq 0x10(%rsp), %r8
movl 0x4(%rsp), %r9d
callq 0x4fa8
addq %rax, %rbx
addq 0x28(%rsp), %r14
movq %r14, %rcx
movq %r13, %rax
jmp 0x4c5f
movq %rbp, %rdi
callq 0x2060
movq 0x8(%rsp), %rdi
callq 0x56e0
testq %rbx, %rbx
js 0x4ce9
movq 0x10(%rsp), %rax
cmpq (%rax), %rbx
je 0x4d0a
leaq 0x14d83(%rip), %rdi     # 0x19a73
leaq 0x14d1c(%rip), %rsi     # 0x19a13
leaq 0x14d98(%rip), %rcx     # 0x19a96
movl $0x413, %edx            # imm = 0x413
callq 0x21d0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq