// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap/main.c
// Function: main
int main(int argc, char *argv[])
{
	mm_mapopt_t opt;
	int i, c, k = 15, w = -1, b = MM_IDX_DEF_B, n_threads = 3, keep_name = 1, is_idx = 0;
	int tbatch_size = 100000000;
	uint64_t ibatch_size = 4000000000ULL;
	float f = 0.001;
	bseq_file_t *fp = 0;
	char *fnw = 0;
	FILE *fpr = 0, *fpw = 0;

	liftrlimit();
	mm_realtime0 = realtime();
	mm_mapopt_init(&opt);

	while ((c = getopt(argc, argv, "w:k:B:b:t:r:c:f:Vv:NOg:I:d:lRPST:m:L:Dx:")) >= 0) {
		if (c == 'w') w = atoi(optarg);
		else if (c == 'k') k = atoi(optarg);
		else if (c == 'b') b = atoi(optarg);
		else if (c == 'r') opt.radius = atoi(optarg);
		else if (c == 'c') opt.min_cnt = atoi(optarg);
		else if (c == 'm') opt.merge_frac = atof(optarg);
		else if (c == 'f') f = atof(optarg);
		else if (c == 't') n_threads = atoi(optarg);
		else if (c == 'v') mm_verbose = atoi(optarg);
		else if (c == 'g') opt.max_gap = atoi(optarg);
		else if (c == 'N') keep_name = 0;
		else if (c == 'd') fnw = optarg;
		else if (c == 'l') is_idx = 1;
		else if (c == 'R') opt.flag |= MM_F_WITH_REP;
		else if (c == 'P') opt.flag &= ~MM_F_WITH_REP;
		else if (c == 'D') opt.flag |= MM_F_NO_SELF;
		else if (c == 'O') opt.flag |= MM_F_NO_ISO;
		else if (c == 'S') opt.flag |= MM_F_AVA | MM_F_NO_SELF;
		else if (c == 'T') opt.sdust_thres = atoi(optarg);
		else if (c == 'L') opt.min_match = atoi(optarg);
		else if (c == 'V') {
			puts(MM_VERSION);
			return 0;
		} else if (c == 'B' || c == 'I') {
			double x;
			char *p;
			x = strtod(optarg, &p);
			if (*p == 'G' || *p == 'g') x *= 1e9;
			else if (*p == 'M' || *p == 'm') x *= 1e6;
			else if (*p == 'K' || *p == 'k') x *= 1e3;
			if (c == 'B') tbatch_size = (uint64_t)(x + .499);
			else ibatch_size = (uint64_t)(x + .499);
		} else if (c == 'x') {
			if (strcmp(optarg, "ava10k") == 0) {
				opt.flag |= MM_F_AVA | MM_F_NO_SELF;
				opt.min_match = 100;
				opt.merge_frac = 0.0;
				w = 5;
			}
		}
	}
	if (w < 0) w = (int)(.6666667 * k + .499);

	if (argc == optind) {
		fprintf(stderr, "Usage: minimap [options] <target.fa> [query.fa] [...]\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, "  Indexing:\n");
		fprintf(stderr, "    -k INT     k-mer size [%d]\n", k);
		fprintf(stderr, "    -w INT     minizer window size [{-k}*2/3]\n");
		fprintf(stderr, "    -I NUM     split index for every ~NUM input bases [4G]\n");
		fprintf(stderr, "    -d FILE    dump index to FILE []\n");
		fprintf(stderr, "    -l         the 1st argument is a index file (overriding -k, -w and -I)\n");
//		fprintf(stderr, "    -b INT     bucket bits [%d]\n", b); // most users would care about this
		fprintf(stderr, "  Mapping:\n");
		fprintf(stderr, "    -f FLOAT   filter out top FLOAT fraction of repetitive minimizers [%.3f]\n", f);
		fprintf(stderr, "    -r INT     bandwidth [%d]\n", opt.radius);
		fprintf(stderr, "    -m FLOAT   merge two chains if FLOAT fraction of minimizers are shared [%.2f]\n", opt.merge_frac);
		fprintf(stderr, "    -c INT     retain a mapping if it consists of >=INT minimizers [%d]\n", opt.min_cnt);
		fprintf(stderr, "    -L INT     min matching length [%d]\n", opt.min_match);
		fprintf(stderr, "    -g INT     split a mapping if there is a gap longer than INT [%d]\n", opt.max_gap);
		fprintf(stderr, "    -T INT     SDUST threshold; 0 to disable SDUST [%d]\n", opt.sdust_thres);
//		fprintf(stderr, "    -D         skip self mappings but keep dual mappings\n"); // too confusing to expose to end users
		fprintf(stderr, "    -S         skip self and dual mappings\n");
		fprintf(stderr, "    -O         drop isolated hits before chaining (EXPERIMENTAL)\n");
		fprintf(stderr, "    -P         filtering potential repeats after mapping (EXPERIMENTAL)\n");
//		fprintf(stderr, "    -R         skip post-mapping repeat filtering\n"); // deprecated option for backward compatibility
		fprintf(stderr, "    -x STR     preset (recommended to be applied before other options) []\n");
		fprintf(stderr, "               ava10k: -Sw5 -L100 -m0 (PacBio/ONT all-vs-all read mapping)\n");
		fprintf(stderr, "  Input/Output:\n");
		fprintf(stderr, "    -t INT     number of threads [%d]\n", n_threads);
//		fprintf(stderr, "    -B NUM     process ~NUM bp in each batch [100M]\n");
//		fprintf(stderr, "    -v INT     verbose level [%d]\n", mm_verbose);
//		fprintf(stderr, "    -N         use integer as target names\n");
		fprintf(stderr, "    -V         show version number\n");
		fprintf(stderr, "\nSee minimap.1 for detailed description of the command-line options.\n");
		return 1;
	}

	if (is_idx) fpr = fopen(argv[optind], "rb");
	else fp = bseq_open(argv[optind]);
	if (fnw) fpw = fopen(fnw, "wb");
	for (;;) {
		mm_idx_t *mi = 0;
		if (fpr) mi = mm_idx_load(fpr);
		else if (!bseq_eof(fp))
			mi = mm_idx_gen(fp, w, k, b, tbatch_size, n_threads, ibatch_size, keep_name);
		if (mi == 0) break;
		if (mm_verbose >= 3)
			fprintf(stderr, "[M::%s::%.3f*%.2f] loaded/built the index for %d target sequence(s)\n",
					__func__, realtime() - mm_realtime0, cputime() / (realtime() - mm_realtime0), mi->n);
		mm_idx_set_max_occ(mi, f);
		if (mm_verbose >= 3)
			fprintf(stderr, "[M::%s] max occurrences of a minimizer to consider: %d\n", __func__, mi->max_occ);
		if (fpw) mm_idx_dump(fpw, mi);
		for (i = optind + 1; i < argc; ++i)
			mm_map_file(mi, argv[i], &opt, n_threads, tbatch_size);
		mm_idx_destroy(mi);
	}
	if (fpw) fclose(fpw);
	if (fpr) fclose(fpr);
	if (fp)  bseq_close(fp);

	fprintf(stderr, "[M::%s] Version: %s\n", __func__, MM_VERSION);
	fprintf(stderr, "[M::%s] CMD:", __func__);
	for (i = 0; i < argc; ++i)
		fprintf(stderr, " %s", argv[i]);
	fprintf(stderr, "\n[M::%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - mm_realtime0, cputime());
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movl $0xee6b2800, %eax       # imm = 0xEE6B2800
movq %rax, 0x60(%rsp)
leaq 0x30(%rsp), %r14
movl $0x9, %edi
movq %r14, %rsi
callq 0x22a0
movq 0x8(%r14), %rax
movq %rax, (%r14)
movl $0x9, %edi
movq %r14, %rsi
callq 0x21f0
callq 0x2f73
leaq 0x8a0b(%rip), %rax      # 0xb2a8
movsd %xmm0, (%rax)
leaq 0x30(%rsp), %rdi
callq 0x4ed8
leaq 0x5856(%rip), %rdx      # 0x8108
movl %ebp, %edi
movq %rbx, %rsi
callq 0x2270
testl %eax, %eax
js 0x2ed2
movl %eax, %r13d
movl $0xf, 0x8(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl $0xe, 0x14(%rsp)
movl $0x3, 0xc(%rsp)
movl $0x1, %eax
movq %rax, 0x58(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x5f5e100, 0x4(%rsp)   # imm = 0x5F5E100
movss 0x56fc(%rip), %xmm0     # 0x8004
movss %xmm0, 0x10(%rsp)
leaq 0x57f3(%rip), %r15      # 0x8108
leaq 0x571c(%rip), %r14      # 0x8038
movl $0x0, 0x20(%rsp)
leal -0x44(%r13), %eax
cmpl $0x33, %eax
ja 0x2acb
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
orb $0x2, 0x44(%rsp)
jmp 0x2bd6
movq 0x868d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, %r12d
jmp 0x2bd6
movq 0x8676(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x30(%rsp)
jmp 0x2bd6
movq $0x0, 0x58(%rsp)
jmp 0x2bd6
orb $0x1, 0x44(%rsp)
jmp 0x2bd6
movq 0x8646(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0xc(%rsp)
jmp 0x2bd6
movq 0x862e(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2090
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x48(%rsp)
jmp 0x2bd6
movq 0x8610(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x38(%rsp)
jmp 0x2bd6
movq 0x85f8(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x3c(%rsp)
jmp 0x2bd6
orb $0xa, 0x44(%rsp)
jmp 0x2bd6
movq 0x85d6(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x40(%rsp)
jmp 0x2bd6
movl $0x1, 0x20(%rsp)
jmp 0x2bd6
orb $0x4, 0x44(%rsp)
jmp 0x2bd6
movq 0x85a7(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x2bd6
andb $-0x2, 0x44(%rsp)
jmp 0x2bd6
movq 0x8589(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
leaq 0x8732(%rip), %rcx      # 0xb190
movl %eax, (%rcx)
jmp 0x2bd6
movq 0x856c(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x14(%rsp)
jmp 0x2bd6
movq 0x8554(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x34(%rsp)
jmp 0x2bd6
movq 0x853c(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2090
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0x2bd6
movq 0x851e(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x2280
movl %eax, 0x8(%rsp)
jmp 0x2bd6
cmpl $0x42, %r13d
je 0x2ae1
cmpl $0x78, %r13d
je 0x2b49
cmpl $0x49, %r13d
jne 0x2bd6
movq 0x84f0(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x80(%rsp), %rsi
callq 0x2080
movq 0x80(%rsp), %rax
movzbl (%rax), %eax
addl $-0x47, %eax
cmpl $0x26, %eax
ja 0x2b92
movabsq $0x100000001, %rcx      # imm = 0x100000001
btq %rax, %rcx
jb 0x2b8a
movabsq $0x1000000010, %rcx     # imm = 0x1000000010
btq %rax, %rcx
jb 0x2b80
movabsq $0x4000000040, %rcx     # imm = 0x4000000040
btq %rax, %rcx
jae 0x2b92
mulsd 0x54c9(%rip), %xmm0     # 0x8010
jmp 0x2b92
movq 0x8488(%rip), %rax      # 0xafd8
movq (%rax), %rdi
leaq 0x55e6(%rip), %rsi      # 0x8140
callq 0x2160
testl %eax, %eax
jne 0x2bd6
orb $0xa, 0x44(%rsp)
movl $0x64, 0x3c(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x5, %r12d
jmp 0x2bd6
mulsd 0x5480(%rip), %xmm0     # 0x8008
jmp 0x2b92
mulsd 0x5486(%rip), %xmm0     # 0x8018
addsd 0x5486(%rip), %xmm0     # 0x8020
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x547e(%rip), %xmm0     # 0x8028
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
cmpl $0x42, %r13d
movl 0x4(%rsp), %eax
cmovel %edx, %eax
movl %eax, 0x4(%rsp)
movq 0x60(%rsp), %rax
cmovneq %rdx, %rax
movq %rax, 0x60(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2270
movl %eax, %r13d
testl %eax, %eax
jns 0x2924
testl %r12d, %r12d
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
mulsd 0x542e(%rip), %xmm0     # 0x8030
addsd 0x5416(%rip), %xmm0     # 0x8020
cvttsd2si %xmm0, %eax
cmovnsl %r12d, %eax
movl %eax, 0x2c(%rsp)
movq 0x83b3(%rip), %rax      # 0xafd0
movl (%rax), %eax
cmpl %ebp, %eax
jne 0x2c58
movl 0xc(%rsp), %edx
leaq 0x30(%rsp), %rsi
movl 0x8(%rsp), %edi
movss 0x10(%rsp), %xmm0
callq 0x23f4
movl $0x1, %ebp
jmp 0x2ebe
leaq 0x54e5(%rip), %rdi      # 0x8131
callq 0x2060
xorl %ebp, %ebp
jmp 0x2ebe
cmpl $0x0, 0x20(%rsp)
jne 0x2c79
movl 0x4(%rsp), %r12d
movq 0x18(%rsp), %r14
cltq
movq (%rbx,%rax,8), %rdi
callq 0x33b4
xorl %r15d, %r15d
jmp 0x2c9a
cltq
movq (%rbx,%rax,8), %rdi
leaq 0x59ba(%rip), %rsi      # 0x8640
callq 0x2250
movq %rax, %r15
xorl %eax, %eax
movl 0x4(%rsp), %r12d
movq 0x18(%rsp), %r14
movl %r12d, 0x4(%rsp)
testq %r14, %r14
movq %rax, 0x68(%rsp)
jne 0x2cae
xorl %r14d, %r14d
jmp 0x2cc0
leaq 0x598e(%rip), %rsi      # 0x8643
movq %r14, %rdi
callq 0x2250
movq %rax, %r14
leal -0x1(%rbp), %r13d
leaq 0x84c5(%rip), %r12      # 0xb190
movq %rbp, 0x18(%rsp)
movq %r15, 0x20(%rsp)
movq %r14, 0x78(%rsp)
movq %r13, 0x70(%rsp)
movq %rbx, 0x50(%rsp)
testq %r15, %r15
je 0x2cf3
movq %r15, %rdi
callq 0x45c7
jmp 0x2d31
movq 0x68(%rsp), %rdi
callq 0x392e
testl %eax, %eax
jne 0x2dfe
movq 0x68(%rsp), %rdi
movl 0x2c(%rsp), %esi
movl 0x8(%rsp), %edx
movl 0x14(%rsp), %ecx
movl 0x4(%rsp), %r8d
movl 0xc(%rsp), %r9d
pushq 0x58(%rsp)
pushq 0x68(%rsp)
callq 0x3f6b
addq $0x10, %rsp
movq %rax, %r15
testq %rax, %rax
je 0x2dfe
cmpl $0x3, (%r12)
jge 0x2de4
movq %r15, %rdi
movss 0x10(%rsp), %xmm0
callq 0x3f58
cmpl $0x3, (%r12)
jge 0x2df1
testq %r14, %r14
je 0x2d71
movq %r14, %rdi
movq %r15, %rsi
callq 0x43d2
movq 0x8258(%rip), %rax      # 0xafd0
movslq (%rax), %rbp
leal 0x1(%rbp), %eax
cmpl 0x18(%rsp), %eax
movl 0xc(%rsp), %r12d
movl 0x4(%rsp), %r14d
leaq 0x30(%rsp), %r13
movq %r15, %rbx
movq %r13, %r15
movq 0x70(%rsp), %r13
jge 0x2dc1
movq 0x50(%rsp), %rax
movq 0x8(%rax,%rbp,8), %rsi
movq %rbx, %rdi
movq %r15, %rdx
movl %r12d, %ecx
movl %r14d, %r8d
callq 0x641d
incq %rbp
cmpl %ebp, %r13d
jne 0x2d9e
movq %rbx, %rdi
callq 0x3c01
movq 0x50(%rsp), %rbx
movq 0x20(%rsp), %r15
movq 0x78(%rsp), %r14
leaq 0x83b1(%rip), %r12      # 0xb190
jmp 0x2ce4
movq %r15, %rdi
callq 0x2310
jmp 0x2d48
movq %r15, %rdi
callq 0x2385
jmp 0x2d61
testq %r14, %r14
je 0x2e0b
movq %r14, %rdi
callq 0x20c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
leaq 0x848e(%rip), %r12      # 0xb2a8
movq 0x68(%rsp), %r14
je 0x2e26
callq 0x20c0
testq %r14, %r14
je 0x2e33
movq %r14, %rdi
callq 0x346f
movq 0x81be(%rip), %r15      # 0xaff8
movq (%r15), %rdi
leaq 0x5884(%rip), %rsi      # 0x86c8
leaq 0x5840(%rip), %r14      # 0x868b
leaq 0x52df(%rip), %rcx      # 0x8131
xorl %ebp, %ebp
movq %r14, %rdx
xorl %eax, %eax
callq 0x2180
movq (%r15), %rdi
leaq 0x5875(%rip), %rsi      # 0x86dd
movq %r14, %rdx
xorl %eax, %eax
callq 0x2180
movq 0x18(%rsp), %rdi
testl %edi, %edi
jle 0x2e83
movq %rbx, %rsi
callq 0x23b0
movq (%r15), %rbx
callq 0x2f73
subsd (%r12), %xmm0
movsd %xmm0, 0x50(%rsp)
callq 0x2f30
movapd %xmm0, %xmm1
leaq 0x5847(%rip), %rsi      # 0x86ee
leaq 0x57dd(%rip), %rdx      # 0x868b
movq %rbx, %rdi
movsd 0x50(%rsp), %xmm0
movb $0x2, %al
callq 0x2180
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x80f7(%rip), %rax      # 0xafd0
movl (%rax), %eax
movss 0x5121(%rip), %xmm0     # 0x8004
movss %xmm0, 0x10(%rsp)
movl $0x3, %edx
movl $0xf, 0x8(%rsp)
cmpl %ebp, %eax
je 0x2c27
movl $0x3, 0xc(%rsp)
movl $0xa, 0x2c(%rsp)
movl $0xe, 0x14(%rsp)
movl $0x1, %ecx
movq %rcx, 0x58(%rsp)
movl $0x5f5e100, %r12d       # imm = 0x5F5E100
xorl %r14d, %r14d
jmp 0x2c69
nop