// File: /workspace/github_c_makefile_star2_O0/nh13[P]ksw/src/main.c
// Function: main
int main(int argc, char *argv[])
{
	main_opt_t * opt = NULL;
	int c;
	ksw_extz_t ez;
	alignment_t *alignment = alignment_init();

	memset(&ez, 0, sizeof(ksw_extz_t));

	opt = main_opt_init();

	// FIXME: for local or glocal we don't the query/target starts unless we output the cigar
	while ((c = getopt(argc, argv, "M:a:b:q:r:w:m:csHROl:h")) >= 0) {
		switch (c) {
			case 'M': opt->alignment_mode = atoi(optarg); break;
			case 'a': opt->match_score = atoi(optarg); break;
			case 'b': opt->mismatch_score = atoi(optarg); break;
			case 'q': opt->gap_open = atoi(optarg); break;
			case 'r': opt->gap_extend = atoi(optarg); break;
			case 'w': opt->band_width = atoi(optarg); break;
			case 'm': opt->matrix_fn = optarg; break; 
			case 'c': opt->add_cigar = 1; break;
			case 's': opt->add_seq = 1; break;
			case 'H': opt->add_header = 1; break;
			case 'R': opt->right_align_gaps = 1; break;
			case 'O': opt->offset_and_length = 1; break;
			case 'l': opt->library = atoi(optarg); break;
			case 'h': usage(opt); return 1;
			default: usage(opt); return 1;
		}
	}
	if (optind > argc) {
		usage(opt);
		return 1;
	}

	// validate args
	main_opt_validate(opt);
	
	// set the library data **after** setting the scoring matrix
	main_opt_init_library(opt);

	// output the header
	if (opt->add_header) {
		// based output format
		if (opt->offset_and_length == 1) fprintf(stdout, "score\tquery_offset\tquery_length\ttarget_offset\ttarget_length");
		else fprintf(stdout, "score\tquery_start\tquery_end\ttarget_start\ttarget_end");
		// append the cigar
		if (opt->add_cigar == 1) fprintf(stdout, "\tcigar");
		// append the query and target sequence
		if (opt->add_seq) fprintf(stdout, "\tquery\ttarget");
		fputc('\n', stdout);
	}

	// read a query and target at a time
	kstream_t *fp     = ks_init(fileno(stdin));
	kstring_t *query  = (kstring_t*)calloc(1, sizeof(kstring_t));
	kstring_t *target = (kstring_t*)calloc(1, sizeof(kstring_t));
	int retval = 0;
	while (ks_getuntil(fp, 0, query, &retval) > 0 && ks_getuntil(fp, 0, target, &retval) > 0) {
		align(query->s, target->s, opt, alignment);
	}
	free(query->s);
	free(query);
	free(target->s);
	free(target);
	ks_destroy(fp);

	// clean up
	alignment_destroy(alignment);
	main_opt_destroy(opt);

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
callq 0x1b8bd0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x19e070
callq 0x1b7e10
movq %rax, -0x18(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xad48e6(%rip), %rdx    # 0xc8dc57
callq 0x19e030
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
jl 0x1b94f9
movl -0x1c(%rbp), %eax
addl $-0x48, %eax
movl %eax, %ecx
movq %rcx, -0x80(%rbp)
subl $0x2f, %eax
ja 0x1b94df
movq -0x80(%rbp), %rax
leaq 0xad4052(%rip), %rcx    # 0xc8d3f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xc6dc0e(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0x1b94f4
movq 0xc6dbf1(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1b94f4
movq 0xc6dbd5(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x1b94f4
movq 0xc6dbb8(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x1b94f4
movq 0xc6db9b(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x1b94f4
movq 0xc6db7e(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x1b94f4
movq 0xc6db61(%rip), %rax    # 0xe26fc0
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rax
movl $0x1, 0x24(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rax
movl $0x1, 0x28(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rax
movl $0x1, 0x2c(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rax
movl $0x1, 0x30(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rax
movl $0x1, 0x34(%rax)
jmp 0x1b94f4
movq 0xc6db09(%rip), %rax    # 0xe26fc0
movq (%rax), %rdi
callq 0x19e1b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
jmp 0x1b94f4
movq -0x18(%rbp), %rdi
callq 0x1b8f10
movl $0x1, -0x4(%rbp)
jmp 0x1b96d1
movq -0x18(%rbp), %rdi
callq 0x1b8f10
movl $0x1, -0x4(%rbp)
jmp 0x1b96d1
jmp 0x1b9363
movq 0xc6dae0(%rip), %rax    # 0xe26fe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jle 0x1b951c
movq -0x18(%rbp), %rdi
callq 0x1b8f10
movl $0x1, -0x4(%rbp)
jmp 0x1b96d1
movq -0x18(%rbp), %rdi
callq 0x1b8990
movq -0x18(%rbp), %rdi
callq 0x1b7ed0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x1b95d0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x34(%rax)
jne 0x1b9560
movq 0xc6da63(%rip), %rax    # 0xe26fb0
movq (%rax), %rdi
leaq 0xad4717(%rip), %rsi    # 0xc8dc6e
movb $0x0, %al
callq 0x19e180
jmp 0x1b9578
movq 0xc6da49(%rip), %rax    # 0xe26fb0
movq (%rax), %rdi
leaq 0xad4739(%rip), %rsi    # 0xc8dcaa
movb $0x0, %al
callq 0x19e180
movq -0x18(%rbp), %rax
cmpl $0x1, 0x24(%rax)
jne 0x1b959a
movq 0xc6da27(%rip), %rax    # 0xe26fb0
movq (%rax), %rdi
leaq 0xad474b(%rip), %rsi    # 0xc8dcde
movb $0x0, %al
callq 0x19e180
movq -0x18(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x1b95bc
movq 0xc6da05(%rip), %rax    # 0xe26fb0
movq (%rax), %rdi
leaq 0xad4730(%rip), %rsi    # 0xc8dce5
movb $0x0, %al
callq 0x19e180
movq 0xc6d9ed(%rip), %rax    # 0xe26fb0
movq (%rax), %rsi
movl $0xa, %edi
callq 0x19e140
movq 0xc6d9f9(%rip), %rax    # 0xe26fd0
movq (%rax), %rdi
callq 0x19e0e0
movl %eax, %edi
callq 0x1b96e0
movq %rax, -0x60(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x19e090
movq %rax, -0x68(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x19e090
movq %rax, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rdx
xorl %esi, %esi
leaq -0x74(%rbp), %rcx
callq 0x1b9730
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
jle 0x1b9658
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rdx
xorl %esi, %esi
leaq -0x74(%rbp), %rcx
callq 0x1b9730
cmpl $0x0, %eax
setg %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x1b9664
jmp 0x1b9683
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x1b8e20
jmp 0x1b9617
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x19e120
movq -0x68(%rbp), %rdi
callq 0x19e120
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x19e120
movq -0x70(%rbp), %rdi
callq 0x19e120
movq -0x60(%rbp), %rdi
callq 0x1b9770
movq -0x58(%rbp), %rdi
callq 0x1b8df0
movq -0x18(%rbp), %rdi
callq 0x1b8810
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)