// File: /workspace/github_c_makefile_star2_O2/jiqingxiaoxi[P]RPA/RPA.c
// Function: read_parPrimer
struct Primer *read_parPrimer(char *path,int common_flag,int specific_flag)
{
	char *in,line[100];
	int pos,len,gi,position,plus,minus,size,i,flag,total,*store,*temp,*data;
	float Tm;
	struct Primer *new_primer,*p_primer,*head;
	struct Node *new_node,*p_node;
	FILE *fp;

///read the  primer file
	if(access(path,0)==-1)
	{
		printf("Error! Don't have the %s file!\n",path);
		exit(1);
	}
        fp=fopen(path,"r");
        if(fp==NULL)
        {
                printf("Error: can't open the %s file!\n",path);
                exit(1);
        }
	
	size=sizeof(struct Primer);
	i=0;
        while(fscanf(fp,"pos:%d\tlength:%d\t+:%d\t-:%d\t%f\n",&pos,&len,&plus,&minus,&Tm)!=EOF)
        {
		new_primer=(struct Primer *)malloc(size);
		new_primer->pos=pos;
		new_primer->len=len;
		new_primer->total=1;
		new_primer->plus=plus;
		new_primer->minus=minus;
		new_primer->Tm=Tm;
		new_primer->next=NULL;
		new_primer->other=NULL;
		new_primer->common=NULL;
		new_primer->specific=NULL;
		new_primer->ignore=0;

		if(i==0)
		{
			head=new_primer;
			p_primer=new_primer;
			i++;
		}
		else
		{
			p_primer->next=new_primer;
			p_primer=new_primer;
		}
        }
	fclose(fp);
        if(i==0)
        {
                printf("Sorry! Don't have any candidate single primers in %s!\n",path);
                exit(1);
        }

//parameter of common
	if(common_flag==1)
	{
		i=strlen(path);
		in=(char *)malloc(i+20);
        	memset(in,'\0',i+20);
        	strcpy(in,path);
        	strcat(in,"-common.txt"); //suffix of parameter
		if(access(in,0)==-1)
		{
			printf("Error! Don't have the %s file!\n",in);
			exit(1);
		}

        	fp=fopen(in,"r");
        	if(fp==NULL)
        	{
        	        printf("Error: can't open the %s file!\n",in);
        	        exit(1);
        	}
		
		total=0;
		while(fgets(line,100,fp)!=NULL)
			total++;
		rewind(fp);
		store=(int *)malloc(total*sizeof(int));
		temp=(int *)malloc(total*sizeof(int));
		data=(int *)malloc(6*total*sizeof(int));
		total=0;
		while(fscanf(fp,"%d\t%d\t%d\t%d\t%d\t%d\n",&pos,&len,&gi,&position,&plus,&minus)!=EOF)
		{
			data[6*total]=pos;
			data[6*total+1]=len;
			data[6*total+2]=gi;
			data[6*total+3]=position;
			data[6*total+4]=plus;
			data[6*total+5]=minus;
			store[total]=total;
			total++;
		}
		fclose(fp);
		sort_merge(store,temp,data,0,(total-1));

		p_primer=head;
		size=sizeof(struct Node);
		flag=0;
		i=0;
		while(p_primer&&i<total)
		{
		//pos
			if(data[store[i]*6]<p_primer->pos)
			{
				i++;
				continue;
			}
			if(data[store[i]*6]>p_primer->pos)
			{
				p_primer=p_primer->next;
				flag=0;
				continue;
			}
		//len
			if(data[store[i]*6+1]<p_primer->len)
                        {
                                i++;
                                continue;
                        }
                        if(data[store[i]*6+1]>p_primer->len)
                        {
                                p_primer=p_primer->next;
				flag=0;
                                continue;
                        }
			new_node=(struct Node *)malloc(size);
			new_node->gi=data[store[i]*6+2];
			new_node->pos=data[store[i]*6+3];
			new_node->plus=data[store[i]*6+4];
			new_node->minus=data[store[i]*6+5];
                        new_node->next=NULL;
			if(flag==0)
			{
				flag++;
				p_primer->common=new_node;
				p_node=new_node;
			}
			else
			{
                        	p_node->next=new_node;
				p_node=new_node;
			}
			i++;
        	}
		free(in);
		free(data);
		free(store);
		free(temp);
	}
//paramter for specific
	if(specific_flag==1)
	{
		i=strlen(path);
		in=(char *)malloc(i+20);
		memset(in,'\0',i+20);
        	strcpy(in,path);
        	strcat(in,"-specific.txt"); //suffix of parameter
		if(access(in,0)==-1)
		{
			printf("Error! Don't have the %s file!\n",in);
			exit(1);
		}

        	fp=fopen(in,"r");
        	if(fp==NULL)
        	{
        	        printf("Error: can't open the %s file!\n",in);
        	        exit(1);
        	}
		total=0;
                while(fgets(line,100,fp)!=NULL)
                        total++;
                rewind(fp);
                store=(int *)malloc(total*sizeof(int));
                temp=(int *)malloc(total*sizeof(int));
                data=(int *)malloc(6*total*sizeof(int));
                total=0;
                while(fscanf(fp,"%d\t%d\t%d\t%d\t%d\t%d\n",&pos,&len,&gi,&position,&plus,&minus)!=EOF)
                {
                        data[6*total]=pos;
                        data[6*total+1]=len;
                        data[6*total+2]=gi;
                        data[6*total+3]=position;
                        data[6*total+4]=plus;
                        data[6*total+5]=minus;
                        store[total]=total;
                        total++;
                }
                fclose(fp);
                sort_merge(store,temp,data,0,(total-1));

                p_primer=head;
                size=sizeof(struct Node);
                flag=0;
		i=0;
                while(p_primer&&i<total)
                {
                //pos
                        if(data[store[i]*6]<p_primer->pos)
                        {
                                i++;
                                continue;
                        }
                        if(data[store[i]*6]>p_primer->pos)
                        {
                                p_primer=p_primer->next;
				flag=0;
                                continue;
                        }
                //len
                        if(data[store[i]*6+1]<p_primer->len)
                        {
                                i++;
                                continue;
                        }
                        if(data[store[i]*6+1]>p_primer->len)
                        {
                                p_primer=p_primer->next;
				flag=0;
                                continue;
                        }
                        new_node=(struct Node *)malloc(size);
                        new_node->gi=data[store[i]*6+2];
                        new_node->pos=data[store[i]*6+3];
                        new_node->plus=data[store[i]*6+4];
                        new_node->minus=data[store[i]*6+5];
                        new_node->next=NULL;
			if(flag==0)
			{
				flag++;
				p_primer->specific=new_node;
				p_node=new_node;
			}
			else
			{
                        	p_node->next=new_node;
                        	p_node=new_node;
			}
                        i++;
                }
		free(in);
                free(data);
                free(store);
                free(temp);

	//ignore info
		i=strlen(path);
                in=(char *)malloc(i+20);
                memset(in,'\0',i+20);
                strcpy(in,path);
                strcat(in,"-ignore.txt"); //suffix of parameter
                if(access(in,0)==-1)
                {
                        printf("Error! Don't have the %s file!\n",in);
                        exit(1);
                }

                fp=fopen(in,"r");
                if(fp==NULL)
                {
                        printf("Error: can't open the %s file!\n",in);
                        exit(1);
                }
		p_primer=head;
                while(fscanf(fp,"%d\n",&pos)!=EOF)
                {
			while(p_primer)
			{
				if(p_primer->pos<pos)
				{
					p_primer=p_primer->next;
					continue;
				}
				if(p_primer->pos>pos)
					break;
				p_primer->ignore=1;
				p_primer=p_primer->next;
			}
                }
                fclose(fp);
                free(in);
	}
	return head;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, -0x70(%rbp)
movl %esi, %r14d
movq %rdi, %rbx
xorl %esi, %esi
callq 0x11b0
cmpl $-0x1, %eax
je 0xad4f
movl %r14d, -0x40(%rbp)
leaq 0x2b5f(%rip), %rsi      # 0xd23b
movq %rbx, -0x58(%rbp)
movq %rbx, %rdi
callq 0x11c0
testq %rax, %rax
je 0xad58
movq %rax, %r14
movb $0x1, %r13b
leaq -0x38(%rbp), %r15
pushq $0x40
popq %r12
movq %rbx, -0x78(%rbp)
subq $0x8, %rsp
movq %r14, %rdi
leaq 0x2dcf(%rip), %rsi      # 0xd4e0
leaq -0x2c(%rbp), %rdx
movq %r15, %rcx
leaq -0x34(%rbp), %r8
leaq -0x30(%rbp), %r9
xorl %eax, %eax
leaq -0x80(%rbp), %r10
pushq %r10
callq 0x1060
popq %rcx
popq %rdx
cmpl $-0x1, %eax
je 0xa793
movq %r12, %rdi
callq 0x1190
movl -0x2c(%rbp), %ecx
movl %ecx, (%rax)
movl -0x38(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl $0x1, 0x10(%rax)
movl -0x34(%rbp), %ecx
movl %ecx, 0x8(%rax)
movl -0x30(%rbp), %ecx
movl %ecx, 0xc(%rax)
movss -0x80(%rbp), %xmm0
movss %xmm0, 0x18(%rax)
andl $0x0, 0x14(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
testb $0x1, %r13b
jne 0xa788
movq %rax, 0x28(%rbx)
xorl %r13d, %r13d
movq %rax, %rbx
jmp 0xa703
xorl %r13d, %r13d
movq %rax, %rbx
jmp 0xa6ff
movq %r14, %rdi
callq 0x10a0
testb $0x1, %r13b
jne 0xad61
cmpl $0x1, -0x40(%rbp)
movq -0x58(%rbp), %rbx
jne 0xaa0b
movq %rbx, %rdi
callq 0x10b0
addl $0x14, %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x1140
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1050
movq %r14, %rdi
callq 0x10b0
movabsq $0x2e6e6f6d6d6f632d, %rcx # imm = 0x2E6E6F6D6D6F632D
movq %rcx, (%r14,%rax)
movl $0x747874, 0x8(%r14,%rax) # imm = 0x747874
movq %r14, %rdi
xorl %esi, %esi
callq 0x11b0
cmpl $-0x1, %eax
je 0xad6e
leaq 0x2a2b(%rip), %rsi      # 0xd23b
movq %r14, -0x60(%rbp)
movq %r14, %rdi
callq 0x11c0
testq %rax, %rax
je 0xad7a
movq %rax, %r13
pushq $-0x4
popq %r14
pushq $-0x6
popq %r12
leaq -0xf0(%rbp), %rbx
pushq $0x64
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x1130
addq $0x4, %r14
addl $0x6, %r12d
testq %rax, %rax
jne 0xa83b
movq %r13, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x1190
movq %rax, %rbx
movq %r14, %rdi
callq 0x1190
movq %rax, -0x40(%rbp)
movl %r12d, %edi
shlq $0x2, %rdi
callq 0x1190
movq %rax, -0x50(%rbp)
movq %rax, %r14
addq $0x14, %r14
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r13, %rdi
leaq 0x2ca6(%rip), %rsi      # 0xd542
leaq -0x2c(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x44(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
leaq -0x34(%rbp), %r10
pushq %r10
callq 0x1060
popq %rcx
popq %rdx
cmpl $-0x1, %eax
je 0xa909
movl -0x2c(%rbp), %eax
movl %eax, -0x14(%r14)
movl -0x38(%rbp), %eax
movl %eax, -0x10(%r14)
movl -0x48(%rbp), %eax
movl %eax, -0xc(%r14)
movl -0x44(%rbp), %eax
movl %eax, -0x8(%r14)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%r14)
movl -0x30(%rbp), %eax
movl %eax, (%r14)
movl %r15d, (%rbx,%r15,4)
incq %r15
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
addq $0x18, %r14
jmp 0xa892
movq %r13, %rdi
callq 0x10a0
decl %r15d
xorl %r13d, %r13d
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x50(%rbp), %r14
movq %r14, %rdx
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0xa60e
movq %r14, %rsi
sarq $0x20, %r12
xorl %edi, %edi
movq -0x78(%rbp), %r15
movslq %r13d, %r13
movq %rdx, -0x68(%rbp)
cmpq %r12, %r13
jge 0xa9e2
testq %r15, %r15
je 0xa9e2
movslq (%rbx,%r13,4), %rax
imulq $0x6, %rax, %r14
movl (%r15), %eax
cmpl %eax, (%rsi,%r14,4)
jl 0xa983
jg 0xa97b
movl %r14d, %eax
orl $0x1, %eax
cltq
movl 0x4(%r15), %ecx
cmpl %ecx, (%rsi,%rax,4)
jl 0xa983
jle 0xa988
movq 0x28(%r15), %r15
xorl %edi, %edi
jmp 0xa94c
incq %r13
jmp 0xa943
movl %edi, -0x7c(%rbp)
pushq $0x18
popq %rdi
callq 0x1190
pushq $0x1
popq %rdx
movq -0x50(%rbp), %rsi
movl 0x8(%rsi,%r14,4), %ecx
movl %ecx, 0x4(%rax)
movl 0xc(%rsi,%r14,4), %ecx
movl %ecx, (%rax)
movl 0x10(%rsi,%r14,4), %ecx
movl %ecx, 0x8(%rax)
movl 0x14(%rsi,%r14,4), %ecx
movl %ecx, 0xc(%rax)
andq $0x0, 0x10(%rax)
movq -0x68(%rbp), %rdi
addq $0x10, %rdi
leaq 0x30(%r15), %rcx
cmpl $0x0, -0x7c(%rbp)
cmovneq %rdi, %rcx
movq %rax, (%rcx)
incq %r13
movl %edx, %edi
movq %rax, %rdx
jmp 0xa93c
movq %rsi, %r14
movq -0x60(%rbp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq -0x40(%rbp), %rdi
callq 0x1030
movq -0x58(%rbp), %rbx
cmpl $0x1, -0x70(%rbp)
jne 0xad39
movq %rbx, %rdi
callq 0x10b0
addl $0x14, %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x1140
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1050
movq %r14, %rdi
callq 0x10b0
movabsq $0x696669636570732d, %rcx # imm = 0x696669636570732D
movq %rcx, (%r14,%rax)
movabsq $0x7478742e636966, %rcx # imm = 0x7478742E636966
movq %rcx, 0x6(%r14,%rax)
movq %r14, %rdi
xorl %esi, %esi
callq 0x11b0
cmpl $-0x1, %eax
je 0xad6e
leaq 0x27c3(%rip), %rsi      # 0xd23b
movq %r14, -0x50(%rbp)
movq %r14, %rdi
callq 0x11c0
testq %rax, %rax
je 0xad87
movq %rax, %r13
pushq $-0x4
popq %rbx
pushq $-0x6
popq %r12
leaq -0xf0(%rbp), %r14
pushq $0x64
popq %r15
movq %r14, %rdi
movl %r15d, %esi
movq %r13, %rdx
callq 0x1130
addq $0x4, %rbx
addl $0x6, %r12d
testq %rax, %rax
jne 0xaaa2
movq %r13, %rdi
callq 0x10e0
movq %rbx, %rdi
callq 0x1190
movq %rax, %r14
movq %rbx, %rdi
callq 0x1190
movq %rax, -0x70(%rbp)
movl %r12d, %edi
shlq $0x2, %rdi
callq 0x1190
movq %rax, -0x40(%rbp)
movq %rax, %rbx
addq $0x14, %rbx
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r13, %rdi
leaq 0x2a3f(%rip), %rsi      # 0xd542
leaq -0x2c(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x48(%rbp), %r8
leaq -0x44(%rbp), %r9
xorl %eax, %eax
leaq -0x30(%rbp), %r10
pushq %r10
leaq -0x34(%rbp), %r10
pushq %r10
callq 0x1060
popq %rcx
popq %rdx
cmpl $-0x1, %eax
je 0xab6a
movl -0x2c(%rbp), %eax
movl %eax, -0x14(%rbx)
movl -0x38(%rbp), %eax
movl %eax, -0x10(%rbx)
movl -0x48(%rbp), %eax
movl %eax, -0xc(%rbx)
movl -0x44(%rbp), %eax
movl %eax, -0x8(%rbx)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbx)
movl -0x30(%rbp), %eax
movl %eax, (%rbx)
movl %r15d, (%r14,%r15,4)
incq %r15
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r12
addq $0x18, %rbx
jmp 0xaaf9
movq %r13, %rdi
callq 0x10a0
decl %r15d
xorl %r13d, %r13d
movq %r14, %rdi
movq -0x70(%rbp), %rsi
movq -0x40(%rbp), %rbx
movq %rbx, %rdx
xorl %ecx, %ecx
movl %r15d, %r8d
callq 0xa60e
movq %rbx, %rsi
sarq $0x20, %r12
xorl %edi, %edi
movq -0x78(%rbp), %r15
movq -0x68(%rbp), %rdx
movslq %r13d, %r13
cmpq %r12, %r13
jge 0xac3f
testq %r15, %r15
je 0xac3f
movslq (%r14,%r13,4), %rax
imulq $0x6, %rax, %rbx
movl (%r15), %eax
cmpl %eax, (%rsi,%rbx,4)
jl 0xabe2
jg 0xabda
movl %ebx, %eax
orl $0x1, %eax
cltq
movl 0x4(%r15), %ecx
cmpl %ecx, (%rsi,%rax,4)
jl 0xabe2
jle 0xabe7
movq 0x28(%r15), %r15
xorl %edi, %edi
jmp 0xabad
incq %r13
jmp 0xaba4
movl %edi, -0x60(%rbp)
pushq $0x18
popq %rdi
movq %rdx, -0x68(%rbp)
callq 0x1190
movq -0x40(%rbp), %rsi
movl 0x8(%rsi,%rbx,4), %ecx
movl %ecx, 0x4(%rax)
movl 0xc(%rsi,%rbx,4), %ecx
movl %ecx, (%rax)
movl 0x10(%rsi,%rbx,4), %ecx
movl %ecx, 0x8(%rax)
movl 0x14(%rsi,%rbx,4), %ecx
movl %ecx, 0xc(%rax)
andq $0x0, 0x10(%rax)
movq -0x68(%rbp), %rdx
addq $0x10, %rdx
leaq 0x38(%r15), %rcx
cmpl $0x0, -0x60(%rbp)
cmovneq %rdx, %rcx
movq %rax, (%rcx)
incq %r13
pushq $0x1
popq %rdi
movq %rax, %rdx
jmp 0xaba1
movq %rsi, %rbx
movq -0x50(%rbp), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq -0x70(%rbp), %rdi
callq 0x1030
movq -0x58(%rbp), %r14
movq %r14, %rdi
callq 0x10b0
shlq $0x20, %rax
movabsq $0x1400000000, %rsi     # imm = 0x1400000000
addq %rax, %rsi
sarq $0x20, %rsi
pushq $0x1
popq %rdi
callq 0x1140
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movq %rbx, %rdi
callq 0x10b0
movabsq $0x2e65726f6e67692d, %rcx # imm = 0x2E65726F6E67692D
movq %rcx, (%rbx,%rax)
movl $0x747874, 0x8(%rbx,%rax) # imm = 0x747874
movq %rbx, %rdi
xorl %esi, %esi
callq 0x11b0
cmpl $-0x1, %eax
je 0xad4f
leaq 0x2568(%rip), %rsi      # 0xd23b
movq %rbx, %rdi
callq 0x11c0
testq %rax, %rax
je 0xad94
movq %rax, %r14
leaq 0x2863(%rip), %r15      # 0xd551
leaq -0x2c(%rbp), %r12
movq -0x78(%rbp), %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x1060
cmpl $-0x1, %eax
je 0xad29
movl -0x2c(%rbp), %eax
testq %r13, %r13
je 0xacf6
cmpl %eax, (%r13)
jl 0xad23
jg 0xacf6
movl $0x1, 0x14(%r13)
movq 0x28(%r13), %r13
jmp 0xad0e
movq %r14, %rdi
callq 0x10a0
movq %rbx, %rdi
callq 0x1030
movq -0x78(%rbp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2519(%rip), %rdi      # 0xd26f
jmp 0xad9b
leaq 0x2761(%rip), %rdi      # 0xd4c0
jmp 0xad68
leaq 0x2797(%rip), %rdi      # 0xd4ff
movq -0x58(%rbp), %rsi
jmp 0xad9e
leaq 0x24fa(%rip), %rdi      # 0xd26f
movq %r14, %rsi
jmp 0xad9e
leaq 0x273f(%rip), %rdi      # 0xd4c0
movq -0x60(%rbp), %rsi
jmp 0xad9e
leaq 0x2732(%rip), %rdi      # 0xd4c0
movq -0x50(%rbp), %rsi
jmp 0xad9e
leaq 0x2725(%rip), %rdi      # 0xd4c0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10c0
pushq $0x1
popq %rdi
callq 0x11f0