// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl 0x315fd(%rip), %eax     # 0x374e2
movl %eax, -0x15(%rbp)
leaq 0x31506(%rip), %rax     # 0x373f5
movq %rax, -0x50(%rbp)
leaq 0x315ec(%rip), %rax     # 0x374e6
movq %rax, -0x48(%rbp)
leaq -0x15(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x1, -0x30(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x315b0(%rip), %rdx     # 0x374ea
callq 0x3090
movb %al, -0x11(%rbp)
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x5fa5
movsbl -0x11(%rbp), %eax
cmpl $0x72, %eax
jne 0x5f65
movq 0x3a066(%rip), %rax     # 0x3ffc0
movq (%rax), %rdi
callq 0x3590
movl %eax, -0x2c(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x66, %eax
jne 0x5f7c
movq 0x3a04b(%rip), %rax     # 0x3ffc0
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x50, %eax
jne 0x5f93
movq 0x3a034(%rip), %rax     # 0x3ffc0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movsbl -0x11(%rbp), %eax
cmpl $0x3f, %eax
jne 0x5fa3
movl $0x0, -0x30(%rbp)
jmp 0x5f2c
cmpl $0x1, -0x2c(%rbp)
jl 0x5fb1
cmpl $0x2, -0x2c(%rbp)
jle 0x5fb8
movl $0x0, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x60eb
movq 0x3a00f(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x315de(%rip), %rsi     # 0x375b1
movb $0x0, %al
callq 0x34e0
movq 0x39ff7(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31506(%rip), %rsi     # 0x374f1
movb $0x0, %al
callq 0x34e0
movq 0x39fdf(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x311db(%rip), %rsi     # 0x371de
movb $0x0, %al
callq 0x34e0
movq 0x39fc7(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x314f9(%rip), %rsi     # 0x37514
movb $0x0, %al
callq 0x34e0
movq 0x39faf(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31509(%rip), %rsi     # 0x3753c
movb $0x0, %al
callq 0x34e0
movq 0x39f97(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x3152a(%rip), %rsi     # 0x37575
movb $0x0, %al
callq 0x34e0
movq 0x39f7f(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31550(%rip), %rsi     # 0x375b3
movb $0x0, %al
callq 0x34e0
movq 0x39f67(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31591(%rip), %rsi     # 0x3760c
movb $0x0, %al
callq 0x34e0
movq 0x39f4f(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x312ed(%rip), %rsi     # 0x37380
movb $0x0, %al
callq 0x34e0
movq 0x39f37(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31592(%rip), %rsi     # 0x3763d
movb $0x0, %al
callq 0x34e0
movq 0x39f1f(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x31592(%rip), %rsi     # 0x37655
movb $0x0, %al
callq 0x34e0
movq 0x39f07(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
leaq 0x314d6(%rip), %rsi     # 0x375b1
movb $0x0, %al
callq 0x34e0
movl $0x1, -0x4(%rbp)
jmp 0x6164
cmpq $0x0, -0x20(%rbp)
jne 0x6115
movl -0x2c(%rbp), %edi
movq -0x28(%rbp), %rsi
callq 0xd410
movq %rax, -0x20(%rbp)
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x6113
movl $0x1, -0x4(%rbp)
jmp 0x6164
jmp 0x6115
movl -0x2c(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0xce80
cmpl $0x0, %eax
jne 0x615d
movq 0x39eb3(%rip), %rax     # 0x3ffe0
movl $0x1, (%rax)
movl -0x2c(%rbp), %eax
addl $0x30, %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x50(%rbp), %rsi
movl $0x4, %edi
callq 0x5630
movl %eax, -0x4(%rbp)
jmp 0x6164
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)