// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]oatk/syncmer.c
// Function: collect_syncmer_from_reads
syncmer_db_t *collect_syncmer_from_reads(sr_db_t *sr_db)
{
    size_t i, j;
    uint64_t n1, n2;
    sr_t *s;
    kvec_t(uint128_t) scm;
    kv_init(scm);
    n1 = 0;
    for (i = 0; i < sr_db->n; ++i) {
        s = &sr_db->a[i];
        assert(s->sid == i);
        n1 += s->n;
        for (j = 0; j < s->n; ++j) {
            uint128_t s1 = (uint128_t) s->k_mer[j] << 64 | ((s->sid << 32) | (j << 1) | (s->m_pos[j] & 1));
            kv_push(uint128_t, scm, s1);
        }
    }
    if (scm.n == 0) {
        kv_destroy(scm);
        return 0;
    }

    qsort(scm.a, scm.n, sizeof(uint128_t), uint128_cmpfunc);

    // pack syncmers by kmer hash
    // check hash collisions
    syncmer_db_t *scm_db;
    size_t last;
    uint64_t h64;
    MYMALLOC(scm_db, 1);
    syncmer_db_init(scm_db);
    h64 = (uint64_t) (scm.a[0] >> 64);
    for (i = 1, last = 0; i < scm.n; ++i) {
        if ((uint64_t) (scm.a[i] >> 64) != h64) {
            // process kmer cluster
            process_kmer_cluster(&scm.a[last], i - last, scm_db, sr_db);

            last = i;
            h64 = (uint64_t) (scm.a[i] >> 64);
        }
    }
    process_kmer_cluster(&scm.a[last], i - last, scm_db, sr_db);
    kv_destroy(scm);

    MYREALLOC(scm_db->a, scm_db->n);
    scm_db->m = scm_db->n;
    MYMALLOC(scm_db->c, scm_db->n);
    for (i = 0; i < scm_db->n; ++i) scm_db->c[i] = 1;

    n2 = 0;
    for (i = 0; i < scm_db->n; ++i) n2 += scm_db->a[i].cov;
    assert(n1 == n2);

    return scm_db;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %ebp, %ebp
xorl %r8d, %r8d
xorl %eax, %eax
xorl %esi, %esi
xorl %r9d, %r9d
movq %rdi, 0x8(%rsp)
cmpq (%rdi), %r9
movq %rsi, (%rsp)
jae 0xc207
movq %rbp, 0x20(%rsp)
movq 0x10(%rdi), %r10
imulq $0x58, %r9, %rcx
movq %r9, 0x18(%rsp)
cmpq %r9, (%r10,%rcx)
jne 0xc34d
addq %rcx, %r10
movl 0x38(%r10), %ecx
movq %rsi, %rbp
shlq $0x4, %rbp
xorl %r13d, %r13d
movq %rcx, 0x10(%rsp)
xorl %r12d, %r12d
movq %r10, 0x28(%rsp)
leaq (%rsi,%r12), %rdx
movl %ecx, %edi
cmpq %rdi, %r12
jae 0xc1e8
movq 0x50(%r10), %rdi
movq (%rdi,%r13,4), %r11
movq (%r10), %r15
movq 0x40(%r10), %rdi
movl (%rdi,%r13,2), %r14d
cmpq %rax, %rdx
jne 0xc1c1
leaq (%rax,%rax), %rbx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rbx
movq %rbx, %rsi
shlq $0x4, %rsi
movq %r8, %rdi
movq %r11, 0x30(%rsp)
callq 0x2350
movq 0x30(%rsp), %r11
movq 0x28(%rsp), %r10
movq (%rsp), %rsi
movq %rax, %r8
movl 0x38(%r10), %ecx
movq %rbx, %rax
shlq $0x20, %r15
orq %r13, %r15
andl $0x1, %r14d
orq %r15, %r14
leaq (%r8,%rbp), %rdx
movq %r11, 0x8(%rdx,%r13,8)
movq %r14, (%rdx,%r13,8)
incq %r12
addq $0x2, %r13
jmp 0xc164
movq 0x20(%rsp), %rbp
addq 0x10(%rsp), %rbp
movq 0x18(%rsp), %r9
incq %r9
movq %rdx, %rsi
movq 0x8(%rsp), %rdi
jmp 0xc11d
testq %rsi, %rsi
je 0xc330
movq %rdi, %rbx
leaq 0x152(%rip), %rcx       # 0xc36c
pushq $0x10
popq %rdx
movq %r8, %rdi
movq %r8, %r14
callq 0x20d0
pushq $0x1
popq %r13
pushq $0x28
popq %rsi
movq %r13, %rdi
callq 0x2250
movq (%rsp), %rdx
movq %r14, %r8
movq %rax, %r12
movq 0x8(%r14), %rcx
leaq 0x10(%r14), %r15
xorl %eax, %eax
cmpq %rdx, %r13
jae 0xc287
cmpq 0x8(%r15), %rcx
je 0xc27e
movq %rax, %rdi
shlq $0x4, %rdi
addq %r8, %rdi
movl %r13d, %esi
subl %eax, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xc395
movq (%rsp), %rdx
movq %r14, %r8
movq 0x8(%r15), %rcx
movq %r13, %rax
incq %r13
addq $0x10, %r15
jmp 0xc24b
movq %rax, %rdi
shlq $0x4, %rdi
addq %r8, %rdi
subl %eax, %r13d
movl %r13d, %esi
movq %r12, %rdx
movq %rbx, %rcx
movq %r8, %rbx
callq 0xc395
movq %rbx, %rdi
callq 0x2060
movq (%r12), %r14
movq 0x10(%r12), %rdi
movq %r14, %rsi
shlq $0x5, %rsi
callq 0x2350
movq %rax, %rbx
movq %rax, 0x10(%r12)
movq %r14, 0x8(%r12)
leaq (%r14,%r14), %rdi
callq 0x2310
movq %rax, 0x18(%r12)
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0xc2ef
movw $0x1, (%rax,%rcx,2)
incq %rcx
jmp 0xc2df
addq $0x10, %rbx
xorl %eax, %eax
subq $0x1, %r14
jb 0xc30c
movl (%rbx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %rax
addq $0x20, %rbx
jmp 0xc2f5
cmpq %rax, %rbp
je 0xc33b
leaq 0xdfc9(%rip), %rdi      # 0x1a2e1
leaq 0xdcef(%rip), %rsi      # 0x1a00e
leaq 0xdf87(%rip), %rcx      # 0x1a2ad
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x21d0
movq %r8, %rdi
callq 0x2060
xorl %r12d, %r12d
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdf4d(%rip), %rdi      # 0x1a2a1
leaq 0xdcb3(%rip), %rsi      # 0x1a00e
leaq 0xdf4b(%rip), %rcx      # 0x1a2ad
movl $0x57f, %edx            # imm = 0x57F
callq 0x21d0