// File: /workspace/github_cpp_makefile_star2_O2/CK7[P]abawaca/src/abawaca.cpp
// Function: Prog_params::read_params(int, char const**)
int Prog_params::read_params(int argc, const char** argv)
{
	if((argc == 1) || ((argc == 2) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) {
		usage(argv[0]);
		return -1;
	}

	// Read parameters
	for(auto i=1; i<argc; i++) {
		if(!strcmp(argv[i], "-u")) {
			abawaca_build_dir = argv[++i];
			char data_file[2048];
			sprintf(data_file, "%s/data.txt", abawaca_build_dir.c_str());
			FILE* fp = fopen(data_file, "r");
			if(fp == NULL) {
				cerr << "Error: could not find " << abawaca_build_dir << "/data.txt. Is it possible that the data was generated using an old version of abawaca-build? (prior to v1.07)" << endl << endl; 
				return -1;
			}
			char line[8192];
			while(fgets(line, 8192, fp)) {
				char* p = strrchr(line, '\n');
				while((p != NULL) && (*p == '\n'))  {
					*(p--) = 0;
				}
				p=strchr(line, '\t');
				*(p++) = 0;
				while(isspace(*p) && (*p != 0))
					p++;

				if(!strcmp(line, "Links")) {
					links_file = p;
				}
				else if(!strcmp(line, "Info")) {
					info_file = p;
				}
				else if(!strcmp(line, "Names")) {
					names_file = p;
				}
				else if(!strcmp(line, "Lrn")) {
					lrn_file = p;
				}
				else if(!strcmp(line, "Assembly")) {
					fasta_file = p;
				}
				else if(!strcmp(line, "SCG")) {
					gene2scg_file = p;
				}
			}
/*			lrn_file = abawaca_build_dir + "/abawaca.lrn";
			names_file = abawaca_build_dir + "/abawaca.names";
			info_file = abawaca_build_dir + "/abawaca.info";
			links_file = abawaca_build_dir + "/abawaca.links";*/
		}
		else if(!strcmp(argv[i], "-f"))
			fasta_file = argv[++i];
		else if(!strcmp(argv[i], "-o"))
			root_dir = argv[++i];
		else if(!strcmp(argv[i], "-p")) {
			ncpus = atoi(argv[++i]);
			if(ncpus==0 || ncpus>40) {
				cerr << "Error: # CPUs (" << argv[i] << ") must be an integer between 1 to 40" << endl << endl;
				return -1; 
			}
		}
		else if(!strcmp(argv[i], "-c"))
			gene2scg_file = argv[++i];
		else {
			cerr << "Unrecognizes flag: " << argv[i] << endl;
			return -1;
		}
	}

	// Make sure we have everything we need
	if(lrn_file == "") {
		cerr << "abawaca-build directrory was not specified (-u)" << endl << endl;
		return -1;
	}

	FILE* IN = fopen(names_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read names file (" << names_file << ") from the abawaca directory (" << abawaca_build_dir << ")" << endl;
		return -1;
	}
	fclose(IN);

	IN = fopen(lrn_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read lrn file (" << lrn_file << ") from the abawaca directory (" << abawaca_build_dir << ")" << endl;
		return -1;
	}
	fclose(IN);

	IN = fopen(info_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read info file (" << info_file << ") from the abawaca directory (" << abawaca_build_dir << ")" << endl;
		return -1;
	}
	fclose(IN);

	IN = fopen(links_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read links file (" << links_file << ") from the abawaca directory (" << abawaca_build_dir << ")" << endl;
		return -1;
	}
	fclose(IN);

	IN = fopen(fasta_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read " << fasta_file << endl;
		return -1;
	}
	fclose(IN);

	if(gene2scg_file.size() > 0) {
		IN = fopen(gene2scg_file.c_str(), "r");
		if(IN == NULL) {
			cerr << "Could not read " << gene2scg_file << endl;
			return -1;
		}
		fclose(IN);
	}

//	const char* p = strrchr(argv[0], '/');
//	if(p != NULL) {
//		string s = argv[0];
//		scg_list_file = s.substr(0, p-argv[0]+1) + scg_list_file;
//	}
	IN = fopen(scg_list_file.c_str(), "r");
	if(IN == NULL) {
		cerr << "Could not read " << scg_list_file << endl;
		return -1;
	}
	fclose(IN);

	cluster_dir = root_dir + string("/clusters");
	fasta_dir = root_dir + string("/final-clusters");

	char 			line[1024] = {};

	if(!directory_exists(root_dir.c_str())) {
		sprintf(line, "mkdir %s", root_dir.c_str());
		system(line);
	}
	if(!directory_exists(cluster_dir.c_str())) {
		sprintf(line, "mkdir %s", cluster_dir.c_str());
		system(line);
	}
	if(!directory_exists(fasta_dir.c_str())) {
		sprintf(line, "mkdir %s", fasta_dir.c_str());
		system(line);
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2858, %rsp           # imm = 0x2858
movl %esi, -0x3c(%rbp)
cmpl $0x1, %esi
je 0x6468
movq %rdi, %rbx
cmpl $0x2, -0x3c(%rbp)
movq %rdx, -0x50(%rbp)
jne 0x61fe
movq 0x8(%rdx), %rdi
cmpb $0x2d, (%rdi)
jne 0x61e6
cmpb $0x68, 0x1(%rdi)
jne 0x61e6
cmpb $0x0, 0x2(%rdi)
je 0x6468
leaq 0xf06d(%rip), %rsi      # 0x1525a
callq 0x44f0
movq -0x50(%rbp), %rdx
testl %eax, %eax
je 0x6468
leaq 0xc0(%rbx), %r15
leaq 0xa0(%rbx), %rax
movq %rax, -0x48(%rbp)
leaq 0x80(%rbx), %r12
leaq 0x100(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x20(%rbx), %rax
movq %rax, -0x70(%rbp)
leaq 0x40(%rbx), %rax
movq %rax, -0x78(%rbp)
movq %rbx, -0x58(%rbp)
leaq 0x60(%rbx), %rax
movq %rax, -0x80(%rbp)
pushq $0x1
popq %r14
leaq -0x2880(%rbp), %r13
movq %r15, -0x60(%rbp)
movq %r12, -0x68(%rbp)
cmpl -0x3c(%rbp), %r14d
jge 0x649c
movslq %r14d, %rbx
movq (%rdx,%rbx,8), %rax
cmpb $0x2d, (%rax)
jne 0x6475
cmpb $0x75, 0x1(%rax)
jne 0x6277
cmpb $0x0, 0x2(%rax)
je 0x62cb
cmpb $0x66, 0x1(%rax)
jne 0x6287
cmpb $0x0, 0x2(%rax)
je 0x6414
cmpb $0x6f, 0x1(%rax)
jne 0x6297
cmpb $0x0, 0x2(%rax)
je 0x6421
cmpb $0x70, 0x1(%rax)
jne 0x62a7
cmpb $0x0, 0x2(%rax)
je 0x643e
cmpb $0x63, 0x1(%rax)
jne 0x6475
cmpb $0x0, 0x2(%rax)
jne 0x6475
incl %r14d
movq 0x8(%rdx,%rbx,8), %rsi
movq %r15, %rdi
jmp 0x642d
movq 0x8(%rdx,%rbx,8), %rsi
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4700
movq (%rbx), %rdx
leaq -0x880(%rbp), %rbx
movq %rbx, %rdi
leaq 0xef71(%rip), %rsi      # 0x15261
xorl %eax, %eax
callq 0x4080
movq %rbx, %rdi
leaq 0xee30(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x673a
movq %rax, %r12
incl %r14d
movq %r13, %rdi
movl $0x2000, %esi           # imm = 0x2000
movq %r12, %rdx
callq 0x45a0
testq %rax, %rax
je 0x640a
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x43b0
testq %rax, %rax
je 0x634b
cmpb $0xa, (%rax)
jne 0x634b
movb $0x0, (%rax)
decq %rax
jmp 0x6339
movq %r13, %rdi
pushq $0x9
popq %rsi
callq 0x4130
movq %rax, %r15
movb $0x0, (%rax)
movsbl 0x1(%r15), %ebx
incq %r15
movl %ebx, %edi
callq 0x4060
testl %ebx, %ebx
je 0x6373
testl %eax, %eax
jne 0x635c
movq %r13, %rdi
leaq 0xef75(%rip), %rsi      # 0x152f2
pushq $0x6
popq %rdx
callq 0x4370
movq -0x80(%rbp), %rdi
testl %eax, %eax
je 0x63fd
movq %r13, %rdi
leaq 0xef61(%rip), %rsi      # 0x152f8
pushq $0x5
popq %rdx
callq 0x4370
movq -0x78(%rbp), %rdi
testl %eax, %eax
je 0x63fd
movq %r13, %rdi
leaq 0xef4c(%rip), %rsi      # 0x152fd
pushq $0x6
popq %rdx
callq 0x4370
movq -0x70(%rbp), %rdi
testl %eax, %eax
je 0x63fd
movl -0x2880(%rbp), %ebx
movq -0x58(%rbp), %rdi
cmpl $0x6e724c, %ebx         # imm = 0x6E724C
je 0x63fd
movq %r13, %rdi
leaq 0xef26(%rip), %rsi      # 0x15303
pushq $0x9
popq %rdx
callq 0x4370
movq -0x68(%rbp), %rdi
testl %eax, %eax
je 0x63fd
movq -0x60(%rbp), %rdi
cmpl $0x474353, %ebx         # imm = 0x474353
jne 0x6315
movq %r15, %rsi
callq 0x4700
jmp 0x6315
movq -0x60(%rbp), %r15
movq -0x68(%rbp), %r12
jmp 0x6432
incl %r14d
movq 0x8(%rdx,%rbx,8), %rsi
movq %r12, %rdi
jmp 0x642d
incl %r14d
movq 0x8(%rdx,%rbx,8), %rsi
movq -0x48(%rbp), %rdi
callq 0x4700
incl %r14d
movq -0x50(%rbp), %rdx
jmp 0x6251
movq 0x8(%rdx,%rbx,8), %rdi
callq 0x4580
movq -0x58(%rbp), %rcx
movl %eax, 0x160(%rcx)
testl %eax, %eax
je 0x6780
cmpl $0x29, %eax
jge 0x6780
incl %r14d
jmp 0x6432
movq (%rdx), %rsi
callq 0x6ad0
jmp 0x67c5
movq 0x18b6c(%rip), %rdi     # 0x1efe8
leaq 0xeebe(%rip), %rsi      # 0x15341
movq %rdx, %r14
callq 0x4340
movq (%r14,%rbx,8), %rsi
movq %rax, %rdi
callq 0x4340
jmp 0x67bd
movq %r12, %rbx
leaq 0xfd84(%rip), %rsi      # 0x1622a
movq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x7197
testb %al, %al
je 0x64c9
movq 0x18b2b(%rip), %rdi     # 0x1efe8
leaq 0xee91(%rip), %rsi      # 0x15355
jmp 0x67b0
movq -0x70(%rbp), %r14
movq (%r14), %rdi
leaq 0xec5a(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x6727
movq %rax, %rdi
callq 0x4350
movq (%r12), %rdi
leaq 0xec39(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x6762
movq %rax, %rdi
callq 0x4350
movq -0x78(%rbp), %r14
movq (%r14), %rdi
leaq 0xec15(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x67da
movq %rax, %rdi
callq 0x4350
movq -0x80(%rbp), %r14
movq (%r14), %rdi
leaq 0xebf1(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x67ea
movq %rax, %rdi
callq 0x4350
movq (%rbx), %rdi
leaq 0xebd1(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x682f
movq %rax, %rdi
callq 0x4350
cmpq $0x0, 0xc8(%r12)
je 0x65a1
movq (%r15), %rdi
leaq 0xeba6(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x686c
movq %rax, %rdi
callq 0x4350
movq 0xe0(%r12), %rdi
leaq 0xeb81(%rip), %rsi      # 0x15131
callq 0x4400
testq %rax, %rax
je 0x684a
movq %rax, %rdi
callq 0x4350
leaq 0xee54(%rip), %rsi      # 0x15421
leaq -0x880(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4140
leaq -0x2880(%rbp), %rdi
leaq -0x880(%rbp), %rdx
movq -0x48(%rbp), %rsi
callq 0x71a7
leaq 0x120(%r12), %rbx
leaq -0x2880(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4440
movq %r14, %rdi
callq 0x4180
leaq -0x880(%rbp), %rdi
callq 0x4180
leaq 0xee02(%rip), %rsi      # 0x1542b
leaq -0x880(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x4140
leaq -0x2880(%rbp), %rdi
leaq -0x880(%rbp), %rdx
movq -0x48(%rbp), %rsi
callq 0x71a7
leaq 0x140(%r12), %r14
leaq -0x2880(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x4440
movq %r15, %rdi
callq 0x4180
leaq -0x880(%rbp), %rdi
callq 0x4180
leaq -0x2880(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x41f0
movq 0xa0(%r12), %rdi
callq 0x13251
testl %eax, %eax
jne 0x66c2
movq -0x48(%rbp), %rax
movq (%rax), %rdx
leaq 0xed8b(%rip), %rsi      # 0x1543b
movq %r15, %rdi
xorl %eax, %eax
callq 0x4080
movq %r15, %rdi
callq 0x42a0
movq (%rbx), %rdi
callq 0x13251
testl %eax, %eax
jne 0x66f1
movq (%rbx), %rdx
leaq 0xed63(%rip), %rsi      # 0x1543b
leaq -0x2880(%rbp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4080
movq %rbx, %rdi
callq 0x42a0
movq (%r14), %rdi
callq 0x13251
testl %eax, %eax
jne 0x6720
movq (%r14), %rdx
leaq 0xed34(%rip), %rsi      # 0x1543b
leaq -0x2880(%rbp), %rbx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x4080
movq %rbx, %rdi
callq 0x42a0
xorl %eax, %eax
jmp 0x67c8
movq 0x188ba(%rip), %rdi     # 0x1efe8
leaq 0xec50(%rip), %rsi      # 0x15385
jmp 0x67f8
movq 0x188a7(%rip), %rdi     # 0x1efe8
leaq 0xeb25(%rip), %rsi      # 0x1526d
callq 0x4340
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x42d0
leaq 0xeb24(%rip), %rsi      # 0x15284
jmp 0x67ad
movq 0x1887f(%rip), %rdi     # 0x1efe8
leaq 0xec50(%rip), %rsi      # 0x153c0
callq 0x4340
movq %rax, %rdi
movq %r12, %rsi
jmp 0x6803
incq %rbx
movq 0x1885e(%rip), %rdi     # 0x1efe8
leaq 0xeb7b(%rip), %rsi      # 0x1530c
callq 0x4340
movq -0x50(%rbp), %rcx
movq (%rcx,%rbx,8), %rsi
movq %rax, %rdi
callq 0x4340
leaq 0xeb6f(%rip), %rsi      # 0x1531c
movq %rax, %rdi
callq 0x4340
movq %rax, %rdi
callq 0x41a0
movq %rax, %rdi
callq 0x41a0
pushq $-0x1
popq %rax
addq $0x2858, %rsp           # imm = 0x2858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18807(%rip), %rdi     # 0x1efe8
leaq 0xebf2(%rip), %rsi      # 0x153da
jmp 0x67f8
movq 0x187f7(%rip), %rdi     # 0x1efe8
leaq 0xebfd(%rip), %rsi      # 0x153f5
callq 0x4340
movq %rax, %rdi
movq %r14, %rsi
callq 0x42d0
leaq 0xeb92(%rip), %rsi      # 0x153a1
movq %rax, %rdi
callq 0x4340
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x42d0
leaq 0xfcce(%rip), %rsi      # 0x164f8
jmp 0x648f
movq 0x187b2(%rip), %rdi     # 0x1efe8
leaq 0xebd4(%rip), %rsi      # 0x15411
callq 0x4340
movq %rax, %rdi
movq %rbx, %rsi
jmp 0x6885
addq $0xe0, %r12
movq 0x18790(%rip), %rdi     # 0x1efe8
leaq 0xebb2(%rip), %rsi      # 0x15411
callq 0x4340
movq %rax, %rdi
movq %r12, %rsi
jmp 0x6885
movq 0x18775(%rip), %rdi     # 0x1efe8
leaq 0xeb97(%rip), %rsi      # 0x15411
callq 0x4340
movq %rax, %rdi
movq %r15, %rsi
callq 0x42d0
jmp 0x67bd
jmp 0x6893
jmp 0x68a4
movq %rax, %rbx
leaq -0x880(%rbp), %rdi
callq 0x4180
jmp 0x68a7
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4660