// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movw $0x0, -0x22(%rbp)
movl $0xfa, -0x28(%rbp)
movl $0x2710, -0x2c(%rbp)    # imm = 0x2710
movl $0x1, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x1824(%rip), %rdx      # 0xf8cd
callq 0x1190
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
jl 0xe12b
cmpl $0x6f, -0x38(%rbp)
jne 0xe0d0
movq 0x4f15(%rip), %rax      # 0x12fd8
movq (%rax), %rdi
callq 0x11b0
movl %eax, -0x28(%rbp)
jmp 0xe126
cmpl $0x6c, -0x38(%rbp)
jne 0xe0ea
movq 0x4efb(%rip), %rax      # 0x12fd8
movq (%rax), %rdi
callq 0x11b0
movl %eax, -0x2c(%rbp)
jmp 0xe124
cmpl $0x75, -0x38(%rbp)
jne 0xe0f9
movl $0x1, -0x34(%rbp)
jmp 0xe122
cmpl $0x56, -0x38(%rbp)
jne 0xe120
leaq 0x1964(%rip), %rdi      # 0xfa6a
leaq 0x17c7(%rip), %rsi      # 0xf8d4
movb $0x0, %al
callq 0x1060
movl $0x0, -0x4(%rbp)
jmp 0xe485
jmp 0xe122
jmp 0xe124
jmp 0xe126
jmp 0xe09b
movl -0x8(%rbp), %eax
movq 0x4e9b(%rip), %rcx      # 0x12fd0
subl (%rcx), %eax
cmpl $0x1, %eax
jl 0xe1c5
movq -0x10(%rbp), %rax
movq 0x4e85(%rip), %rcx      # 0x12fd0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movl -0x8(%rbp), %eax
movq 0x4e70(%rip), %rcx      # 0x12fd0
subl (%rcx), %eax
cmpl $0x1, %eax
jle 0xe1c0
movl $0x0, -0x30(%rbp)
movl -0x8(%rbp), %eax
movq 0x4e58(%rip), %rcx      # 0x12fd0
subl (%rcx), %eax
subl $0x1, %eax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x1130
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq 0x4e2d(%rip), %rax      # 0x12fd0
movl (%rax), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
movzwl -0x22(%rbp), %eax
movl %eax, %edx
shlq $0x3, %rdx
callq 0x1110
jmp 0xe261
movq 0x4e2c(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1702(%rip), %rsi      # 0xf8d8
movb $0x0, %al
callq 0x10f0
movq 0x4e14(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x172c(%rip), %rsi      # 0xf91a
movb $0x0, %al
callq 0x10f0
movq 0x4dfc(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x171e(%rip), %rsi      # 0xf924
movb $0x0, %al
callq 0x10f0
movq 0x4de4(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1732(%rip), %rsi      # 0xf950
movb $0x0, %al
callq 0x10f0
movq 0x4dcc(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1741(%rip), %rsi      # 0xf977
movb $0x0, %al
callq 0x10f0
movq 0x4db4(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1748(%rip), %rsi      # 0xf996
movb $0x0, %al
callq 0x10f0
movl $0x1, -0x4(%rbp)
jmp 0xe485
movb $0x0, %al
callq 0x13f0
callq 0x1470
movq %rax, -0x40(%rbp)
movq 0x4d80(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1741(%rip), %rsi      # 0xf9c3
leaq 0x176c(%rip), %rdx      # 0xf9f5
movb $0x0, %al
callq 0x10f0
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x2c(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0xc940
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0xe302
movq 0x4d3c(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x1734(%rip), %rsi      # 0xf9fa
leaq 0x1728(%rip), %rdx      # 0xf9f5
movb $0x0, %al
callq 0x10f0
movq -0x20(%rbp), %rdi
movzwl -0x22(%rbp), %eax
movl %eax, %esi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
movl -0x34(%rbp), %r8d
callq 0xd950
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
callq 0x1040
jmp 0xe339
movq 0x4cef(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x171b(%rip), %rsi      # 0xfa2e
leaq 0x16db(%rip), %rdx      # 0xf9f5
movb $0x0, %al
callq 0x10f0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
movl -0x34(%rbp), %edx
callq 0xddb0
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0xc6d0
movq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
callq 0xbd10
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0xb7b0
movq -0x58(%rbp), %rdi
callq 0x1040
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jae 0xe3a7
movq -0x50(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x1040
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xe375
movq -0x50(%rbp), %rdi
callq 0x1040
movq -0x40(%rbp), %rdi
callq 0x14d0
movq 0x4c38(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x168f(%rip), %rsi      # 0xfa59
leaq 0x1624(%rip), %rdx      # 0xf9f5
leaq 0x14fc(%rip), %rcx      # 0xf8d4
movb $0x0, %al
callq 0x10f0
movq 0x4c12(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
leaq 0x167e(%rip), %rsi      # 0xfa6e
leaq 0x15fe(%rip), %rdx      # 0xf9f5
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xe43c
movq 0x4be4(%rip), %rax      # 0x12ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x64(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x1651(%rip), %rsi      # 0xfa7b
movb $0x0, %al
callq 0x10f0
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xe405
movq 0x4bb5(%rip), %rax      # 0x12ff8
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movb $0x0, %al
callq 0x1370
movsd %xmm0, -0x70(%rbp)
movb $0x0, %al
callq 0x1310
movq -0x78(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
leaq 0x160f(%rip), %rsi      # 0xfa7f
leaq 0x157e(%rip), %rdx      # 0xf9f5
movb $0x2, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq