// File: /workspace/github_c_makefile_star2_O3/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
leaq 0x1c(%rsp), %rax
movl $0x30702d, (%rax)       # imm = 0x30702D
leaq 0x1ef6c(%rip), %rcx     # 0x253f5
movq %rcx, 0x20(%rsp)
leaq 0x1f04d(%rip), %rcx     # 0x254e2
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x1f040(%rip), %rdx     # 0x254e6
movl %edi, 0xc(%rsp)
movq %rsi, %rbp
callq 0x3090
movl %eax, %r13d
shll $0x18, %r13d
js 0x659e
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x10(%rsp)
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %r14d, %r14d
movq 0x29adc(%rip), %rax     # 0x2ffb8
movq (%rax), %rbx
cmpl $0x72000000, %r13d      # imm = 0x72000000
jne 0x64f5
movq %rbx, %rdi
callq 0x35b0
movq %rax, 0x10(%rsp)
cmpl $0x66000000, %r13d      # imm = 0x66000000
cmoveq %rbx, %r14
cmpl $0x50000000, %r13d      # imm = 0x50000000
cmoveq %rbx, %r12
cmpl $0x3f000000, %r13d      # imm = 0x3F000000
movl $0x0, %eax
cmovel %eax, %r15d
movl 0xc(%rsp), %edi
movq %rbp, %rsi
leaq 0x1efbd(%rip), %rdx     # 0x254e6
callq 0x3090
movl %eax, %r13d
shll $0x18, %r13d
jns 0x64d5
movq 0x10(%rsp), %rbx
leal -0x3(%rbx), %eax
cmpl $-0x2, %eax
jb 0x659e
testl %r15d, %r15d
je 0x659e
testq %r14, %r14
jne 0x6560
movl %ebx, %edi
movq %r12, %rsi
callq 0xb3f0
movq %rax, %r14
cmpb $0x0, (%rax)
je 0x65a3
movl %ebx, %edi
movq %r14, %rsi
callq 0xb0b9
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x65a8
movq 0x29a5f(%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 0x5e1d
jmp 0x65a8
callq 0x390b
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop