// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Process_Read.cpp
// Function: ha_encode_base(unsigned char*, char*, unsigned long, N_t*, unsigned long)
void ha_encode_base(uint8_t* dest, char* src, uint64_t src_l, N_t *nn, uint64_t nn_offset)
{
    uint64_t i = 0;
    uint64_t dest_i = 0;
    uint8_t tmp = 0;
    uint8_t c = 0;

    while (i + 4 <= src_l) {
        tmp = 0;
		// fprintf(stderr, "i->%lu, src_l->%ld, src[i]->%c, (uint8_t)src[i]->%u\n", i, src_l, src[i], (uint8_t)src[i]);
        c = seq_nt6_table[(uint8_t)src[i]];
		if (c >= 4) {
			c = 0; kv_push(uint32_t, *nn, i+nn_offset);
		}
		i++;
        tmp = tmp | (c<<6);

        c = seq_nt6_table[(uint8_t)src[i]];
		if (c >= 4) {
			c = 0; kv_push(uint32_t, *nn, i+nn_offset);
		}
		i++;
        tmp = tmp | (c<<4);

        c = seq_nt6_table[(uint8_t)src[i]];
		if (c >= 4) {
			c = 0; kv_push(uint32_t, *nn, i+nn_offset);
		}
		i++;
        tmp = tmp | (c<<2);

        c = seq_nt6_table[(uint8_t)src[i]];
		if (c >= 4) {
			c = 0; kv_push(uint32_t, *nn, i+nn_offset);
		}
		i++;
        tmp = tmp | c;

        dest[dest_i] = tmp;

        dest_i++;
    }

    //at most 3 bases here
    uint64_t shift = 6;
    if (i < src_l) {
        tmp = 0;
        while (i < src_l) {
            c = seq_nt6_table[(uint8_t)src[i]];
			if (c >= 4) {
				c = 0; kv_push(uint32_t, *nn, i+nn_offset);
			}
			i++;
            tmp = tmp | (c << shift);
            shift = shift -2;
        }
        
        dest[dest_i] = tmp;
        dest_i++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rdx, 0x18(%rsp)
movq %rdi, %r12
xorl %ebx, %ebx
leaq 0x24b830(%rip), %r9     # 0x253630
movq %r8, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
leaq 0x4(%rbx), %rbp
cmpq 0x18(%rsp), %rbp
ja 0x7fdb
movzbl (%rsi,%rbx), %eax
movb (%rax,%r9), %r15b
cmpb $0x4, %r15b
jb 0x7e7c
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x7e6a
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
leaq 0x24b7d7(%rip), %r9     # 0x253630
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leal (%r8,%rbx), %edx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x8(%r14)
movl %edx, (%rax,%rcx,4)
xorl %r15d, %r15d
movq %r12, 0x20(%rsp)
movzbl 0x1(%rsi,%rbx), %eax
movb (%rax,%r9), %r12b
cmpb $0x4, %r12b
jb 0x7ee7
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x7ed3
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
leaq 0x24b76e(%rip), %r9     # 0x253630
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leal (%r8,%rbx), %edx
incl %edx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x8(%r14)
movl %edx, (%rax,%rcx,4)
xorl %r12d, %r12d
movzbl 0x2(%rsi,%rbx), %eax
movb (%rax,%r9), %r13b
cmpb $0x4, %r13b
jb 0x7f4e
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x7f39
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
leaq 0x24b708(%rip), %r9     # 0x253630
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leal (%r8,%rbx), %edx
addl $0x2, %edx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x8(%r14)
movl %edx, (%rax,%rcx,4)
xorl %r13d, %r13d
movzbl 0x3(%rsi,%rbx), %eax
movb (%rax,%r9), %al
cmpb $0x4, %al
jb 0x7fb2
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x7f9e
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
leaq 0x24b6a3(%rip), %r9     # 0x253630
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leal (%r8,%rbx), %edx
addl $0x3, %edx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x8(%r14)
movl %edx, (%rax,%rcx,4)
xorl %eax, %eax
shlb $0x6, %r15b
shlb $0x4, %r12b
orb %r15b, %r12b
shlb $0x2, %r13b
orb %r12b, %r13b
orb %al, %r13b
movq 0x20(%rsp), %r12
movb %r13b, (%r12)
incq %r12
movq %rbp, %rbx
jmp 0x7e0a
cmpq 0x18(%rsp), %rbx
jae 0x8069
pushq $0x6
popq %rbp
xorl %r15d, %r15d
cmpq 0x18(%rsp), %rbx
jae 0x8065
movzbl (%rsi,%rbx), %eax
movb (%rax,%r9), %al
cmpb $0x4, %al
jb 0x8053
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x8042
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
leaq 0x24b5ff(%rip), %r9     # 0x253630
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %r8
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leal (%r8,%rbx), %edx
leaq 0x1(%rcx), %rdi
movq %rdi, 0x8(%r14)
movl %edx, (%rax,%rcx,4)
xorl %eax, %eax
movzbl %al, %eax
movl %ebp, %ecx
shll %cl, %eax
incq %rbx
orb %al, %r15b
addl $-0x2, %ebp
jmp 0x7fec
movb %r15b, (%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq