// File: /workspace/github_c_makefile_star2_O3/aokad[P]sequeeze/seqtk.c
// Function: binning
int binning(gzFile fp, char *bin_quality)
{
	kseq_t *seq, last;
	uint64_t n = 1;

	char base_quality[] = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ";
	//char bin_quality[] = "!!''''''''000000000077777<<<<<BBBBBFFFFFII";

	seq = kseq_init(fp);

	memset(&last, 0, sizeof(kseq_t));
	while (kseq_read(seq) >= 0) {
		int i;
		for (i = 0; i < seq->qual.l; ++i) {
			char *p = strchr(base_quality, seq->qual.s[i]);
			int pos = 42;
			if (p != NULL) {
				pos = p - base_quality;
			}
			seq->qual.s[i] = bin_quality[pos];
		}
		if (last.name.l) {
			kstring_t *p = &last.name, *q = &seq->name;
			int is_diff;
			if (p->l == q->l) {
				int l = (p->l > 2 && p->s[p->l-2] == '/' && q->s[q->l-2] == '/' && isdigit(p->s[p->l-1]) && isdigit(q->s[q->l-1]))? p->l - 2 : p->l;
				is_diff = strncmp(p->s, q->s, l);
			} else is_diff = 1;
			if (!is_diff) {
				stk_printseq(&last, 0);
				stk_printseq(seq,   0);
				last.name.l = 0;
				++n;
			} else {
				stk_printseq(&last, 0);
				++n;
				cpy_kseq(&last, seq);
			}
		} else cpy_kseq(&last, seq);
	}
	if (last.name.l) stk_printseq(&last, 0);

	kseq_destroy(seq);
	gzclose(fp);
	// free last!
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r15
movq %rdi, %r14
movups 0x326c(%rip), %xmm0     # 0xc98b
movups %xmm0, 0xab(%rsp)
movaps 0x3252(%rip), %xmm0     # 0xc980
movaps %xmm0, 0xa0(%rsp)
movaps 0x3233(%rip), %xmm0     # 0xc970
movaps %xmm0, 0x90(%rsp)
callq 0x3edd
movq %rax, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rax, %rdi
callq 0x3f27
testl %eax, %eax
js 0x9a61
movq %r14, 0x18(%rsp)
leaq 0x90(%rsp), %r13
movl $0x2a, %r12d
movq %rbx, (%rsp)
movq 0x48(%rbx), %rbp
testq %rbp, %rbp
je 0x97dd
movq (%rsp), %rax
movq 0x58(%rax), %rbx
xorl %r14d, %r14d
movsbl (%rbx,%r14), %esi
movq %r13, %rdi
callq 0x20e0
movl %eax, %ecx
subl %r13d, %ecx
testq %rax, %rax
movslq %ecx, %rax
cmoveq %r12, %rax
movb (%r15,%rax), %al
movb %al, (%rbx,%r14)
incq %r14
cmpq %r14, %rbp
ja 0x97b1
movq 0x20(%rsp), %r14
testq %r14, %r14
je 0x98d6
movq 0x30(%rsp), %rsi
movq (%rsp), %rax
cmpq (%rax), %r14
jne 0x9842
cmpq $0x2, %r14
jbe 0x984c
cmpb $0x2f, -0x2(%rsi,%r14)
movq (%rsp), %rax
movq 0x10(%rax), %rbx
jne 0x9854
cmpb $0x2f, -0x2(%rbx,%r14)
jne 0x9854
movq %rbx, 0x8(%rsp)
movq %rsi, %rbx
callq 0x2290
movq %rbx, %rsi
movq (%rax), %rax
movsbq -0x1(%rbx,%r14), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x99cf
movq 0x8(%rsp), %rbx
jmp 0x9854
movq %rsi, %rbx
movq 0x68(%rsp), %r14
jmp 0x9879
movq (%rsp), %rax
movq 0x10(%rax), %rbx
movslq %r14d, %rdx
movq %rsi, %rdi
movq %rsi, 0x10(%rsp)
movq %rbx, %rsi
callq 0x2070
movq 0x68(%rsp), %r14
testl %eax, %eax
je 0x98fc
movq 0x10(%rsp), %rbx
xorl %eax, %eax
testq %r14, %r14
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x672c(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %r14, %r14
je 0x98d6
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
leaq 0x20(%rsp), %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x71ec
movq %rbx, %rdi
callq 0x3f27
testl %eax, %eax
jns 0x979d
jmp 0x99ec
movq %rbx, 0x8(%rsp)
xorl %eax, %eax
testq %r14, %r14
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x66a4(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %r14, %r14
je 0x9960
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
xorl %eax, %eax
testq %rbp, %rbp
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x6645(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq (%rsp), %rbx
movq 0x40(%rbx), %rdi
callq 0x2080
testq %rbp, %rbp
je 0x99c1
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x58(%rbx), %rdi
callq 0x2080
movq $0x0, 0x20(%rsp)
jmp 0x98e7
leaq -0x2(%r14), %rcx
movq 0x8(%rsp), %rbx
movsbq -0x1(%rbx,%r14), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
cmovneq %rcx, %r14
jmp 0x9854
cmpq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %r14
je 0x9a61
movq 0x68(%rsp), %rbx
xorl %eax, %eax
testq %rbx, %rbx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x30(%rsp), %rdi
movq 0x65a2(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x60(%rsp), %rdi
callq 0x2080
testq %rbx, %rbx
movq (%rsp), %rbx
je 0x9a61
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x78(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x428d
movq %r14, %rdi
callq 0x2040
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq