// File: /workspace/github_c_makefile_star2_O3/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 $0x1f8, %rsp            # imm = 0x1F8
movq %rsi, %rbp
movl %edi, %r13d
leaq 0x78(%rsp), %r14
movl $0x178, %edx            # imm = 0x178
movq %r14, %rdi
xorl %esi, %esi
callq 0x2110
movaps 0x17ad(%rip), %xmm0     # 0x6020
movaps %xmm0, -0x28(%r14)
movaps 0x17b1(%rip), %xmm0     # 0x6030
movaps %xmm0, -0x18(%r14)
movq $0x0, -0x8(%r14)
leaq 0x1894(%rip), %rdx      # 0x6127
movl %r13d, %edi
movq %rbp, %rsi
callq 0x2220
testl %eax, %eax
js 0x4a46
movl $0x2, 0xc(%rsp)
movl $0x1e, 0x10(%rsp)
movl $0xa, 0x14(%rsp)
movq $0x0, 0x30(%rsp)
leaq 0x38(%rsp), %rbx
leaq 0x1854(%rip), %r14      # 0x6127
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movq %rbx, %r12
cmpl $0x61, %eax
jg 0x492d
cmpl $0x42, %eax
je 0x4965
cmpl $0x50, %eax
je 0x49ae
cmpl $0x54, %eax
jne 0x4a2b
movq 0x36c1(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2230
movq %rax, 0x30(%rsp)
movl %eax, 0x78(%rsp)
jmp 0x4a2b
leal -0x6c(%rax), %ecx
cmpl $0x8, %ecx
ja 0x49bb
leaq 0x1720(%rip), %rdx      # 0x6060
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq 0x3688(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2230
movl %eax, 0x10(%rsp)
movl %eax, 0x58(%rsp)
jmp 0x4a2b
movq 0x366c(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
movq %rbx, %rsi
movl $0xa, %edx
callq 0x2150
movq %rax, %r15
movl %r15d, 0x74(%rsp)
movl %r15d, 0x70(%rsp)
movq 0x38(%rsp), %rdi
cmpb $0x2c, (%rdi)
jne 0x49cf
incq %rdi
movq %rbx, %rsi
movl $0xa, %edx
callq 0x2150
movq %rax, 0x20(%rsp)
movl %eax, 0x74(%rsp)
jmp 0x4a2b
movl $0x1, 0x80(%rsp)
jmp 0x4a2b
cmpl $0x62, %eax
je 0x4a1c
cmpl $0x64, %eax
jne 0x4a2b
movl $0x1, 0x7c(%rsp)
jmp 0x4a2b
movl %r15d, %eax
movq %rax, 0x20(%rsp)
jmp 0x4a2b
movq 0x35f8(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2230
movl %eax, 0xc(%rsp)
movl %eax, 0x50(%rsp)
jmp 0x4a2b
movq 0x35df(%rip), %rax      # 0x7fd8
movq (%rax), %rdi
callq 0x2230
movl %eax, 0x14(%rsp)
movl %eax, 0x64(%rsp)
jmp 0x4a2b
movq 0x35c6(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x4a2b
movq 0x35b5(%rip), %rax      # 0x7fd8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movl %r13d, %edi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x2220
testl %eax, %eax
movq %r12, %rbx
jns 0x48f4
jmp 0x4a85
movq $0x0, 0x30(%rsp)
movl $0x2, 0xc(%rsp)
movl $0x1e, 0x10(%rsp)
movl $0xa, 0x14(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x3544(%rip), %rax      # 0x7fd0
movslq (%rax), %rax
cmpl %r13d, %eax
jge 0x4cae
movq (%rbp,%rax,8), %rdi
cmpb $0x2d, (%rdi)
jne 0x4aac
cmpb $0x0, 0x1(%rdi)
je 0x4c8c
leaq 0x162f(%rip), %rsi      # 0x60e2
callq 0x2200
movq %rax, %rbx
movq 0x18(%rsp), %r13
movl $0x1, %edi
movl $0x50, %esi
callq 0x2120
movq %rax, %r14
movl $0x1, %edi
movl $0x20, %esi
callq 0x2120
movq %rax, %r15
movq %rbx, 0x10(%rax)
movl $0x10000, 0x8(%rax)     # imm = 0x10000
movl $0x4000, %edi           # imm = 0x4000
callq 0x21b0
movq %rax, 0x18(%r15)
movq %r15, 0x48(%r14)
movq %r14, 0x88(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4b29
callq 0x36f0
movq %rax, 0x1e8(%rsp)
movq $0x0, 0x70(%rsp)
testq %r13, %r13
je 0x4ba9
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r14
movaps %xmm0, (%r14)
xorl %ebp, %ebp
movl %ebp, (%r14)
leaq 0x17fc(%rip), %r15      # 0x6342
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl $0x1, %ecx
xorl %eax, %eax
callq 0x4dc3
movq 0x8(%r14), %rdi
leaq 0x17e9(%rip), %r12      # 0x634f
movq %r12, %rsi
callq 0x2200
movq %rax, 0x90(%rsp)
movl %ebp, (%r14)
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl $0x2, %ecx
xorl %eax, %eax
callq 0x4dc3
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x2200
movq %rax, 0x98(%rsp)
movl %ebp, 0x80(%rsp)
leaq 0x32a(%rip), %rsi       # 0x4eda
leaq 0x50(%rsp), %rdx
movl $0x2, %edi
movl $0x3, %ecx
callq 0x2540
movq 0x342d(%rip), %r13      # 0x7ff8
leaq 0x1780(%rip), %r14      # 0x6352
leaq 0x178b(%rip), %r15      # 0x6364
xorl %r12d, %r12d
movq 0xa0(%rsp,%r12,8), %r8
testq %r8, %r8
jne 0x4bf4
incq %r12
cmpq $0x29, %r12
jne 0x4bdc
jmp 0x4c0a
movq (%r13), %rdi
movq %r14, %rsi
movq %r15, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2140
jmp 0x4be9
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x4c1c
callq 0x2040
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x4c2e
callq 0x2040
movq 0x88(%rsp), %r14
testq %r14, %r14
je 0x4c70
movq 0x8(%r14), %rdi
callq 0x2050
movq 0x18(%r14), %rdi
callq 0x2050
movq 0x28(%r14), %rdi
callq 0x2050
movq 0x38(%r14), %rdi
callq 0x2050
movq 0x48(%r14), %rdi
callq 0x398b
movq %r14, %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2040
xorl %eax, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3335(%rip), %rax      # 0x7fc8
movq (%rax), %rdi
callq 0x2170
leaq 0x1440(%rip), %rsi      # 0x60e2
movl %eax, %edi
callq 0x20b0
jmp 0x4ab8
movq 0x3343(%rip), %rbx      # 0x7ff8
movq (%rbx), %rcx
leaq 0x1479(%rip), %rdi      # 0x6138
movl $0x43, %esi
movl $0x1, %edx
callq 0x2240
movq (%rbx), %rcx
leaq 0x14a4(%rip), %rdi      # 0x617c
movl $0x9, %esi
movl $0x1, %edx
callq 0x2240
movq (%rbx), %rcx
leaq 0x1495(%rip), %rdi      # 0x6186
movl $0x2f, %esi
movl $0x1, %edx
callq 0x2240
movq (%rbx), %rdi
leaq 0x14ac(%rip), %rsi      # 0x61b6
movl %r15d, %edx
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x2140
movq (%rbx), %rdi
leaq 0x14ba(%rip), %rsi      # 0x61dd
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%rbx), %rdi
leaq 0x14cc(%rip), %rsi      # 0x6204
movl 0x10(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%rbx), %rdi
leaq 0x14ef(%rip), %rsi      # 0x623c
movl 0x14(%rsp), %edx
xorl %eax, %eax
callq 0x2140
movq (%rbx), %rcx
leaq 0x1502(%rip), %rdi      # 0x6264
movl $0x4f, %esi
movl $0x1, %edx
callq 0x2240
movq (%rbx), %rdi
leaq 0x1539(%rip), %rsi      # 0x62b4
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x2140
movq (%rbx), %rcx
leaq 0x1544(%rip), %rdi      # 0x62d5
movl $0x3f, %esi
movl $0x1, %edx
callq 0x2240
movq (%rbx), %rcx
leaq 0x156b(%rip), %rdi      # 0x6315
movl $0x2c, %esi
movl $0x1, %edx
callq 0x2240
movl $0x1, %eax
jmp 0x4c7a