// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6047
movq $0x0, -0x8(%rbp)
jmp 0x628b
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x5c(%rbp)
callq 0x7630
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2320
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq $0x0, (%rax)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x6145
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
subq $0x1, %rdx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
andq $0x1, %rdx
movq -0x80(%rbp), %rcx
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %r8
movq (%rax,%r8,8), %r8
andq $0x1, %r8
movq -0x68(%rbp), %r9
callq 0x62a0
movq -0x88(%rbp), %rdx
cltq
addq %rax, %rdx
movq -0x70(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x607e
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x623c
jmp 0x6175
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x89(%rbp)
jae 0x61a5
movq -0x70(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rax
cmpq -0x50(%rbp), %rax
setle %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x61b1
jmp 0x61bf
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6175
movq -0x70(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
shlq $0x5, %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
movl %eax, %edx
movq -0x50(%rbp), %rcx
subq -0x48(%rbp), %rcx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
callq 0x6900
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movslq -0x5c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6165
movq -0x70(%rbp), %rdi
callq 0x2060
movq -0x68(%rbp), %rdi
callq 0x7640
cmpq $0x0, -0x58(%rbp)
jl 0x6264
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x6264
jmp 0x6283
leaq 0x277a8(%rip), %rdi     # 0x2da13
leaq 0x27741(%rip), %rsi     # 0x2d9b3
movl $0x413, %edx            # imm = 0x413
leaq 0x277b8(%rip), %rcx     # 0x2da36
callq 0x21e0
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)