// File: /workspace/github_c_makefile_star2_O1/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 $0xd8, %rsp
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movups 0x390e(%rip), %xmm0     # 0xc97b
movups %xmm0, 0xbb(%rsp)
movaps 0x38f4(%rip), %xmm0     # 0xc970
movaps %xmm0, 0xb0(%rsp)
movaps 0x38d5(%rip), %xmm0     # 0xc960
movaps %xmm0, 0xa0(%rsp)
movq %rdi, 0x28(%rsp)
callq 0x3e57
movq %rax, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movq %rax, %rdi
callq 0x3ea1
movl $0x1, %r12d
testl %eax, %eax
js 0x93d4
leaq 0xa0(%rsp), %rbx
movl $0x2a, %r15d
movq %r12, 0x18(%rsp)
cmpq $0x0, 0x48(%r14)
je 0x9132
xorl %r12d, %r12d
movq 0x58(%r14), %rbp
movsbl (%rbp,%r12), %esi
movq %rbx, %rdi
callq 0x20e0
movl %eax, %ecx
subl %ebx, %ecx
testq %rax, %rax
movslq %ecx, %rax
cmoveq %r15, %rax
movb (%r13,%rax), %al
movb %al, (%rbp,%r12)
incq %r12
cmpq %r12, 0x48(%r14)
ja 0x90ff
movq 0x30(%rsp), %r12
testq %r12, %r12
je 0x920b
movq (%r14), %rbp
cmpq %rbp, %r12
jne 0x91bc
cmpq $0x3, %r12
jb 0x91a0
movq 0x40(%rsp), %rax
cmpb $0x2f, -0x2(%rax,%r12)
jne 0x91a0
movq 0x10(%r14), %rcx
cmpb $0x2f, -0x2(%rcx,%rbp)
jne 0x91a0
movq %rax, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
callq 0x2290
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movsbq -0x1(%rcx,%r12), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
movq 0x10(%rsp), %rcx
je 0x91a0
movsbq -0x1(%rcx,%rbp), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
je 0x91a0
addq $-0x2, %r12
movq 0x40(%rsp), %rbp
movq 0x10(%r14), %rsi
movslq %r12d, %rdx
movq %rbp, %rdi
callq 0x2070
testl %eax, %eax
je 0x9292
movq 0x78(%rsp), %rbp
xorl %eax, %eax
testq %rbp, %rbp
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x18(%rsp), %r12
testq %r12, %r12
js 0x921f
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x91f8
movq 0x6dd0(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x3374(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x9233
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x6ee7
movq 0x18(%rsp), %r12
jmp 0x927d
movq 0x40(%rsp), %rdi
movq 0x6d95(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
testq %rbp, %rbp
je 0x926d
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x6ee7
incq %r12
movq %r14, %rdi
callq 0x3ea1
testl %eax, %eax
jns 0x90f0
jmp 0x93d4
movq 0x78(%rsp), %rcx
xorl %eax, %eax
movq %rcx, 0x10(%rsp)
testq %rcx, %rcx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
movq 0x18(%rsp), %r12
testq %r12, %r12
js 0x92e6
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x92d3
movq 0x6cf5(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x3299(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x92f8
movq 0x6cd3(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
cmpq $0x0, 0x10(%rsp)
je 0x9335
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
xorl %eax, %eax
cmpq $0x0, 0x48(%r14)
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x937c
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x9369
movq 0x6c5f(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x3203(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x938f
movq 0x10(%r14), %rdi
movq 0x6c39(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x40(%r14), %rdi
callq 0x2080
cmpq $0x0, 0x48(%r14)
je 0x93c6
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x58(%r14), %rdi
callq 0x2080
movq $0x0, 0x30(%rsp)
jmp 0x927a
cmpq $0x0, 0x30(%rsp)
je 0x9478
movq 0x78(%rsp), %rbx
xorl %eax, %eax
testq %rbx, %rbx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
testq %r12, %r12
js 0x942a
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x9417
movq 0x6bb1(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x3155(%rip), %rdi      # 0xc573
movq %r12, %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x943e
movq 0x40(%rsp), %rdi
movq 0x6b8a(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
testq %rbx, %rbx
je 0x9478
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x4229
movq 0x28(%rsp), %rdi
callq 0x2040
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq