// File: /workspace/github_c_makefile_star2_O1/ToniWestbrook[P]paladin/bwtindex.c
// Function: command_prepare
int command_prepare(int argc, char *argv[]) {
	char c;
	char refArg[] = "-p0";
	const char * refName, * proxyAddress;
	int refType, valid;

	// Fixed passthrough arguments
	const char * passArgs[] = {"index", "-r3", refArg, NULL};


	// Parse arguments
	valid = 1;
	refType = -1;
	refName = NULL;
    proxyAddress = NULL;

	while ((c = getopt(argc, argv, "r:f:P:")) >= 0) {
		if (c == 'r') refType = atoi(optarg);
		if (c == 'f') refName = optarg;
        if (c == 'P') proxyAddress = optarg;
		if (c == '?') valid = 0;
	}

	if ((refType < UNIPROT_REFERENCE_SWISSPROT) || (refType > UNIPROT_REFERENCE_UNIREF90)) valid = 0;

	if (!valid) {
			fprintf(stderr, "\n");
			fprintf(stderr, "Usage: paladin prepare [options]\n\n");
			fprintf(stderr, "Options:\n\n");
			fprintf(stderr, "    -r <#>         Reference Database:\n");
			fprintf(stderr, "                     1: UniProtKB Reviewed (Swiss-Prot)\n");
			fprintf(stderr, "                     2: UniProtKB Clustered 90%% (UniRef90)\n\n");
			fprintf(stderr, "    -f <ref.fasta> Skip download, use local copy of reference database (may be indexed)\n");
            fprintf(stderr, "    -P <address>   HTTP or SOCKS proxy address\n\n");
			fprintf(stderr, "Examples:\n\n");
			fprintf(stderr, "   paladin prepare -r2\n");
			fprintf(stderr, "   paladin prepare -r1 -f uniprot_sprot.fasta.gz\n");

			fprintf(stderr, "\n");
			return 1;
	}


	// We can generalize this in the future to include other reference types
	if (!refName) {
		if ((refName = downloadUniprotReference(refType, proxyAddress))[0] == 0) {
			return 1;
		}
	}

	// Clean the UniProt reference, fixing up headers.  Then index if necessary
	if (cleanUniprotReference(refType, refName) == 0) {
		// Pass reference type to indexing step
		optind = 1;
		((char *)passArgs[2])[2] = '0' + refType;
		passArgs[3] = refName;

		// Index
		return command_index(4, (char * *) passArgs);

	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r12
movl %edi, %ebp
leaq 0x1c(%rsp), %rax
movl $0x30702d, (%rax)       # imm = 0x30702D
leaq 0x1efad(%rip), %rcx     # 0x253f5
movq %rcx, 0x20(%rsp)
leaq 0x1f08e(%rip), %rcx     # 0x254e2
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
leaq 0x1f078(%rip), %rdx     # 0x254e6
callq 0x3090
movl %eax, %r13d
movq $0x0, 0x8(%rsp)
shll $0x18, %r13d
js 0x6515
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl $0x1, %ebx
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpl $0x72000000, %r13d      # imm = 0x72000000
jne 0x64bb
movq 0x29b0a(%rip), %rax     # 0x2ffb8
movq (%rax), %rdi
callq 0x35b0
movq %rax, 0x10(%rsp)
cmpl $0x66000000, %r13d      # imm = 0x66000000
movq 0x29aef(%rip), %rax     # 0x2ffb8
movq (%rax), %rax
cmoveq %rax, %r14
cmpl $0x50000000, %r13d      # imm = 0x50000000
cmoveq %rax, %r15
cmpl $0x3f000000, %r13d      # imm = 0x3F000000
movl $0x0, %eax
cmovel %eax, %ebx
movl %ebp, %edi
movq %r12, %rsi
leaq 0x1eff0(%rip), %rdx     # 0x254e6
callq 0x3090
movl %eax, %r13d
shll $0x18, %r13d
jns 0x649e
testl %ebx, %ebx
sete %al
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rbx
jmp 0x6520
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %r15d, %r15d
leal -0x3(%rbx), %eax
cmpl $-0x2, %eax
jb 0x6584
cmpb $0x0, 0x8(%rsp)
jne 0x6584
testq %r14, %r14
jne 0x6546
movl %ebx, %edi
movq %r15, %rsi
callq 0xb1ce
movq %rax, %r14
cmpb $0x0, (%rax)
je 0x6589
movl %ebx, %edi
movq %r14, %rsi
callq 0xaea2
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x658e
movq 0x29a79(%rip), %rax     # 0x2ffd8
movl $0x1, (%rax)
orb $0x30, %bl
leaq 0x20(%rsp), %rsi
movq 0x10(%rsi), %rax
movb %bl, 0x2(%rax)
movq %r14, 0x18(%rsi)
movl $0x4, %edi
callq 0x5df3
jmp 0x658e
callq 0x390b
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)