// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x1, -0x90(%rbp)
leaq -0xc0(%rbp), %rdi
leaq 0x4244(%rip), %rsi      # 0xea50
movl $0x2b, %edx
callq 0x21a0
movq -0x8(%rbp), %rdi
callq 0x38f0
movq %rax, -0x18(%rbp)
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0x70, %edx
callq 0x2120
movq -0x18(%rbp), %rdi
callq 0x3930
cmpl $0x0, %eax
jl 0xaae7
movl $0x0, -0xc4(%rbp)
movslq -0xc4(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0xa8ec
leaq -0xc0(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0xc4(%rbp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x20e0
movq %rax, -0xd0(%rbp)
movl $0x2a, -0xd4(%rbp)
cmpq $0x0, -0xd0(%rbp)
je 0xa8b8
movq -0xd0(%rbp), %rax
leaq -0xc0(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xd4(%rbp)
movq -0x10(%rbp), %rax
movslq -0xd4(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0xc4(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xa852
cmpq $0x0, -0x88(%rbp)
je 0xaad2
leaq -0x88(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq -0xe8(%rbp), %rcx
cmpq (%rcx), %rax
jne 0xaa55
movq -0xe0(%rbp), %rax
cmpq $0x2, (%rax)
jbe 0xaa0d
movq -0xe0(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe0(%rbp), %rcx
movq (%rcx), %rcx
subq $0x2, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0xaa0d
movq -0xe8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0xe8(%rbp), %rcx
movq (%rcx), %rcx
subq $0x2, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0xaa0d
callq 0x2280
movq (%rax), %rax
movq -0xe0(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xe0(%rbp), %rdx
movq (%rdx), %rdx
subq $0x1, %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0xaa0d
callq 0x2280
movq (%rax), %rax
movq -0xe8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0xe8(%rbp), %rdx
movq (%rdx), %rdx
subq $0x1, %rdx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0xaa0d
movq -0xe0(%rbp), %rax
movq (%rax), %rax
subq $0x2, %rax
movq %rax, -0xf8(%rbp)
jmp 0xaa1e
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movl %eax, -0xf0(%rbp)
movq -0xe0(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xe8(%rbp), %rax
movq 0x10(%rax), %rsi
movslq -0xf0(%rbp), %rdx
callq 0x2060
movl %eax, -0xec(%rbp)
jmp 0xaa5f
movl $0x1, -0xec(%rbp)
cmpl $0x0, -0xec(%rbp)
jne 0xaaa0
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x7440
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x7440
movq $0x0, -0x88(%rbp)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0xaad0
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x7440
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x73d0
jmp 0xaae2
movq -0x18(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x73d0
jmp 0xa836
cmpq $0x0, -0x88(%rbp)
je 0xaaff
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
callq 0x7440
movq -0x18(%rbp), %rdi
callq 0x3d40
movq -0x8(%rbp), %rdi
callq 0x2030
xorl %eax, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)