// File: chhylp123[P]hifiasm/Process_Read.cpp
// Function: ha_compress_qual(unsigned char*, char*, unsigned long, unsigned long, unsigned long)
void ha_compress_qual(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitn, uint64_t sc_off)
{

	uint64_t i = 0, k, bit_r = 8/bitn, dest_i = 0, bitu = (1<<bitn);
	uint8_t tmp = 0, c = 0, sc;

	for (i = 0; i + bit_r <= src_l;) {
		for (k = tmp = 0; k < bit_r; k++) {
			for (c = 0, sc = ((uint8_t)src[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
			if(c >= bitu) c = bitu - 1;
			tmp <<= bitn; tmp |= c; i++;
		}
		dest[dest_i++] = tmp;
	}

	if(i < src_l) {
		for (k = tmp = 0; i < src_l; k++) {
			for (c = 0, sc = ((uint8_t)src[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
			if(c >= bitu) c = bitu - 1;
			tmp <<= bitn; tmp |= c; i++;
		}
		 
		dest[dest_i++] = (tmp<<(8-(bitn*k)));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x8, %eax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x20(%rbp)
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq %rax, -0x50(%rbp)
movb $0x0, -0x51(%rbp)
movb $0x0, -0x52(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0xadbd
movb $0x0, -0x51(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0xad9f
movb $0x0, -0x52(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
subq -0x28(%rbp), %rax
movb %al, -0x53(%rbp)
movzbl -0x52(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x50(%rbp), %rcx
movb %al, -0x54(%rbp)
jae 0xad3e
movzbl -0x52(%rbp), %eax
movl %eax, %ecx
leaq 0x376bd3(%rip), %rax    # 0x381900
movq (%rax,%rcx,8), %rax
movzbl -0x53(%rbp), %ecx
cmpq %rcx, %rax
setb %al
movb %al, -0x54(%rbp)
movb -0x54(%rbp), %al
testb $0x1, %al
jne 0xad47
jmp 0xad53
jmp 0xad49
movb -0x52(%rbp), %al
addb $0x1, %al
movb %al, -0x52(%rbp)
jmp 0xad0f
movzbl -0x52(%rbp), %eax
cmpq -0x50(%rbp), %rax
jb 0xad68
movq -0x50(%rbp), %rax
subq $0x1, %rax
movb %al, -0x52(%rbp)
movq -0x20(%rbp), %rcx
movzbl -0x51(%rbp), %eax
shll %cl, %eax
movb %al, -0x51(%rbp)
movzbl -0x52(%rbp), %ecx
movzbl -0x51(%rbp), %eax
orl %ecx, %eax
movb %al, -0x51(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xacea
movb -0x51(%rbp), %dl
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movb %dl, (%rax,%rcx)
jmp 0xaccc
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xaebb
movb $0x0, -0x51(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0xae8c
movb $0x0, -0x52(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
subq -0x28(%rbp), %rax
movb %al, -0x53(%rbp)
movzbl -0x52(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x50(%rbp), %rcx
movb %al, -0x55(%rbp)
jae 0xae2b
movzbl -0x52(%rbp), %eax
movl %eax, %ecx
leaq 0x376ae6(%rip), %rax    # 0x381900
movq (%rax,%rcx,8), %rax
movzbl -0x53(%rbp), %ecx
cmpq %rcx, %rax
setb %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0xae34
jmp 0xae40
jmp 0xae36
movb -0x52(%rbp), %al
addb $0x1, %al
movb %al, -0x52(%rbp)
jmp 0xadfc
movzbl -0x52(%rbp), %eax
cmpq -0x50(%rbp), %rax
jb 0xae55
movq -0x50(%rbp), %rax
subq $0x1, %rax
movb %al, -0x52(%rbp)
movq -0x20(%rbp), %rcx
movzbl -0x51(%rbp), %eax
shll %cl, %eax
movb %al, -0x51(%rbp)
movzbl -0x52(%rbp), %ecx
movzbl -0x51(%rbp), %eax
orl %ecx, %eax
movb %al, -0x51(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xadd7
movzbl -0x51(%rbp), %eax
movq -0x20(%rbp), %rdx
imulq -0x38(%rbp), %rdx
movl $0x8, %ecx
subq %rdx, %rcx
shll %cl, %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x48(%rbp)
movb %dl, (%rax,%rcx)
popq %rbp
retq
nopl (%rax)