// File: /workspace/github_c_makefile_star2_O1/DReichLab[P]adna/trim.c
// Function: main
int main(int argc, char *argv[])
{
	int c;
	lt_global_t g;
	gzFile fp;
	char *p, *pe_prefix = 0, *fn_bc = 0;

	lt_global_init(&g);
	while ((c = getopt(argc, argv, "dt:b:l:o:p:B:T:P")) >= 0) {
		if (c == 't') g.opt.n_threads = atoi(optarg);
		else if (c == 'd') g.opt.tab_out = 1;
		else if (c == 'P') g.opt.retain_pe = 1;
		else if (c == 'l') g.opt.min_seq_len = atoi(optarg);
		else if (c == 'o') g.opt.min_ovlp_len = atoi(optarg);
		else if (c == 'p') pe_prefix = optarg;
		else if (c == 'b') fn_bc = optarg;
		else if (c == 'T') g.opt.trim_len = atoi(optarg);
		else if (c == 'B') {
			g.opt.bc_len[0] = g.opt.bc_len[1] = strtol(optarg, &p, 10);
			if (*p == ',') g.opt.bc_len[1] = strtol(p+1, &p, 10);
		}
	}
	if (argc - optind < 1) {
		fprintf(stderr, "Usage: seqtk mergepe <read1.fq> <read2.fq> | adna-trim [options] -\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  -b FILE      barcode file (overriding -B) []\n");
		fprintf(stderr, "  -B INT[,INT] barcode length [%d,%d]\n", g.opt.bc_len[0], g.opt.bc_len[1]);
		fprintf(stderr, "  -t INT       number of threads [%d]\n", g.opt.n_threads);
		fprintf(stderr, "  -l INT       min read/fragment length to output [%d]\n", g.opt.min_seq_len);
		fprintf(stderr, "  -o INT       min overlap length [%d]\n", g.opt.min_ovlp_len);
		fprintf(stderr, "  -p STR       output PE reads to STR.R[12].fq.gz (overriding -P) [discard pe]\n");
		fprintf(stderr, "  -T INT       trim INT-bp [%d]\n", g.opt.trim_len);
		fprintf(stderr, "  -P           output paired reads also to stdout [discard pe]\n");
		fprintf(stderr, "  -d           tabular output for debugging\n");
		return 1;
	}

	fp = strcmp(argv[optind], "-")? gzopen(argv[optind], "r") : gzdopen(fileno(stdin), "r");
	g.ks = kseq_init(fp);
	if (fn_bc) g.bc = ad_bc_read(fn_bc), g.opt.bc_len[0] = g.opt.bc_len[1] = 0;
	if (pe_prefix) {
		kstring_t str = {0,0,0};
		for (c = 0; c < 2; ++c) {
			str.l = 0;
			ksprintf(&str, "%s.R%d.fq.gz", pe_prefix, c+1);
			g.fp_pe[c] = gzopen(str.s, "w1");
		}
		g.opt.retain_pe = 0;
	}

	kt_pipeline(2, worker_pipeline, &g, 3);
	for (c = 0; c <= AD_MAX_TYPE; ++c)
		if (g.types[c] > 0)
			fprintf(stderr, "[M::%s] %2d  %ld\n", __func__, c, (long)g.types[c]);

	if (g.fp_pe[0]) gzclose(g.fp_pe[0]);
	if (g.fp_pe[1]) gzclose(g.fp_pe[1]);
	kseq_destroy(g.ks);
	gzclose(fp);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %r15
movl %edi, %ebp
leaq 0x28(%rsp), %r14
xorl %ebx, %ebx
movl $0x1a0, %edx            # imm = 0x1A0
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
movaps 0x198c(%rip), %xmm0     # 0x6010
movups %xmm0, (%r14)
movaps 0x1991(%rip), %xmm0     # 0x6020
movups %xmm0, 0x10(%r14)
movq $0x0, 0x20(%r14)
movl $0x0, 0x28(%r14)
leaq 0x1a60(%rip), %rdx      # 0x610b
movl %ebp, %edi
movq %r15, %rsi
callq 0x2230
testl %eax, %eax
js 0x47f5
movq $0x0, (%rsp)
leaq 0x8(%rsp), %r12
leaq 0x1a3a(%rip), %r13      # 0x610b
xorl %ebx, %ebx
movq %r12, %r14
cmpl $0x61, %eax
jg 0x470a
cmpl $0x42, %eax
je 0x473a
cmpl $0x50, %eax
je 0x4779
cmpl $0x54, %eax
jne 0x47db
movq 0x38df(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2240
movl %eax, 0x50(%rsp)
jmp 0x47db
leal -0x6c(%rax), %ecx
cmpl $0x8, %ecx
ja 0x4783
leaq 0x1917(%rip), %rdx      # 0x6030
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x38af(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2240
movl %eax, 0x30(%rsp)
jmp 0x47db
movq 0x3897(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2160
movl %eax, 0x4c(%rsp)
movl %eax, 0x48(%rsp)
movq 0x8(%rsp), %rdi
cmpb $0x2c, (%rdi)
jne 0x47db
incq %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2160
movl %eax, 0x4c(%rsp)
jmp 0x47db
movl $0x1, 0x58(%rsp)
jmp 0x47db
cmpl $0x62, %eax
je 0x47cd
cmpl $0x64, %eax
jne 0x47db
movl $0x1, 0x54(%rsp)
jmp 0x47db
movq 0x383a(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2240
movl %eax, 0x28(%rsp)
jmp 0x47db
movq 0x3825(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2240
movl %eax, 0x3c(%rsp)
jmp 0x47db
movq 0x3810(%rip), %rax      # 0x7fd8
movq (%rax), %rbx
jmp 0x47db
movq 0x3804(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, (%rsp)
movl %ebp, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2230
testl %eax, %eax
movq %r14, %r12
jns 0x46d6
jmp 0x47fd
movq $0x0, (%rsp)
movq 0x37cc(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
cmpl %ebp, %eax
jge 0x4a07
movq (%r15,%rax,8), %r15
leaq 0x1b0c(%rip), %rsi      # 0x6326
movq %r15, %rdi
callq 0x2130
testl %eax, %eax
je 0x4837
leaq 0x1899(%rip), %rsi      # 0x60c6
movq %r15, %rdi
callq 0x2210
jmp 0x4854
movq 0x378a(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
callq 0x2180
leaq 0x1879(%rip), %rsi      # 0x60c6
movl %eax, %edi
callq 0x20b0
movq %rax, %r15
movl $0x1, %edi
movl $0x50, %esi
callq 0x2120
movq %rax, %r12
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r13
movq %r15, 0x10(%rax)
movl 0x8(%rax), %eax
andl $0x3, %eax
orl $0x10000, %eax          # imm = 0x10000
movl %eax, 0x8(%r13)
movl $0x4000, %edi           # imm = 0x4000
callq 0x21c0
movq %rax, 0x18(%r13)
movq %r13, 0x48(%r12)
movq %r12, 0x60(%rsp)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x48c5
callq 0x3537
movq %rax, 0x1c0(%rsp)
movq $0x0, 0x48(%rsp)
testq %rbx, %rbx
je 0x4930
movq %r15, (%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r14
movaps %xmm0, (%r14)
leaq 0x1a47(%rip), %r12      # 0x6328
leaq 0x1a4d(%rip), %r13      # 0x6335
xorl %ebp, %ebp
movl $0x0, 0x10(%rsp)
leaq 0x1(%rbp), %r15
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4b1b
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x2210
movq %rax, 0x68(%rsp,%rbp,8)
movq %r15, %rbp
cmpq $0x1, %r15
je 0x48ea
movl $0x0, 0x58(%rsp)
movq (%rsp), %r15
leaq 0x2fb(%rip), %rsi       # 0x4c32
leaq 0x28(%rsp), %rdx
movl $0x2, %edi
movl $0x3, %ecx
callq 0x2547
movq 0x36a6(%rip), %r13      # 0x7ff8
leaq 0x19df(%rip), %rbx      # 0x6338
leaq 0x19ea(%rip), %r14      # 0x634a
xorl %r12d, %r12d
movq 0x78(%rsp,%r12,8), %r8
testq %r8, %r8
jne 0x4978
incq %r12
cmpq $0x29, %r12
jne 0x4963
jmp 0x498e
movq (%r13), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2150
jmp 0x496d
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x499d
callq 0x2040
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x49ac
callq 0x2040
movq 0x60(%rsp), %rbx
testq %rbx, %rbx
je 0x49eb
movq 0x8(%rbx), %rdi
callq 0x2050
movq 0x18(%rbx), %rdi
callq 0x2050
movq 0x28(%rbx), %rdi
callq 0x2050
movq 0x38(%rbx), %rdi
callq 0x2050
movq 0x48(%rbx), %rdi
callq 0x37c6
movq %rbx, %rdi
callq 0x2050
movq %r15, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x35ea(%rip), %rbx      # 0x7ff8
movq (%rbx), %rcx
leaq 0x1704(%rip), %rdi      # 0x611c
movl $0x43, %esi
movl $0x1, %edx
callq 0x2250
movq (%rbx), %rcx
leaq 0x172f(%rip), %rdi      # 0x6160
movl $0x9, %esi
movl $0x1, %edx
callq 0x2250
movq (%rbx), %rcx
leaq 0x1720(%rip), %rdi      # 0x616a
movl $0x2f, %esi
movl $0x1, %edx
callq 0x2250
movq (%rbx), %rdi
movl 0x48(%rsp), %edx
movl 0x4c(%rsp), %ecx
leaq 0x172f(%rip), %rsi      # 0x619a
xorl %eax, %eax
callq 0x2150
movq (%rbx), %rdi
movl 0x28(%rsp), %edx
leaq 0x1741(%rip), %rsi      # 0x61c1
xorl %eax, %eax
callq 0x2150
movq (%rbx), %rdi
movl 0x30(%rsp), %edx
leaq 0x1753(%rip), %rsi      # 0x61e8
xorl %eax, %eax
callq 0x2150
movq (%rbx), %rdi
movl 0x3c(%rsp), %edx
leaq 0x1776(%rip), %rsi      # 0x6220
xorl %eax, %eax
callq 0x2150
movq (%rbx), %rcx
leaq 0x178d(%rip), %rdi      # 0x6248
movl $0x4f, %esi
movl $0x1, %edx
callq 0x2250
movq (%rbx), %rdi
movl 0x50(%rsp), %edx
leaq 0x17c0(%rip), %rsi      # 0x6298
xorl %eax, %eax
callq 0x2150
movq (%rbx), %rcx
leaq 0x17d0(%rip), %rdi      # 0x62b9
movl $0x3f, %esi
movl $0x1, %edx
callq 0x2250
movq (%rbx), %rcx
leaq 0x17f7(%rip), %rdi      # 0x62f9
movl $0x2c, %esi
movl $0x1, %edx
callq 0x2250
movl $0x1, %eax
jmp 0x49f5