// File: /workspace/github_c_makefile_star2_O0/aokad[P]sequeeze/seqtk.c
// Function: stk_trimfq
int stk_trimfq(int argc, char *argv[])
{ // FIXME: when a record with zero length will always be treated as a fasta record
	gzFile fp;
	kseq_t *seq;
	double param = 0.05, q_int2real[128];
	int i, c, min_len = 30, left = 0, right = 0, fixed_len = -1;
	while ((c = getopt(argc, argv, "l:q:b:e:L:")) >= 0) {
		switch (c) {
			case 'q': param = atof(optarg); break;
			case 'l': min_len = atoi(optarg); break;
			case 'b': left = atoi(optarg); break;
			case 'e': right = atoi(optarg); break;
			case 'L': fixed_len = atoi(optarg); break;
		}
	}
	if (optind == argc) {
		fprintf(stderr, "\n");
		fprintf(stderr, "Usage:   seqtk trimfq [options] <in.fq>\n\n");
		fprintf(stderr, "Options: -q FLOAT    error rate threshold (disabled by -b/-e) [%.2f]\n", param);
		fprintf(stderr, "         -l INT      maximally trim down to INT bp (disabled by -b/-e) [%d]\n", min_len);
		fprintf(stderr, "         -b INT      trim INT bp from left (non-zero to disable -q/-l) [0]\n");
		fprintf(stderr, "         -e INT      trim INT bp from right (non-zero to disable -q/-l) [0]\n");
		fprintf(stderr, "         -L INT      retain at most INT bp from the 5'-end (non-zero to disable -q/-l) [0]\n");
		fprintf(stderr, "         -Q          force FASTQ output\n");
		fprintf(stderr, "\n");
		return 1;
	}
	fp = strcmp(argv[optind], "-")? gzopen(argv[optind], "r") : gzdopen(fileno(stdin), "r");
	if (fp == 0) {
		fprintf(stderr, "[E::%s] failed to open the input file/stream.\n", __func__);
		return 1;
	}
	seq = kseq_init(fp);
	for (i = 0; i < 128; ++i)
		q_int2real[i] = pow(10., -(i - 33) / 10.);
	while (kseq_read(seq) >= 0) {
		int beg, tmp, end;
		double s, max;
		if (left || right || fixed_len > 0) {
			beg = left; end = seq->seq.l - right;
			if (beg >= end) beg = end = 0;
			if (fixed_len > 0 && end - beg > fixed_len) end = beg + fixed_len;
		} else if (seq->qual.l > min_len) {
			for (i = 0, beg = tmp = 0, end = seq->qual.l, s = max = 0.; i < seq->qual.l; ++i) {
				int q = seq->qual.s[i];
				if (q < 36) q = 36;
				if (q > 127) q = 127;
				s += param - q_int2real[q];
				if (s > max) max = s, beg = tmp, end = i + 1;
				if (s < 0) s = 0, tmp = i + 1;
			}

			/* max never set; all low qual, just give first min_len bp */
			if (max == 0.) beg = 0, end = min_len;

			if (end - beg < min_len) { // window-based 
				int is, imax;
				for (i = 0, is = 0; i < min_len; ++i)
					is += seq->qual.s[i] - 33;
				for (imax = is, beg = 0; i < seq->qual.l; ++i) {
					is += (int)seq->qual.s[i] - seq->qual.s[i - min_len];
					if (imax < is) imax = is, beg = i - min_len + 1;
				}
				end = beg + min_len;
			}
		} else beg = 0, end = seq->seq.l;
		putchar(seq->is_fastq? '@' : '>'); fputs(seq->name.s, stdout); 
		if (seq->comment.l) {
			putchar(' '); puts(seq->comment.s);
		} else putchar('\n');
		fwrite(seq->seq.s + beg, 1, end - beg, stdout); putchar('\n');
		if (seq->is_fastq) {
			puts("+");
			fwrite(seq->qual.s + beg, 1, end - beg, stdout); putchar('\n');
		}
	}
	kseq_destroy(seq);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd 0x9eae(%rip), %xmm0     # 0xd008
movsd %xmm0, -0x28(%rbp)
movl $0x1e, -0x43c(%rbp)
movl $0x0, -0x440(%rbp)
movl $0x0, -0x444(%rbp)
movl $0xffffffff, -0x448(%rbp) # imm = 0xFFFFFFFF
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xa0fe(%rip), %rdx      # 0xd293
callq 0x2240
movl %eax, -0x438(%rbp)
cmpl $0x0, %eax
jl 0x3250
movl -0x438(%rbp), %eax
addl $-0x4c, %eax
movl %eax, %ecx
movq %rcx, -0x480(%rbp)
subl $0x25, %eax
ja 0x324b
movq -0x480(%rbp), %rax
leaq 0x9eae(%rip), %rcx      # 0xd080
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xddf6(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x20a0
movsd %xmm0, -0x28(%rbp)
jmp 0x324b
movq 0xdde0(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x43c(%rbp)
jmp 0x324b
movq 0xddc9(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x440(%rbp)
jmp 0x324b
movq 0xddb2(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x444(%rbp)
jmp 0x324b
movq 0xdd9b(%rip), %rax      # 0x10fd8
movq (%rax), %rdi
callq 0x2250
movl %eax, -0x448(%rbp)
jmp 0x3187
movq 0xdd79(%rip), %rax      # 0x10fd0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jne 0x3351
movq 0xdd8f(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa4c4(%rip), %rsi      # 0xd737
movb $0x0, %al
callq 0x2190
movq 0xdd77(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa013(%rip), %rsi      # 0xd29e
movb $0x0, %al
callq 0x2190
movq 0xdd5f(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movsd -0x28(%rbp), %xmm0
leaq 0xa020(%rip), %rsi      # 0xd2c8
movb $0x1, %al
callq 0x2190
movq 0xdd42(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movl -0x43c(%rbp), %edx
leaq 0xa048(%rip), %rsi      # 0xd30e
movb $0x0, %al
callq 0x2190
movq 0xdd24(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa07d(%rip), %rsi      # 0xd35b
movb $0x0, %al
callq 0x2190
movq 0xdd0c(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa0b1(%rip), %rsi      # 0xd3a7
movb $0x0, %al
callq 0x2190
movq 0xdcf4(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa0e6(%rip), %rsi      # 0xd3f4
movb $0x0, %al
callq 0x2190
movq 0xdcdc(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa12a(%rip), %rsi      # 0xd450
movb $0x0, %al
callq 0x2190
movq 0xdcc4(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa3f9(%rip), %rsi      # 0xd737
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x38e3
movq -0x10(%rbp), %rax
movq 0xdc74(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xb12c(%rip), %rsi      # 0xe496
callq 0x2170
cmpl $0x0, %eax
je 0x339b
movq -0x10(%rbp), %rax
movq 0xdc51(%rip), %rcx      # 0x10fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9ef3(%rip), %rsi      # 0xd280
callq 0x2220
movq %rax, -0x488(%rbp)
jmp 0x33bf
movq 0xdc26(%rip), %rax      # 0x10fc8
movq (%rax), %rdi
callq 0x21b0
movl %eax, %edi
leaq 0x9ecd(%rip), %rsi      # 0xd280
callq 0x20b0
movq %rax, -0x488(%rbp)
movq -0x488(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x33fc
movq 0xdc20(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0xa097(%rip), %rsi      # 0xd479
leaq 0xa0bf(%rip), %rdx      # 0xd4a8
movb $0x0, %al
callq 0x2190
movl $0x1, -0x4(%rbp)
jmp 0x38e3
movq -0x18(%rbp), %rdi
callq 0x38f0
movq %rax, -0x20(%rbp)
movl $0x0, -0x434(%rbp)
cmpl $0x80, -0x434(%rbp)
jge 0x346a
movl -0x434(%rbp), %ecx
subl $0x21, %ecx
xorl %eax, %eax
subl %ecx, %eax
cvtsi2sd %eax, %xmm1
movsd 0x9bd8(%rip), %xmm0     # 0xd010
divsd %xmm0, %xmm1
movsd 0x9bcc(%rip), %xmm0     # 0xd010
callq 0x20c0
movslq -0x434(%rbp), %rax
movsd %xmm0, -0x430(%rbp,%rax,8)
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x3413
jmp 0x346c
movq -0x20(%rbp), %rdi
callq 0x3930
cmpl $0x0, %eax
jl 0x38ca
cmpl $0x0, -0x440(%rbp)
jne 0x3499
cmpl $0x0, -0x444(%rbp)
jne 0x3499
cmpl $0x0, -0x448(%rbp)
jle 0x3513
movl -0x440(%rbp), %eax
movl %eax, -0x44c(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x444(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x454(%rbp)
movl -0x44c(%rbp), %eax
cmpl -0x454(%rbp), %eax
jl 0x34df
movl $0x0, -0x454(%rbp)
movl $0x0, -0x44c(%rbp)
cmpl $0x0, -0x448(%rbp)
jle 0x350e
movl -0x454(%rbp), %eax
subl -0x44c(%rbp), %eax
cmpl -0x448(%rbp), %eax
jle 0x350e
movl -0x44c(%rbp), %eax
addl -0x448(%rbp), %eax
movl %eax, -0x454(%rbp)
jmp 0x37d0
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x43c(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x37b6
movl $0x0, -0x434(%rbp)
movl $0x0, -0x450(%rbp)
movl $0x0, -0x44c(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, -0x454(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x468(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x460(%rbp)
movslq -0x434(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x3660
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x434(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x46c(%rbp)
cmpl $0x24, -0x46c(%rbp)
jge 0x35ae
movl $0x24, -0x46c(%rbp)
cmpl $0x7f, -0x46c(%rbp)
jle 0x35c1
movl $0x7f, -0x46c(%rbp)
movsd -0x28(%rbp), %xmm0
movslq -0x46c(%rbp), %rax
subsd -0x430(%rbp,%rax,8), %xmm0
addsd -0x460(%rbp), %xmm0
movsd %xmm0, -0x460(%rbp)
movsd -0x460(%rbp), %xmm0
ucomisd -0x468(%rbp), %xmm0
jbe 0x3623
movsd -0x460(%rbp), %xmm0
movsd %xmm0, -0x468(%rbp)
movl -0x450(%rbp), %eax
movl %eax, -0x44c(%rbp)
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x454(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x460(%rbp), %xmm0
jbe 0x364a
xorps %xmm0, %xmm0
movsd %xmm0, -0x460(%rbp)
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x450(%rbp)
jmp 0x364c
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x356d
movsd -0x468(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3689
jp 0x3689
movl $0x0, -0x44c(%rbp)
movl -0x43c(%rbp), %eax
movl %eax, -0x454(%rbp)
movl -0x454(%rbp), %eax
subl -0x44c(%rbp), %eax
cmpl -0x43c(%rbp), %eax
jge 0x37b4
movl $0x0, -0x434(%rbp)
movl $0x0, -0x470(%rbp)
movl -0x434(%rbp), %eax
cmpl -0x43c(%rbp), %eax
jge 0x36f6
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x434(%rbp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x21, %eax
addl -0x470(%rbp), %eax
movl %eax, -0x470(%rbp)
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x36b5
movl -0x470(%rbp), %eax
movl %eax, -0x474(%rbp)
movl $0x0, -0x44c(%rbp)
movslq -0x434(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x37a2
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x434(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq 0x58(%rcx), %rcx
movl -0x434(%rbp), %edx
subl -0x43c(%rbp), %edx
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
subl %ecx, %eax
addl -0x470(%rbp), %eax
movl %eax, -0x470(%rbp)
movl -0x474(%rbp), %eax
cmpl -0x470(%rbp), %eax
jge 0x378c
movl -0x470(%rbp), %eax
movl %eax, -0x474(%rbp)
movl -0x434(%rbp), %eax
subl -0x43c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44c(%rbp)
jmp 0x378e
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x370c
movl -0x44c(%rbp), %eax
addl -0x43c(%rbp), %eax
movl %eax, -0x454(%rbp)
jmp 0x37ce
movl $0x0, -0x44c(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, -0x454(%rbp)
jmp 0x37d0
movq -0x20(%rbp), %rax
movl 0x64(%rax), %ecx
movl $0x3e, %edi
movl $0x40, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edi
callq 0x2050
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq 0xd7c5(%rip), %rax      # 0x10fc0
movq (%rax), %rsi
callq 0x2110
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x3827
movl $0x20, %edi
callq 0x2050
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x2080
jmp 0x3831
movl $0xa, %edi
callq 0x2050
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
movslq -0x44c(%rbp), %rax
addq %rax, %rdi
movl -0x454(%rbp), %eax
subl -0x44c(%rbp), %eax
movslq %eax, %rdx
movq 0xd767(%rip), %rax      # 0x10fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x2260
movl $0xa, %edi
callq 0x2050
movq -0x20(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0x38c5
leaq 0x9c32(%rip), %rdi      # 0xd4b3
callq 0x2080
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rdi
movslq -0x44c(%rbp), %rax
addq %rax, %rdi
movl -0x454(%rbp), %eax
subl -0x44c(%rbp), %eax
movslq %eax, %rdx
movq 0xd712(%rip), %rax      # 0x10fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x2260
movl $0xa, %edi
callq 0x2050
jmp 0x346c
movq -0x20(%rbp), %rdi
callq 0x3d40
movq -0x18(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nop