// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movl %edi, %ebp
leaq 0x1c(%rsp), %rax
leaq 0x1b4c7(%rip), %rcx     # 0x203f5
movq %rcx, 0x20(%rsp)
leaq 0x1b5a8(%rip), %rcx     # 0x204e2
movq %rcx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movl $0x30702d, (%rax)       # imm = 0x30702D
pushq $0x1
popq %r12
pushq $-0x1
popq %rax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %ebp, %edi
movq 0x10(%rsp), %rsi
leaq 0x1b576(%rip), %rdx     # 0x204e6
callq 0x3090
movl %eax, %ebx
shll $0x18, %ebx
js 0x4fc0
movq 0x27035(%rip), %rax     # 0x2bfb8
movq (%rax), %r13
cmpl $0x72000000, %ebx       # imm = 0x72000000
jne 0x4f9b
movq %r13, %rdi
callq 0x35b0
movq %rax, 0x8(%rsp)
cmpl $0x66000000, %ebx       # imm = 0x66000000
cmoveq %r13, %r14
cmpl $0x50000000, %ebx       # imm = 0x50000000
cmoveq %r13, %r15
cmpl $0x3f000000, %ebx       # imm = 0x3F000000
movl $0x0, %eax
cmovel %eax, %r12d
jmp 0x4f62
movq 0x8(%rsp), %rbx
leal -0x3(%rbx), %eax
cmpl $-0x2, %eax
jb 0x5030
testl %r12d, %r12d
je 0x5030
testq %r14, %r14
jne 0x4fed
movl %ebx, %edi
movq %r15, %rsi
callq 0x9c18
movq %rax, %r14
cmpb $0x0, (%rax)
je 0x5120
movl %ebx, %edi
movq %r14, %rsi
callq 0x98f5
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x5123
movq 0x26fce(%rip), %rax     # 0x2bfd8
movl $0x1, (%rax)
orb $0x30, %bl
leaq 0x20(%rsp), %rsi
movq 0x10(%rsi), %rax
movb %bl, 0x2(%rax)
movq %r14, 0x18(%rsi)
pushq $0x4
popq %rdi
callq 0x480e
jmp 0x5123
movq 0x26f99(%rip), %r15     # 0x2bfd0
movq (%r15), %rsi
pushq $0xa
popq %rbx
movl %ebx, %edi
callq 0x3410
movq (%r15), %rcx
leaq 0x1b49f(%rip), %rdi     # 0x204ed
pushq $0x22
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b177(%rip), %rdi     # 0x201de
pushq $0xa
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b494(%rip), %rdi     # 0x20510
pushq $0x27
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b4a7(%rip), %rdi     # 0x20538
pushq $0x38
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rdi
leaq 0x1b4cb(%rip), %rsi     # 0x20571
xorl %eax, %eax
callq 0x3500
movq (%r15), %rcx
leaq 0x1b4f8(%rip), %rdi     # 0x205af
pushq $0x58
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b53c(%rip), %rdi     # 0x20608
pushq $0x30
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b29f(%rip), %rdi     # 0x20380
pushq $0xb
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b543(%rip), %rdi     # 0x20639
pushq $0x17
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rcx
leaq 0x1b546(%rip), %rdi     # 0x20651
pushq $0x31
popq %rsi
movq %r14, %rdx
callq 0x3790
movq (%r15), %rsi
movl %ebx, %edi
callq 0x3410
pushq $0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop