// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/syncmer.c
// Function: fputs_kmer
static void fputs_kmer(uint8_t *s, uint32_t p, int w, FILE *fo)
{
    int i, j, rev, res, p0, p1, b, c;
    uint8_t *key;

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

    // 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
    MYMALLOC(key, b);
    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];

    for (i = 0; i < p1 - p0 + 1; ++i)
        // fputc(char_nt4_table[(key[i / 4] >> (3 - i % 4) * 2) & 3], fo);
        fputc(char_nt4_table[(key[i/4]>>(((i&3)^3)<<1)) & 3], fo);
    free(key);

    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl -0xc(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %eax
shrl %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %eax
addl -0x10(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x13fff
movl -0x30(%rbp), %eax
andl $0x3, %eax
xorl $0x3, %eax
shll %eax
movl %eax, -0x44(%rbp)
jmp 0x1400a
movl -0x2c(%rbp), %eax
andl $0x3, %eax
shll %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x30(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0x48(%rbp)
movl -0x2c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movslq -0x34(%rbp), %rdi
shlq $0x0, %rdi
callq 0x2320
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x2c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cltq
addq %rax, %rsi
movslq -0x34(%rbp), %rdx
callq 0x22c0
cmpl $0x0, -0x24(%rbp)
je 0x14116
movl $0x0, -0x1c(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x140e9
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x202d2(%rip), %rax     # 0x34380
movb (%rax,%rcx), %dl
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movslq -0x38(%rbp), %rcx
leaq 0x202b9(%rip), %rax     # 0x34380
movb (%rax,%rcx), %dl
movq -0x40(%rbp), %rax
movslq -0x20(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x14082
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x14114
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2027a(%rip), %rax     # 0x34380
movb (%rax,%rcx), %dl
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x14116
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1417d
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movq %rdx, -0x50(%rbp)
movzbl (%rax,%rdx), %edx
shll %cl, %edx
movq -0x50(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %esi
movl $0x8, %ecx
subl -0x28(%rbp), %ecx
sarl %cl, %esi
movq -0x40(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
orl %esi, %edx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1411d
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq %rdx, -0x58(%rbp)
movzbl (%rax,%rdx), %edx
shll %cl, %edx
movq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x10(%rbp), %eax
subl $0x1, %eax
movl $0x4, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x10(%rbp), %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0x202be(%rip), %rax     # 0x34480
movzbl (%rax,%rcx), %esi
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
andl %esi, %edx
movb %dl, (%rax,%rcx)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0x30(%rbp), %ecx
subl -0x2c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x14245
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x1c(%rbp), %ecx
andl $0x3, %ecx
xorl $0x3, %ecx
shll %ecx
sarl %cl, %eax
andl $0x3, %eax
movslq %eax, %rcx
leaq 0x19cf3(%rip), %rax     # 0x2df20
movsbl (%rax,%rcx), %edi
movq -0x18(%rbp), %rsi
callq 0x2220
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x141e3
movq -0x40(%rbp), %rdi
callq 0x2060
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)