// File: /workspace/github_c_makefile_star2_O2/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 $0xb8, %rsp
movq %rsi, %r15
movups 0x2c01(%rip), %xmm0     # 0xa98b
leaq 0x80(%rsp), %r12
movups %xmm0, 0x1b(%r12)
movaps 0x2be1(%rip), %xmm0     # 0xa980
movaps %xmm0, 0x10(%r12)
movaps 0x2bc4(%rip), %xmm0     # 0xa970
movaps %xmm0, (%r12)
movq %rdi, 0x8(%rsp)
callq 0x3102
movq %rax, %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
movaps %xmm0, 0x50(%rax)
movaps %xmm0, 0x60(%rax)
movq %r14, %rdi
callq 0x312e
testl %eax, %eax
js 0x7ee2
movq 0x48(%r14), %rbx
xorl %ebp, %ebp
cmpq %rbp, %rbx
jbe 0x7e2e
movq 0x58(%r14), %r13
movsbl (%r13,%rbp), %esi
movq %r12, %rdi
callq 0x20e0
movl %eax, %ecx
subl %r12d, %ecx
testq %rax, %rax
movslq %ecx, %rax
pushq $0x2a
popq %rcx
cmoveq %rcx, %rax
movb (%r15,%rax), %al
movb %al, (%r13,%rbp)
incq %rbp
jmp 0x7df7
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0x7e85
cmpq (%r14), %rbx
jne 0x7ea2
movq 0x20(%rsp), %rbp
cmpq $0x2, %rbx
jbe 0x7e8c
cmpb $0x2f, -0x2(%rbp,%rbx)
movq 0x10(%r14), %r13
jne 0x7e90
cmpb $0x2f, -0x2(%r13,%rbx)
jne 0x7e90
callq 0x2290
movq (%rax), %rax
movsbq -0x1(%rbp,%rbx), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x7e90
leaq -0x2(%rbx), %rcx
movsbq -0x1(%r13,%rbx), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
cmovneq %rcx, %rbx
jmp 0x7e90
leaq 0x10(%rsp), %rdi
jmp 0x7eb4
movq 0x10(%r14), %r13
movslq %ebx, %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2070
testl %eax, %eax
je 0x7ec1
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5e07
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5dc4
jmp 0x7de1
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x5e07
movq %r14, %rdi
xorl %esi, %esi
callq 0x5e07
andq $0x0, 0x10(%rsp)
jmp 0x7de1
cmpq $0x0, 0x10(%rsp)
je 0x7ef6
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x5e07
movq %r14, %rdi
callq 0x3329
movq 0x8(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq