// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/syncmer.c
// Function: kmer_hash64
static uint64_t kmer_hash64(uint8_t *s, uint32_t p, int w, uint8_t *key)
#endif
{
    uint64_t h64;
    int i, j, rev, res, p0, p1, b, c;

    rev = p & 1, p >>= 1;
    p0 = p, p1 = p + w - 1;

    // assert(p0 >= 0 && p1 < l);

    // res = rev? 6 - p1 % 4 * 2 : p0 % 4 * 2; // shift bits
    res = rev? ((p1&3)^3)<<1 : (p0&3)<<1;
    b = p1 / 4 - p0 / 4 + 1; // number bytes holding syncmer sequence
    memcpy(key, s + p0 / 4, b);
    // key[b-1] needs bit shift
    // when the last byte is partially filled
    // if (l < (p1 / 4 + 1) * 4) key[b-1] <<= 8 - l % 4 * 2;
    // do reverse complementary
    if (rev) {
        for (i = 0, j = b - 1; i < j; ++i, --j) {
            c = key[i];
            key[i] = comp_seq8_table[key[j]];
            key[j] = comp_seq8_table[c];
        }
        if (i == j) key[i] = comp_seq8_table[key[i]];
    }
    // do bit shift to align syncmer bytes
    for (i = 0; i < b-1; ++i) {
        key[i] <<= res;
        key[i] |= key[i+1] >> (8-res);
    }
    key[b-1] <<= res;

    // real bytes
    b = (w - 1) / 4 + 1;
    // mask the lower bits
    key[b-1] &= lmask[w&3];

    h64 = MurmurHash64A(key, b, murmur3_seed);

#ifdef DEBUG_KMER_EXTRACTION
    fprintf(stderr, "[DEBUG_KMER_EXTRACTION::%s] sid:%lu p0:%d p1:%d rev:%d bit:%d hash:%lu ", __func__, sid, p0, p1, rev, b, h64);
    for (i = 0; i < p1 - p0 + 1; ++i)
        // fputc(char_nt4_table[(key[i / 4] >> (3 - i % 4) * 2) & 3], stderr);
        fputc(char_nt4_table[(key[i/4]>>(((i&3)^3)<<1)) & 3], stderr);

    fputc('\n', stderr);
#endif

    return h64;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %r14d
movl %esi, %r15d
movl %esi, %eax
shrl %eax
leal (%r14,%rax), %r13d
leal (%r14,%rax), %ecx
decl %ecx
negl %r13d
addl %r13d, %r13d
andl $0x6, %r13d
movl %esi, %ebp
andl $0x6, %ebp
leal (%r14,%rax), %r12d
addl $0x2, %r12d
testl %ecx, %ecx
cmovnsl %ecx, %r12d
sarl $0x2, %r12d
shrl $0x3, %esi
subl %esi, %r12d
leal 0x1(%r12), %eax
addq %rdi, %rsi
movslq %eax, %rdx
movq %rbx, %rdi
callq 0x22c0
testb $0x1, %r15b
cmovnel %r13d, %ebp
je 0x11edc
testl %r12d, %r12d
jle 0x11ec0
movl %r12d, %ecx
xorl %eax, %eax
leaq 0xc6db(%rip), %rdx      # 0x1e570
movq %rcx, %rsi
movzbl (%rbx,%rax), %edi
movzbl (%rbx,%rsi), %r8d
movb (%r8,%rdx), %r8b
movb %r8b, (%rbx,%rax)
movb (%rdi,%rdx), %dil
movb %dil, (%rbx,%rsi)
incq %rax
decq %rsi
cmpq %rsi, %rax
jl 0x11e98
subl %eax, %ecx
jmp 0x11ec5
xorl %eax, %eax
movl %r12d, %ecx
cmpl %ecx, %eax
jne 0x11edc
movl %eax, %eax
movzbl (%rbx,%rax), %ecx
leaq 0xc69a(%rip), %rdx      # 0x1e570
movb (%rcx,%rdx), %cl
movb %cl, (%rbx,%rax)
testl %r12d, %r12d
jle 0x11f13
movl $0x8, %eax
subl %ebp, %eax
movl %r12d, %edx
xorl %esi, %esi
movzbl (%rbx,%rsi), %edi
movl %ebp, %ecx
shll %cl, %edi
movzbl 0x1(%rbx,%rsi), %r8d
movl %eax, %ecx
shrl %cl, %r8d
orl %edi, %r8d
movb %r8b, (%rbx,%rsi)
leaq 0x1(%rsi), %rcx
movq %rcx, %rsi
cmpq %rcx, %rdx
jne 0x11eed
movslq %r12d, %rax
movzbl (%rbx,%rax), %edx
movl %ebp, %ecx
shll %cl, %edx
movb %dl, (%rbx,%rax)
leal -0x1(%r14), %eax
shrl $0x2, %eax
andl $0x3, %r14d
leaq 0xc73d(%rip), %rcx      # 0x1e670
movb (%r14,%rcx), %cl
andb %cl, (%rbx,%rax)
movl %eax, %esi
incl %esi
movl $0x4d2, %edx            # imm = 0x4D2
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcd50