// File: Mengjintao[P]SWAPCounter/src/sequence.cpp
// Function: parameter::getopt(int, char**)
void parameter::getopt(int argc, char **argv)
{
    this->fastaPath[0] = 0;
    this->outputPath[0] = 0;
    this->hashLength=23;
    this->cutoffThreshold = 5;
    this->groupProc = 1;
	
    this->kmerGraphFlag=0;
    this->JungGraphFlag=0;
    this->distGraphFlag=0;
    this->performanceFlag=0;
    this->refSize = 0;

    char comStr[100], localChar;
    int  ret;
    for(int i=1;i<argc;i++)
    {
	sscanf(argv[i], "%s", comStr);
 	if(comStr[0] != '-')  
	{
	  	printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
//	    MPI_Abort(MPI_COMM_WORLD,1);		
	    exit(0);
	}	
	switch(comStr[1])
	{
	    case 'h':
	    	printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		exit(0);
	    case 'v':
		printf("SWAP-Assembler version 0.5\n");
		exit(0);
	    case 'k':
		if(i+1 == argc) 
		{
		    printf("Error: -k needs a value for the kmer size\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		ret = sscanf(argv[i+1], "%d", &this->hashLength);
		i++;
		if(ret!=1 || this->hashLength<3 || this->hashLength>31 || this->hashLength%2!=1)	
		{
		    printf("Error: -k needs a value (odd number between 18 and 32) for the kmer size\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
	            exit(0);
		}
		break;	
	    case 'c':
		if(i+1 == argc) 
		{
		    printf("Error: -c needs a value for the cutoff threshold\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		ret = sscanf(argv[i+1], "%d", &this->cutoffThreshold);
		i++;
		if(ret!=1)	
		{
		    printf("Error: -c needs a value for the cutoff threshold (it is suggested to be 3~10 percent of the coverage of dataset)\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
	            exit(0);
		}
		break;
            case 'i':
		if(i+1 == argc) 
		{
		    printf("Error: -i needs a path for the file in fasta format\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		ret = sscanf(argv[i+1], "%s", this->fastaPath);
		i++;
		if(ret==0)
		{
		    printf("Error: -i needs a path for the file in fasta format\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		break;
            case 'o':
		if(i+1 == argc) 
		{
		    printf("Error: -o needs a directory name used for the output data\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		ret = sscanf(argv[i+1], "%s", this->outputPath);
		i++;
		if(ret==0)
		{
		    printf("Error: -o needs a directory path for the output data\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		break;
	    case 'r':
		if(i+1 == argc) 
		{
		    printf("Error: -r needs a reference size for the Bloom filter\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		localChar = 0;
		ret = sscanf(argv[i+1], "%lf%c", &this->refSize, &localChar);
		if(localChar=='G')	this->refSize *= (1024*1024*1024);
		if(localChar=='M')	this->refSize *= (1024*1024);
		if(localChar=='K')	this->refSize *= 1024;
		i++;
		if(ret==0)
		{
		    printf("Error: -r needs a reference size for the Bloom filter\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
	            exit(0);
		}
		break;
	    case 'g':
		if(i+1 == argc) 
		{
		    printf("Error: -g needs a value for the grouped processes number for reading input data (suggested value should be larger than 1 and less than the number of cores in computing nodes)\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
		    exit(0);
		}
		ret = sscanf(argv[i+1], "%d", &this->groupProc);
		i++;
		if(ret!=1)	
		{
		    printf("Error: -g needs a value for the grouped processes number for reading input data (suggested value should be larger than 1 and less than the number of cores in computing nodes)\n");
	    	    printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -g <grouped processes> -i <input Fasta data> -o <output data directory>\n",argv[0]);
	            exit(0);
		}
		break;
		this->groupProc = 4;
	    case 's':
		this->kmerGraphFlag = 1;
		break;
	    case 'j':
		this->JungGraphFlag = 1;
		break;
	    case 'd':
		this->distGraphFlag = 1;
		break;
	    case 'p':
		this->performanceFlag = 1;
		break;
		
	}	
    }
    if(this->fastaPath[0]==0 || this->outputPath[0]==0)
    {
        printf("Usage: %s -k <kmerlength> -r <reference size> -c <cutoff Threshod> -i <input Fasta data> -o <output data directory>\n",argv[0]);
        exit(0);
    }

}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movl %esi, 0x9c(%rsp)
movq %rdx, 0x90(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x8(%rsp)
movb $0x0, (%rax)
movb $0x0, 0xff(%rax)
movl $0x17, 0xaf8(%rax)
movl $0x5, 0xb0c(%rax)
movl $0x1, 0xb20(%rax)
movl $0x0, 0xb10(%rax)
movl $0x0, 0xb14(%rax)
movl $0x0, 0xb18(%rax)
movl $0x0, 0xb1c(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0xb28(%rax)
movl $0x1, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x14e04
movq 0x90(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x2064(%rip), %rsi      # 0x16890
movb $0x0, %al
callq 0x8670
movsbl 0x20(%rsp), %eax
cmpl $0x2d, %eax
je 0x1485d
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x2044(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movsbl 0x21(%rsp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, (%rsp)
subl $0x13, %eax
ja 0x14df2
movq (%rsp), %rax
leaq 0x1fc1(%rip), %rcx      # 0x16840
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1ff9(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
leaq 0x2070(%rip), %rdi      # 0x1691f
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x148fb
leaq 0x2067(%rip), %rdi      # 0x1693b
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1fa6(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0xaf8, %rdx            # imm = 0xAF8
leaq 0x2042(%rip), %rsi      # 0x16966
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x1, 0x18(%rsp)
jne 0x14975
movq 0x8(%rsp), %rax
cmpl $0x3, 0xaf8(%rax)
jl 0x14975
movq 0x8(%rsp), %rax
cmpl $0x1f, 0xaf8(%rax)
jg 0x14975
movq 0x8(%rsp), %rax
movl 0xaf8(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
je 0x149a3
leaq 0x1fed(%rip), %rdi      # 0x16969
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1efe(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x149e6
leaq 0x1ff4(%rip), %rdi      # 0x169b3
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1ebb(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0xb0c, %rdx            # imm = 0xB0C
leaq 0x1f57(%rip), %rsi      # 0x16966
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x1, 0x18(%rsp)
je 0x14a5a
leaq 0x1fb2(%rip), %rdi      # 0x169e5
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1e47(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x14a9d
leaq 0x1fe1(%rip), %rdi      # 0x16a57
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1e04(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x1dd1(%rip), %rsi      # 0x16890
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x18(%rsp)
jne 0x14b0a
leaq 0x1f74(%rip), %rdi      # 0x16a57
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1d97(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x14b4d
leaq 0x1f66(%rip), %rdi      # 0x16a8c
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1d54(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0xff, %rdx
leaq 0x1d1a(%rip), %rsi      # 0x16890
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x18(%rsp)
jne 0x14bc1
leaq 0x1f2d(%rip), %rdi      # 0x16ac7
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1ce0(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x14c04
leaq 0x1f20(%rip), %rdi      # 0x16afd
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1c9d(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movb $0x0, 0x1f(%rsp)
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0xb28, %rdx            # imm = 0xB28
leaq 0x1f02(%rip), %rsi      # 0x16b34
leaq 0x1f(%rsp), %rcx
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movsbl 0x1f(%rsp), %eax
cmpl $0x47, %eax
jne 0x14c69
movq 0x8(%rsp), %rax
movsd 0x1bcf(%rip), %xmm0     # 0x16828
mulsd 0xb28(%rax), %xmm0
movsd %xmm0, 0xb28(%rax)
movsbl 0x1f(%rsp), %eax
cmpl $0x4d, %eax
jne 0x14c90
movq 0x8(%rsp), %rax
movsd 0x1bb0(%rip), %xmm0     # 0x16830
mulsd 0xb28(%rax), %xmm0
movsd %xmm0, 0xb28(%rax)
movsbl 0x1f(%rsp), %eax
cmpl $0x4b, %eax
jne 0x14cb7
movq 0x8(%rsp), %rax
movsd 0x1b91(%rip), %xmm0     # 0x16838
mulsd 0xb28(%rax), %xmm0
movsd %xmm0, 0xb28(%rax)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x18(%rsp)
jne 0x14cf7
leaq 0x1e2d(%rip), %rdi      # 0x16afd
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1baa(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movl 0x14(%rsp), %eax
addl $0x1, %eax
cmpl 0x9c(%rsp), %eax
jne 0x14d3a
leaq 0x1e27(%rip), %rdi      # 0x16b3a
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1b67(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
movq 0x8(%rsp), %rdx
movq 0x90(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0xb20, %rdx            # imm = 0xB20
leaq 0x1c03(%rip), %rsi      # 0x16966
movb $0x0, %al
callq 0x8670
movl %eax, 0x18(%rsp)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x1, 0x18(%rsp)
je 0x14dae
leaq 0x1db3(%rip), %rdi      # 0x16b3a
movb $0x0, %al
callq 0x8040
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1af3(%rip), %rdi      # 0x16893
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
jmp 0x14df2
movq 0x8(%rsp), %rax
movl $0x1, 0xb10(%rax)
jmp 0x14df2
movq 0x8(%rsp), %rax
movl $0x1, 0xb14(%rax)
jmp 0x14df2
movq 0x8(%rsp), %rax
movl $0x1, 0xb18(%rax)
jmp 0x14df2
movq 0x8(%rsp), %rax
movl $0x1, 0xb1c(%rax)
jmp 0x14df4
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x147fe
movq 0x8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x14e22
movq 0x8(%rsp), %rax
movsbl 0xff(%rax), %eax
cmpl $0x0, %eax
jne 0x14e42
movq 0x90(%rsp), %rax
movq (%rax), %rsi
leaq 0x1db6(%rip), %rdi      # 0x16bea
movb $0x0, %al
callq 0x8040
xorl %edi, %edi
callq 0x8800
addq $0xa8, %rsp
retq
nopw (%rax,%rax)