// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, %r14
cmpq $0x0, (%rdi)
je 0xefdc
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %eax, %eax
xorl %edi, %edi
xorl %ebp, %ebp
movq %r14, 0x8(%rsp)
movq 0x10(%r14), %r13
movq %rcx, %rdx
imulq $0x58, %rcx, %rcx
movq %rdx, 0x20(%rsp)
cmpq %rdx, (%r13,%rcx)
jne 0xf134
movq %rbp, 0x18(%rsp)
addq %rcx, %r13
movl 0x38(%r13), %ecx
movq %rcx, 0x10(%rsp)
testq %rcx, %rcx
je 0xefb4
xorl %ebp, %ebp
movq 0x50(%r13), %rcx
movq (%rcx,%rbp,8), %rdx
movq (%r13), %rbx
movq 0x40(%r13), %rcx
movl (%rcx,%rbp,4), %r14d
cmpq %rax, %r12
jne 0xef7b
leaq (%rax,%rax), %r15
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r15
movq %r15, %rsi
shlq $0x4, %rsi
movq %rdx, (%rsp)
callq 0x2360
movq (%rsp), %rdx
movq %rax, %rdi
movq %r15, %rax
shlq $0x20, %rbx
leaq (,%rbp,2), %rcx
orq %rbx, %rcx
andl $0x1, %r14d
orq %rcx, %r14
leaq 0x1(%r12), %rbx
shlq $0x4, %r12
movq %rdx, 0x8(%rdi,%r12)
movq %r14, (%rdi,%r12)
incq %rbp
movl 0x38(%r13), %ecx
movq %rbx, %r12
cmpq %rcx, %rbp
jb 0xef38
jmp 0xefb7
movq %r12, %rbx
movq 0x18(%rsp), %rbp
addq 0x10(%rsp), %rbp
movq 0x20(%rsp), %rcx
incq %rcx
movq %rbx, %r12
movq 0x8(%rsp), %r14
cmpq (%r14), %rcx
jb 0xef05
jmp 0xefe2
xorl %ebp, %ebp
xorl %edi, %edi
xorl %ebx, %ebx
testq %rbx, %rbx
je 0xf035
leaq 0x184(%rip), %rcx       # 0xf172
movl $0x10, %edx
movq %rdi, (%rsp)
movq %rbx, %rsi
callq 0x20d0
movl $0x28, %edi
callq 0x2320
movq %rax, %r15
testq %rax, %rax
je 0xf025
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r15)
movups %xmm0, (%r15)
movq $0x0, 0x20(%r15)
cmpq $0x1, %rbx
jne 0xf042
movl $0x1, %r12d
xorl %eax, %eax
jmp 0xf098
callq 0x2060
xorl %r15d, %r15d
jmp 0xf122
cmpq $0x3, %rbx
movl $0x2, %r13d
cmovaeq %rbx, %r13
movq (%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0x10(%rax), %rbx
movl $0x1, %r12d
xorl %eax, %eax
cmpq 0x8(%rbx), %rcx
je 0xf08c
movq %rax, %rdi
shlq $0x4, %rdi
addq (%rsp), %rdi
movl %r12d, %esi
subl %eax, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf19b
movq 0x8(%rbx), %rcx
movq %r12, %rax
incq %r12
addq $0x10, %rbx
cmpq %r12, %r13
jne 0xf064
movq %rax, %rdi
shlq $0x4, %rdi
movq (%rsp), %rbx
addq %rbx, %rdi
subl %eax, %r12d
movl %r12d, %esi
movq %r15, %rdx
movq %r14, %rcx
callq 0xf19b
movq %rbx, %rdi
callq 0x2060
movq (%r15), %r14
movq 0x10(%r15), %rdi
movq %r14, %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rbx
movq %rax, 0x10(%r15)
movq %r14, 0x8(%r15)
leaq (%r14,%r14), %rdi
callq 0x2320
movq %rax, 0x18(%r15)
testq %r14, %r14
je 0xf11b
xorl %ecx, %ecx
movw $0x1, (%rax,%rcx,2)
incq %rcx
cmpq %rcx, %r14
jne 0xf0f1
addq $0x10, %rbx
xorl %eax, %eax
movl (%rbx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %rax
addq $0x20, %rbx
decq %r14
jne 0xf105
jmp 0xf11d
xorl %eax, %eax
cmpq %rax, %rbp
jne 0xf153
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf11e(%rip), %rdi      # 0x1e259
leaq 0xee84(%rip), %rsi      # 0x1dfc6
leaq 0xf11c(%rip), %rcx      # 0x1e265
movl $0x57f, %edx            # imm = 0x57F
callq 0x21d0
leaq 0xf13f(%rip), %rdi      # 0x1e299
leaq 0xee65(%rip), %rsi      # 0x1dfc6
leaq 0xf0fd(%rip), %rcx      # 0x1e265
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x21d0