// File: /workspace/github_c_makefile_star2_O3/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), %ecx
decl %ecx
movl %ecx, %r13d
notl %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 0x22b0
testb $0x1, %r15b
cmovnel %r13d, %ebp
je 0x12972
testl %r12d, %r12d
jle 0x12956
movl %r12d, %eax
xorl %ecx, %ecx
leaq 0xdcd5(%rip), %rdx      # 0x20600
movq %rax, %rsi
movzbl (%rbx,%rcx), %edi
movzbl (%rbx,%rsi), %r8d
movb (%r8,%rdx), %r8b
movb %r8b, (%rbx,%rcx)
movb (%rdi,%rdx), %dil
movb %dil, (%rbx,%rsi)
incq %rcx
decq %rsi
cmpq %rsi, %rcx
jl 0x1292e
subl %ecx, %eax
jmp 0x1295b
xorl %ecx, %ecx
movl %r12d, %eax
cmpl %eax, %ecx
jne 0x12972
movl %eax, %eax
movzbl (%rbx,%rax), %ecx
leaq 0xdc94(%rip), %rdx      # 0x20600
movb (%rcx,%rdx), %cl
movb %cl, (%rbx,%rax)
leal -0x1(%r14), %edi
testl %r12d, %r12d
jle 0x129a7
movl %r12d, %edx
movb (%rbx), %cl
xorl %esi, %esi
movzbl %cl, %eax
movzbl 0x1(%rbx,%rsi), %r8d
shll $0x8, %eax
orl %r8d, %eax
movl %ebp, %ecx
shll %cl, %eax
movb %ah, (%rbx,%rsi)
leaq 0x1(%rsi), %rax
movl %r8d, %ecx
movq %rax, %rsi
cmpq %rax, %rdx
jne 0x12982
movslq %r12d, %rax
movzbl (%rbx,%rax), %edx
movl %ebp, %ecx
shll %cl, %edx
movb %dl, (%rbx,%rax)
shrl $0x2, %edi
movl %edi, %esi
andl $0x3, %r14d
leaq 0xdd3b(%rip), %rax      # 0x20700
movb (%r14,%rax), %al
andb %al, (%rbx,%rdi)
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 0xd5a8