// File: /workspace/github_c_makefile_star2_O3/rikuu[P]kermit/kermit-color.c
// Function: main
int main(int argc, char *argv[])
{
	char *paf_fn = 0, **map_fns = 0;
	uint16_t n_maps = 0;
	uint32_t max_overhang = 250, bin_length = 10000;
	int reference_only = 1, unicolor = 0, c;

	while ((c = getopt(argc, argv, "o:l:Vu")) >= 0) {
		if (c == 'o') max_overhang = atoi(optarg);
		else if (c == 'l') bin_length = atoi(optarg);
		else if (c == 'u') unicolor = 1;
		else if (c == 'V') {
			printf("%s\n", KM_VERSION);
			return 0;
		}
	}

	if (argc - optind >= 1) {
		paf_fn = argv[optind];

		if (argc - optind > 1) {
			reference_only = 0;
			n_maps = argc - optind - 1;
			map_fns = (char**) malloc(sizeof(char*) * n_maps);
			memcpy(map_fns, argv + (optind + 1), sizeof(char*) * n_maps);
		}
	} else {
		fprintf(stderr, "Usage: kermit-color [options] <in.paf> <markers> [<markers2>,..]\n");
		fprintf(stderr, "Options:\n");
		fprintf(stderr, " -V          print version number and exit\n");
		fprintf(stderr, " -o [INT]    max extension of mapping\n");
		fprintf(stderr, " -l [INT]    index bin length\n");
		fprintf(stderr, " -u          assign single color per contig\n");
		return 1;
	}

	sys_init();
	sdict_t *d = sd_init();

	fprintf(stderr, "[M::%s] ===> Step 1: indexing read mappings <===\n", __func__);
	km_idx_t *idx = km_build_idx(paf_fn, d, bin_length, max_overhang);

	km_multicolor_t *multicolors = 0;
	if (!reference_only) {
		fprintf(stderr, "[M::%s] ===> Step 2: mapping markers to reads <===\n", __func__);
		multicolors = km_align_markers(map_fns, n_maps, idx, d->n_seq, unicolor);
		free(map_fns);
	} else {
		fprintf(stderr, "[M::%s] ===> Step 2: reversing index <===\n", __func__);
		multicolors = km_align_reference(idx, d->n_seq, unicolor);
	}

	km_idx_destroy(idx);

	km_color_t *colors = km_intervalize(multicolors, d->n_seq);
	km_cf_print(d, colors);
	free(colors);

	for (size_t i = 0; i < d->n_seq; i++)
		free(multicolors[i].a);
	free(multicolors);

	sd_destroy(d);

	fprintf(stderr, "[M::%s] Version: %s\n", __func__, KM_VERSION);
	fprintf(stderr, "[M::%s] CMD:", __func__);
	for (int i = 0; i < argc; ++i)
		fprintf(stderr, " %s", argv[i]);
	fprintf(stderr, "\n[M::%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, sys_realtime(), sys_cputime());
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x1a64(%rip), %rdx      # 0xa961
callq 0x11a0
testl %eax, %eax
js 0x8f9d
movl $0xfa, %r15d
movl $0x2710, %r12d          # imm = 0x2710
movl $0x0, 0x8(%rsp)
movq 0x50b3(%rip), %r14      # 0xdfd8
leaq 0x1a35(%rip), %r13      # 0xa961
cmpl $0x6e, %eax
jle 0x8f48
cmpl $0x75, %eax
je 0x8f5a
cmpl $0x6f, %eax
jne 0x8f69
movq (%r14), %rdi
callq 0x11c0
movl %eax, %r15d
jmp 0x8f69
cmpl $0x6c, %eax
jne 0x8f64
movq (%r14), %rdi
callq 0x11c0
movl %eax, %r12d
jmp 0x8f69
movl $0x1, 0x8(%rsp)
jmp 0x8f69
cmpl $0x56, %eax
je 0x8f7c
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x11a0
testl %eax, %eax
jns 0x8f2c
jmp 0x8fb1
leaq 0x19e5(%rip), %rdi      # 0xa968
callq 0x1050
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x8(%rsp)
movl $0x2710, %r12d          # imm = 0x2710
movl $0xfa, %r15d
movq 0x5018(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
movl %ebp, %r14d
subl %eax, %r14d
jle 0x90a2
movq (%rbx,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
cmpl $0x1, %r14d
je 0x9024
leaq (%rbx,%rax,8), %rax
movq %rax, 0x10(%rsp)
leal -0x1(%r14), %eax
movzwl %ax, %r13d
movq %r13, 0x18(%rsp)
shll $0x3, %r13d
movq %r13, %rdi
callq 0x1140
movq 0x10(%rsp), %rsi
addq $0x8, %rsi
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movq %r13, %rdx
callq 0x1120
xorl %eax, %eax
callq 0x2c3a
callq 0x2d50
movq %rax, %r13
movq 0x4fbe(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x1a13(%rip), %rsi      # 0xaa57
leaq 0x1a3e(%rip), %rdx      # 0xaa89
xorl %eax, %eax
callq 0x1100
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x852a
movq %rax, %r15
movq 0x4f89(%rip), %rax      # 0xdff8
movq (%rax), %rdi
cmpl $0x1, %r14d
jne 0x90b2
leaq 0x1a43(%rip), %rsi      # 0xaac2
leaq 0x1a03(%rip), %rdx      # 0xaa89
xorl %eax, %eax
callq 0x1100
movl (%r13), %esi
movq %r15, %rdi
movl 0x8(%rsp), %edx
callq 0x27f8
movq %rax, %r14
jmp 0x90f0
callq 0x29be
movl $0x1, %r14d
jmp 0x8f8b
leaq 0x19d5(%rip), %rsi      # 0xaa8e
leaq 0x19c9(%rip), %rdx      # 0xaa89
xorl %eax, %eax
callq 0x1100
movl (%r13), %ecx
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movl 0x8(%rsp), %r8d
callq 0x8ce4
movq %rax, %r14
movq %r12, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x834c
movl (%r13), %esi
movq %r14, %rdi
callq 0x82c7
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
callq 0x80f4
movq %r15, %rdi
callq 0x1040
cmpl $0x0, (%r13)
je 0x9140
leaq 0x10(%r14), %r15
xorl %r12d, %r12d
movq (%r15), %rdi
callq 0x1040
incq %r12
movl (%r13), %eax
addq $0x18, %r15
cmpq %rax, %r12
jb 0x9128
movq %r14, %rdi
callq 0x1040
movq %r13, %rdi
callq 0x2d7b
movq 0x4ea1(%rip), %r12      # 0xdff8
movq (%r12), %rdi
leaq 0x198b(%rip), %rsi      # 0xaaed
leaq 0x1920(%rip), %r15      # 0xaa89
leaq 0x17f8(%rip), %rcx      # 0xa968
xorl %r14d, %r14d
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
movq (%r12), %rdi
leaq 0x197a(%rip), %rsi      # 0xab02
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
testl %ebp, %ebp
jle 0x91a0
movl %ebp, %edi
movq %rbx, %rsi
callq 0x2a51
movq (%r12), %rbx
xorl %eax, %eax
callq 0x2bcf
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0x2b8c
movaps %xmm0, %xmm1
leaq 0x1951(%rip), %rsi      # 0xab13
leaq 0x18c0(%rip), %rdx      # 0xaa89
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x1100
jmp 0x8f8b