// File: chhylp123[P]hifiasm/Process_Read.cpp
// Function: ha_compress_base(unsigned char*, char*, unsigned long, unsigned long**, unsigned long)
void ha_compress_base(uint8_t* dest, char* src, uint64_t src_l, uint64_t** N_site_lis, uint64_t N_site_occ)
{
	///N_site_lis saves the pos of all Ns in this read
	///N_site_lis[0] is the number of Ns
	free((*N_site_lis));
	if (N_site_occ)
	{
		(*N_site_lis) = (uint64_t*)malloc(sizeof(uint64_t)*(N_site_occ + 1));
		(*N_site_lis)[0] = N_site_occ;
	}
	else
	{
		(*N_site_lis) = NULL;
	}

	uint64_t i = 0;
	uint64_t N_site_i = 1;
	uint64_t dest_i = 0;
	uint8_t tmp = 0;
	uint8_t c = 0;

	while (i + 4 <= src_l)
	{
		tmp = 0;

		COMPRESS_BASE;
		tmp = tmp | (c<<6);

		COMPRESS_BASE;
		tmp = tmp | (c<<4);

		COMPRESS_BASE;
		tmp = tmp | (c<<2);

		COMPRESS_BASE;
		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)
		{
			COMPRESS_BASE;
			tmp = tmp | (c << shift);
			shift = shift -2;
		}
		
		dest[dest_i] = tmp;
		dest_i++;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x2210
cmpq $0x0, -0x28(%rbp)
je 0xa76a
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
shlq $0x3, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rcx, (%rax)
jmp 0xa775
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x30(%rbp)
movq $0x1, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rax
addq $0x4, %rax
cmpq -0x18(%rbp), %rax
ja 0xa953
movb $0x0, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3b9e90(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x4, %eax
jl 0xa7f2
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %ecx
shll $0x6, %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3b9e2d(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x4, %eax
jl 0xa855
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3b9dca(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x4, %eax
jl 0xa8b8
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %ecx
shll $0x2, %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3b9d67(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x4, %eax
jl 0xa91b
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %dl
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xa795
movq $0x6, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xaa07
movb $0x0, -0x41(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xa9ed
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x3b9cc4(%rip), %rax    # 0x3c4650
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movzbl -0x42(%rbp), %eax
cmpl $0x4, %eax
jl 0xa9be
movb $0x0, -0x42(%rbp)
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movzbl -0x41(%rbp), %eax
movzbl -0x42(%rbp), %edx
movq -0x50(%rbp), %rcx
shll %cl, %edx
movl %edx, %ecx
orl %ecx, %eax
movb %al, -0x41(%rbp)
movq -0x50(%rbp), %rax
subq $0x2, %rax
movq %rax, -0x50(%rbp)
jmp 0xa96d
movb -0x41(%rbp), %dl
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)