// File: /workspace/github_c_makefile_star2_O2/aokad[P]sequeeze/seqtk.c
// Function: sequeeze
int sequeeze(gzFile fp, char *bin_quality, char *prefix)
{
	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_renamed(&last, 0, prefix, n);
				stk_printseq_renamed(seq,   0, prefix, n);
				last.name.l = 0;
				++n;
			} else {
				stk_printseq_renamed(&last, 0, prefix, n);
				++n;
				cpy_kseq(&last, seq);
			}
		} else cpy_kseq(&last, seq);
	}
	if (last.name.l) stk_printseq_renamed(&last, 0, prefix, n);

	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 %rdx, 0x8(%rsp)
movq %rsi, %r12
movups 0x2dec(%rip), %xmm0     # 0xa98b
leaq 0x90(%rsp), %r13
movups %xmm0, 0x1b(%r13)
movaps 0x2dcd(%rip), %xmm0     # 0xa980
movaps %xmm0, 0x10(%r13)
movaps 0x2db1(%rip), %xmm0     # 0xa970
movaps %xmm0, (%r13)
movq %rdi, 0x18(%rsp)
callq 0x3102
movq %rax, %r15
xorps %xmm0, %xmm0
leaq 0x20(%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)
pushq $0x1
popq %r14
movq %r14, 0x10(%rsp)
movq %r15, %rdi
callq 0x312e
testl %eax, %eax
js 0x7d2d
movq 0x48(%r15), %rbp
xorl %r14d, %r14d
cmpq %r14, %rbp
jbe 0x7c49
movq 0x58(%r15), %rbx
movsbl (%rbx,%r14), %esi
movq %r13, %rdi
callq 0x20e0
movl %eax, %ecx
subl %r13d, %ecx
testq %rax, %rax
movslq %ecx, %rax
pushq $0x2a
popq %rcx
cmoveq %rcx, %rax
movb (%r12,%rax), %al
movb %al, (%rbx,%r14)
incq %r14
jmp 0x7c14
movq 0x20(%rsp), %rbp
testq %rbp, %rbp
jne 0x7c67
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x5dc4
movq 0x10(%rsp), %r14
jmp 0x7bfd
cmpq (%r15), %rbp
jne 0x7cca
movq 0x30(%rsp), %rbx
cmpq $0x2, %rbp
jbe 0x7cb4
cmpb $0x2f, -0x2(%rbx,%rbp)
movq 0x10(%r15), %r14
jne 0x7cb8
cmpb $0x2f, -0x2(%r14,%rbp)
jne 0x7cb8
callq 0x2290
movq (%rax), %rax
movsbq -0x1(%rbx,%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x7cb8
leaq -0x2(%rbp), %rcx
movsbq -0x1(%r14,%rbp), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
cmovneq %rcx, %rbp
jmp 0x7cb8
movq 0x10(%r15), %r14
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2070
testl %eax, %eax
je 0x7cf9
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x71e4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5dc4
incq %r14
jmp 0x7bf8
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x71e4
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x71e4
andq $0x0, 0x20(%rsp)
jmp 0x7cf1
cmpq $0x0, 0x20(%rsp)
je 0x7d49
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
movq %r14, %rcx
callq 0x71e4
movq %r15, %rdi
callq 0x3329
movq 0x18(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq