// File: /workspace/github_c_makefile_star2_O3/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, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, %r14
movups 0x36f5(%rip), %xmm0     # 0xc98b
movups %xmm0, 0xbb(%rsp)
movaps 0x36db(%rip), %xmm0     # 0xc980
movaps %xmm0, 0xb0(%rsp)
movaps 0x36bc(%rip), %xmm0     # 0xc970
movaps %xmm0, 0xa0(%rsp)
callq 0x3edd
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, 0x8(%rsp)
movq %rax, %rdi
callq 0x3f27
testl %eax, %eax
js 0x96db
movq %r14, 0x28(%rsp)
movl $0x1, %eax
movq %rax, (%rsp)
leaq 0xa0(%rsp), %rbx
movl $0x2a, %ebp
movq 0x8(%rsp), %r14
movq 0x48(%r14), %r12
testq %r12, %r12
je 0x9363
movq 0x8(%rsp), %rax
movq 0x58(%rax), %r15
xorl %r14d, %r14d
movsbl (%r15,%r14), %esi
movq %rbx, %rdi
callq 0x20e0
movl %eax, %ecx
subl %ebx, %ecx
testq %rax, %rax
movslq %ecx, %rax
cmoveq %rbp, %rax
movb (%r13,%rax), %al
movb %al, (%r15,%r14)
incq %r14
cmpq %r14, %r12
ja 0x9337
movq 0x30(%rsp), %r15
testq %r15, %r15
je 0x93c5
movq 0x8(%rsp), %r14
cmpq (%r14), %r15
jne 0x93dc
movq 0x40(%rsp), %rdi
cmpq $0x2, %r15
jbe 0x93e3
cmpb $0x2f, -0x2(%rdi,%r15)
movq 0x10(%r14), %rsi
jne 0x93e7
cmpb $0x2f, -0x2(%rsi,%r15)
jne 0x93e7
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
callq 0x2290
movq 0x20(%rsp), %rdi
movq (%rax), %rax
movsbq -0x1(%rdi,%r15), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x9612
movq 0x10(%rsp), %rsi
jmp 0x93e7
leaq 0x30(%rsp), %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x71ec
jmp 0x94b1
movq 0x78(%rsp), %r15
jmp 0x940a
movq 0x10(%r14), %rsi
movslq %r15d, %rdx
movq %rdi, %r14
movq %rsi, %r15
callq 0x2070
movq 0x78(%rsp), %rcx
testl %eax, %eax
je 0x94c6
movq %rcx, %r15
movq 0x8(%rsp), %r14
xorl %eax, %eax
testq %r15, %r15
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
cmpq $0x0, (%rsp)
js 0x9452
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x943e
movq 0x6b8a(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x313e(%rip), %rdi      # 0xc583
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x9466
movq 0x40(%rsp), %rdi
movq 0x6b62(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
testq %r15, %r15
je 0x94a0
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x71ec
incq (%rsp)
movq %r14, %rdi
callq 0x3f27
testl %eax, %eax
jns 0x9322
jmp 0x962f
movq %r14, 0x20(%rsp)
movq %r15, 0x10(%rsp)
xorl %eax, %eax
testq %rcx, %rcx
setne %al
leal 0x3e(,%rax,2), %edi
movq %rcx, %r15
callq 0x2060
cmpq $0x0, (%rsp)
js 0x9520
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r14
je 0x950c
movq 0x6abc(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x3070(%rip), %rdi      # 0xc583
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x9539
movq 0x6a99(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq 0x20(%rsp), %rdi
callq 0x2110
movq 0x8(%rsp), %r14
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
testq %r15, %r15
je 0x9573
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
xorl %eax, %eax
testq %r12, %r12
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
cmpq $0x0, (%rsp)
js 0x95bb
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x95a7
movq 0x6a21(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x2fd5(%rip), %rdi      # 0xc583
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x95cf
movq 0x69fe(%rip), %rax      # 0xffc0
movq (%rax), %rsi
movq 0x10(%rsp), %rdi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x40(%r14), %rdi
callq 0x2080
testq %r12, %r12
je 0x9604
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x58(%r14), %rdi
callq 0x2080
movq $0x0, 0x30(%rsp)
jmp 0x94ad
leaq -0x2(%r15), %rcx
movq 0x10(%rsp), %rsi
movsbq -0x1(%rsi,%r15), %rdx
testb $0x8, 0x1(%rax,%rdx,2)
cmovneq %rcx, %r15
jmp 0x93e7
cmpq $0x0, 0x30(%rsp)
movq 0x28(%rsp), %r14
je 0x96db
movq 0x78(%rsp), %rbx
xorl %eax, %eax
testq %rbx, %rbx
setne %al
leal 0x3e(,%rax,2), %edi
callq 0x2060
cmpq $0x0, (%rsp)
js 0x968d
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x9679
movq 0x694f(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
leaq 0x2f03(%rip), %rdi      # 0xc583
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x96a1
movq 0x40(%rsp), %rdi
movq 0x6927(%rip), %rax      # 0xffc0
movq (%rax), %rsi
callq 0x2110
movl $0xa, %edi
callq 0x2060
movq 0x70(%rsp), %rdi
callq 0x2080
testq %rbx, %rbx
je 0x96db
movl $0x2b, %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq 0x88(%rsp), %rdi
callq 0x2080
movq 0x8(%rsp), %rdi
callq 0x428d
movq %r14, %rdi
callq 0x2040
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq