// File: /workspace/github_c_makefile_star2_O3/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), %rax
testq %rax, %rax
je 0xf85f
movq %rdi, %r15
xorl %esi, %esi
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %edi, %edi
xorl %edx, %edx
movq %r15, 0x8(%rsp)
movq 0x10(%r15), %r8
imulq $0x58, %rsi, %rcx
cmpq %rsi, (%r8,%rcx)
jne 0xfbf8
addq %rcx, %r8
movl 0x38(%r8), %ecx
testq %rcx, %rcx
je 0xf80e
movq %rsi, 0x18(%rsp)
movq %rdx, (%rsp)
movq %rcx, 0x10(%rsp)
movl %ecx, %eax
xorl %r13d, %r13d
movq %r8, 0x20(%rsp)
movq 0x50(%r8), %rcx
movq (%rcx,%r13,8), %rbp
movq (%r8), %r14
movq 0x40(%r8), %rcx
movl (%rcx,%r13,4), %r15d
cmpq %rbx, %r12
jne 0xf7c0
leaq (%r12,%r12), %rbx
testq %r12, %r12
movl $0x2, %eax
cmoveq %rax, %rbx
movq %rbx, %rsi
shlq $0x4, %rsi
callq 0x2350
movq 0x20(%rsp), %r8
movq %rax, %rdi
movl 0x38(%r8), %eax
shlq $0x20, %r14
leaq (,%r13,2), %rcx
orq %r14, %rcx
andl $0x1, %r15d
orq %rcx, %r15
leaq 0x1(%r12), %rcx
shlq $0x4, %r12
movq %rbp, 0x8(%rdi,%r12)
movq %r15, (%rdi,%r12)
incq %r13
movl %eax, %edx
movq %rcx, %r12
cmpq %rdx, %r13
jb 0xf780
movq 0x8(%rsp), %r15
movq (%r15), %rax
movq %rcx, %r12
movq (%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rcx
addq %rcx, %rdx
incq %rsi
cmpq %rax, %rsi
jb 0xf746
testq %r12, %r12
je 0xf861
movq %rdx, (%rsp)
leaq 0x409(%rip), %rcx       # 0xfc36
movl $0x10, %edx
movq %r12, %rsi
movq %rdi, %rbp
callq 0x20d0
movl $0x1, %r13d
movl $0x1, %edi
movl $0x28, %esi
callq 0x2250
movq %rax, %rbx
cmpq $0x1, %r12
jne 0xf86d
xorl %eax, %eax
jmp 0xf8b3
xorl %edi, %edi
callq 0x2060
xorl %ebx, %ebx
jmp 0xfbe6
movq 0x8(%rbp), %rcx
leaq 0x10(%rbp), %r14
movl $0x1, %r13d
xorl %eax, %eax
cmpq 0x8(%r14), %rcx
je 0xf8a4
movq %rax, %rdi
shlq $0x4, %rdi
addq %rbp, %rdi
movl %r13d, %esi
subl %eax, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xfc5f
movq 0x8(%r14), %rcx
movq %r13, %rax
incq %r13
addq $0x10, %r14
cmpq %r13, %r12
jne 0xf87d
movq %r12, %r13
movq %rax, %rdi
shlq $0x4, %rdi
addq %rbp, %rdi
subl %eax, %r13d
movl %r13d, %esi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xfc5f
movq %rbp, %rdi
callq 0x2060
movq (%rbx), %r15
movq 0x10(%rbx), %rdi
movq %r15, %rsi
shlq $0x5, %rsi
callq 0x2350
movq %rax, %r14
movq %rax, 0x10(%rbx)
movq %r15, 0x8(%rbx)
leaq (%r15,%r15), %rdi
callq 0x2310
movq %rax, 0x18(%rbx)
testq %r15, %r15
je 0xfbde
leaq 0x7(%r15), %rcx
andq $-0x8, %rcx
leaq -0x1(%r15), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x10638(%rip), %xmm1    # 0x1ff60
movdqa 0x10640(%rip), %xmm2    # 0x1ff70
movdqa 0x10648(%rip), %xmm3    # 0x1ff80
movdqa 0xfe90(%rip), %xmm4     # 0x1f7d0
xorl %edx, %edx
movdqa 0xfe96(%rip), %xmm5     # 0x1f7e0
pxor %xmm5, %xmm0
pcmpeqd %xmm6, %xmm6
movdqa 0x10636(%rip), %xmm7    # 0x1ff90
movdqa %xmm4, %xmm8
pxor %xmm5, %xmm8
movdqa %xmm8, %xmm10
pcmpgtd %xmm0, %xmm10
pshufd $0xa0, %xmm10, %xmm9    # xmm9 = xmm10[0,0,2,2]
pshuflw $0xe8, %xmm9, %xmm11    # xmm11 = xmm9[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm8
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm12    # xmm12 = xmm8[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm12
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
pshuflw $0xe8, %xmm10, %xmm11   # xmm11 = xmm10[0,2,2,3,4,5,6,7]
por %xmm12, %xmm11
pxor %xmm6, %xmm11
packssdw %xmm11, %xmm11
movd %xmm11, %esi
testb $0x1, %sil
je 0xf9bc
movw $0x1, (%rax,%rdx,2)
pand %xmm9, %xmm8
por %xmm10, %xmm8
packssdw %xmm8, %xmm8
pxor %xmm6, %xmm8
packssdw %xmm8, %xmm8
movd %xmm8, %esi
shrl $0x10, %esi
testb $0x1, %sil
je 0xf9ea
movw $0x1, 0x2(%rax,%rdx,2)
movdqa %xmm3, %xmm9
pxor %xmm5, %xmm9
movdqa %xmm9, %xmm10
pcmpgtd %xmm0, %xmm10
pshufd $0xa0, %xmm10, %xmm8    # xmm8 = xmm10[0,0,2,2]
pcmpeqd %xmm0, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
movdqa %xmm9, %xmm11
pand %xmm8, %xmm11
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
por %xmm10, %xmm11
packssdw %xmm11, %xmm11
pxor %xmm6, %xmm11
packssdw %xmm11, %xmm11
pextrw $0x2, %xmm11, %esi
testb $0x1, %sil
je 0xfa46
movw $0x1, 0x4(%rax,%rdx,2)
pshufhw $0x84, %xmm8, %xmm8     # xmm8 = xmm8[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pand %xmm8, %xmm9
pshufhw $0x84, %xmm10, %xmm8    # xmm8 = xmm10[0,1,2,3,4,5,4,6]
por %xmm9, %xmm8
pxor %xmm6, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x3, %xmm8, %esi
testb $0x1, %sil
je 0xfa7f
movw $0x1, 0x6(%rax,%rdx,2)
movdqa %xmm2, %xmm8
pxor %xmm5, %xmm8
movdqa %xmm8, %xmm10
pcmpgtd %xmm0, %xmm10
pshufd $0xa0, %xmm10, %xmm9    # xmm9 = xmm10[0,0,2,2]
pshuflw $0xe8, %xmm9, %xmm11    # xmm11 = xmm9[0,2,2,3,4,5,6,7]
pcmpeqd %xmm0, %xmm8
pshufd $0xf5, %xmm8, %xmm8     # xmm8 = xmm8[1,1,3,3]
pshuflw $0xe8, %xmm8, %xmm12    # xmm12 = xmm8[0,2,2,3,4,5,6,7]
pand %xmm11, %xmm12
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
pshuflw $0xe8, %xmm10, %xmm11   # xmm11 = xmm10[0,2,2,3,4,5,6,7]
por %xmm12, %xmm11
pxor %xmm6, %xmm11
packssdw %xmm11, %xmm11
pextrw $0x4, %xmm11, %esi
testb $0x1, %sil
je 0xfae3
movw $0x1, 0x8(%rax,%rdx,2)
pand %xmm9, %xmm8
por %xmm10, %xmm8
packssdw %xmm8, %xmm8
pxor %xmm6, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x5, %xmm8, %esi
testb $0x1, %sil
je 0xfb0f
movw $0x1, 0xa(%rax,%rdx,2)
movdqa %xmm1, %xmm9
pxor %xmm5, %xmm9
movdqa %xmm9, %xmm10
pcmpgtd %xmm0, %xmm10
pshufd $0xa0, %xmm10, %xmm8    # xmm8 = xmm10[0,0,2,2]
pcmpeqd %xmm0, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
movdqa %xmm9, %xmm11
pand %xmm8, %xmm11
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
por %xmm10, %xmm11
packssdw %xmm11, %xmm11
pxor %xmm6, %xmm11
packssdw %xmm11, %xmm11
pextrw $0x6, %xmm11, %esi
testb $0x1, %sil
je 0xfb6b
movw $0x1, 0xc(%rax,%rdx,2)
pshufhw $0x84, %xmm8, %xmm8     # xmm8 = xmm8[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pand %xmm8, %xmm9
pshufhw $0x84, %xmm10, %xmm8    # xmm8 = xmm10[0,1,2,3,4,5,4,6]
por %xmm9, %xmm8
pxor %xmm6, %xmm8
packssdw %xmm8, %xmm8
pextrw $0x7, %xmm8, %esi
testb $0x1, %sil
je 0xfba4
movw $0x1, 0xe(%rax,%rdx,2)
addq $0x8, %rdx
paddq %xmm7, %xmm4
paddq %xmm7, %xmm3
paddq %xmm7, %xmm2
paddq %xmm7, %xmm1
cmpq %rdx, %rcx
jne 0xf95a
addq $0x10, %r14
xorl %eax, %eax
movl (%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %rax
addq $0x20, %r14
decq %r15
jne 0xfbc7
jmp 0xfbe0
xorl %eax, %eax
cmpq %rax, (%rsp)
jne 0xfc17
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x106ea(%rip), %rdi     # 0x202e9
leaq 0x10450(%rip), %rsi     # 0x20056
leaq 0x106e8(%rip), %rcx     # 0x202f5
movl $0x57f, %edx            # imm = 0x57F
callq 0x21d0
leaq 0x1070b(%rip), %rdi     # 0x20329
leaq 0x10431(%rip), %rsi     # 0x20056
leaq 0x106c9(%rip), %rcx     # 0x202f5
movl $0x5a8, %edx            # imm = 0x5A8
callq 0x21d0