// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movl $0x0, (%rsp)
movl $0x2710, %r12d          # imm = 0x2710
movl $0xfa, %r15d
leaq 0x1a23(%rip), %r13      # 0x9961
movq 0x5093(%rip), %rbp      # 0xcfd8
movl %r14d, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x11a0
testl %eax, %eax
js 0x7fae
cmpl $0x56, %eax
je 0x7f8f
cmpl $0x6c, %eax
je 0x7f79
cmpl $0x75, %eax
je 0x7f87
cmpl $0x6f, %eax
jne 0x7f45
movq (%rbp), %rdi
callq 0x11c0
movl %eax, %r15d
jmp 0x7f45
movq (%rbp), %rdi
callq 0x11c0
movl %eax, %r12d
jmp 0x7f45
pushq $0x1
popq %rax
movl %eax, (%rsp)
jmp 0x7f45
leaq 0x19d2(%rip), %rdi      # 0x9968
callq 0x1050
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x501b(%rip), %rax      # 0xcfd0
movslq (%rax), %rax
movl %r14d, %edx
subl %eax, %edx
jle 0x80a2
movq (%rbx,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
xorl %ebp, %ebp
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
cmpl $0x1, %edx
je 0x801d
leaq (%rbx,%rax,8), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
decl %eax
movzwl %ax, %ebp
movl %ebp, %r13d
shll $0x3, %r13d
movq %r13, %rdi
callq 0x1140
movq 0x8(%rsp), %rsi
addq $0x8, %rsi
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r13, %rdx
callq 0x1120
movq %rbp, 0x18(%rsp)
xorl %eax, %eax
callq 0x13dd
callq 0x143c
movq %rax, %r13
movq 0x4fc0(%rip), %rbp      # 0xcff8
movq (%rbp), %rdi
leaq 0x1a14(%rip), %rsi      # 0x9a57
leaq 0x1a3f(%rip), %rdx      # 0x9a89
xorl %eax, %eax
callq 0x1100
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x73cd
movq %rax, %r15
movq (%rbp), %rdi
cmpl $0x1, 0x10(%rsp)
jne 0x8132
leaq 0x1a45(%rip), %rsi      # 0x9ac2
leaq 0x1a05(%rip), %rdx      # 0x9a89
xorl %eax, %eax
callq 0x1100
movl (%r13), %esi
movq %r15, %rdi
movl (%rsp), %edx
callq 0x7da4
movq %rax, %r12
jmp 0x816f
movq 0x4f4f(%rip), %r14      # 0xcff8
movq (%r14), %rcx
leaq 0x18b9(%rip), %rdi      # 0x996c
pushq $0x41
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x11f0
movq (%r14), %rcx
leaq 0x18e3(%rip), %rdi      # 0x99ae
pushq $0x9
popq %rsi
movq %rbx, %rdx
callq 0x11f0
movq (%r14), %rcx
leaq 0x18d8(%rip), %rdi      # 0x99b8
pushq $0x2b
popq %rsi
movq %rbx, %rdx
callq 0x11f0
movq (%r14), %rcx
leaq 0x18ef(%rip), %rdi      # 0x99e4
pushq $0x26
popq %rsi
movq %rbx, %rdx
callq 0x11f0
movq (%r14), %rcx
leaq 0x1901(%rip), %rdi      # 0x9a0b
pushq $0x1e
popq %rsi
movq %rbx, %rdx
callq 0x11f0
movq (%r14), %rcx
leaq 0x190b(%rip), %rdi      # 0x9a2a
pushq $0x2c
popq %rsi
movq %rbx, %rdx
callq 0x11f0
pushq $0x1
popq %rbx
jmp 0x7f9d
leaq 0x1955(%rip), %rsi      # 0x9a8e
leaq 0x1949(%rip), %rdx      # 0x9a89
xorl %eax, %eax
callq 0x1100
movl (%r13), %ecx
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movl (%rsp), %r8d
callq 0x7b4c
movq %rax, %r12
movq %rbp, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x722c
movl (%r13), %esi
movq %r12, %rdi
callq 0x6d6b
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
callq 0x6a4b
movq %r15, %rdi
callq 0x1040
leaq 0x10(%r12), %r15
xorl %ebp, %ebp
movl (%r13), %eax
cmpq %rax, %rbp
jae 0x81ba
movq (%r15), %rdi
callq 0x1040
incq %rbp
addq $0x18, %r15
jmp 0x81a0
movq %r12, %rdi
callq 0x1040
movq %r13, %rdi
callq 0x1464
movq 0x4e27(%rip), %rbp      # 0xcff8
movq (%rbp), %rdi
leaq 0x1911(%rip), %rsi      # 0x9aed
leaq 0x18a6(%rip), %r15      # 0x9a89
leaq 0x177e(%rip), %rcx      # 0x9968
xorl %r12d, %r12d
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbp), %rdi
leaq 0x1900(%rip), %rsi      # 0x9b02
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
testl %r14d, %r14d
cmovlel %r12d, %r14d
leaq 0x18f5(%rip), %r12      # 0x9b0f
xorl %r13d, %r13d
movq (%rbp), %r15
cmpq %r13, %r14
je 0x823c
movq (%rbx,%r13,8), %rdx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1100
incq %r13
jmp 0x821d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x136f
movsd %xmm0, (%rsp)
xorl %eax, %eax
callq 0x132c
movaps %xmm0, %xmm1
leaq 0x18b8(%rip), %rsi      # 0x9b13
leaq 0x1827(%rip), %rdx      # 0x9a89
movq %r15, %rdi
movsd (%rsp), %xmm0
movb $0x2, %al
callq 0x1100
jmp 0x7f9d