// File: /workspace/github_c_makefile_star2_O1/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 0x1ad0(%rip), %rdx      # 0xa991
callq 0x11a0
testl %eax, %eax
js 0x8f61
movl $0xfa, %r15d
movl $0x2710, %r12d          # imm = 0x2710
movl $0x0, 0x8(%rsp)
movq 0x50ef(%rip), %r14      # 0xdfd8
leaq 0x1aa1(%rip), %r13      # 0xa991
cmpl $0x6e, %eax
jle 0x8f0c
cmpl $0x75, %eax
je 0x8f1e
cmpl $0x6f, %eax
jne 0x8f2d
movq (%r14), %rdi
callq 0x11c0
movl %eax, %r15d
jmp 0x8f2d
cmpl $0x6c, %eax
jne 0x8f28
movq (%r14), %rdi
callq 0x11c0
movl %eax, %r12d
jmp 0x8f2d
movl $0x1, 0x8(%rsp)
jmp 0x8f2d
cmpl $0x56, %eax
je 0x8f40
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x11a0
testl %eax, %eax
jns 0x8ef0
jmp 0x8f75
leaq 0x1a51(%rip), %rdi      # 0xa998
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 0x5054(%rip), %rax      # 0xdfd0
movslq (%rax), %rax
movl %ebp, %r14d
subl %eax, %r14d
jle 0x9066
movq (%rbx,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
cmpl $0x1, %r14d
je 0x8fe8
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 0x2cca
callq 0x2de0
movq %rax, %r13
movq 0x4ffa(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x1a7f(%rip), %rsi      # 0xaa87
leaq 0x1aaa(%rip), %rdx      # 0xaab9
xorl %eax, %eax
callq 0x1100
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x84fe
movq %rax, %r15
movq 0x4fc5(%rip), %rax      # 0xdff8
movq (%rax), %rdi
cmpl $0x1, %r14d
jne 0x9076
leaq 0x1aaf(%rip), %rsi      # 0xaaf2
leaq 0x1a6f(%rip), %rdx      # 0xaab9
xorl %eax, %eax
callq 0x1100
movl (%r13), %esi
movq %r15, %rdi
movl 0x8(%rsp), %edx
callq 0x2896
movq %rax, %r14
jmp 0x90b4
callq 0x2a4e
movl $0x1, %r14d
jmp 0x8f4f
leaq 0x1a41(%rip), %rsi      # 0xaabe
leaq 0x1a35(%rip), %rdx      # 0xaab9
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 0x8cb0
movq %rax, %r14
movq %r12, %rdi
callq 0x1040
movq %r15, %rdi
callq 0x832c
movl (%r13), %esi
movq %r14, %rdi
callq 0x82a8
movq %rax, %r15
movq %r13, %rdi
movq %rax, %rsi
callq 0x81b8
movq %r15, %rdi
callq 0x1040
cmpl $0x0, (%r13)
je 0x9104
leaq 0x10(%r14), %r15
xorl %r12d, %r12d
movq (%r15), %rdi
callq 0x1040
incq %r12
movl (%r13), %eax
addq $0x18, %r15
cmpq %rax, %r12
jb 0x90ec
movq %r14, %rdi
callq 0x1040
movq %r13, %rdi
callq 0x2e0b
movq 0x4edd(%rip), %r12      # 0xdff8
movq (%r12), %rdi
leaq 0x19f7(%rip), %rsi      # 0xab1d
leaq 0x198c(%rip), %r15      # 0xaab9
leaq 0x1864(%rip), %rcx      # 0xa998
xorl %r14d, %r14d
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
movq (%r12), %rdi
leaq 0x19e6(%rip), %rsi      # 0xab32
movq %r15, %rdx
xorl %eax, %eax
callq 0x1100
testl %ebp, %ebp
jle 0x9164
movl %ebp, %edi
movq %rbx, %rsi
callq 0x2ae1
movq (%r12), %rbx
xorl %eax, %eax
callq 0x2c5f
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0x2c1c
movaps %xmm0, %xmm1
leaq 0x19bd(%rip), %rsi      # 0xab43
leaq 0x192c(%rip), %rdx      # 0xaab9
movq %rbx, %rdi
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x1100
jmp 0x8f4f