// File: gpertea[P]gclib/GBase.cpp
// Function: GRangeParser::parse(char*)
void GRangeParser::parse(char* s) {
	 //parses general range format: [+\-|.]refID[+\-\.][ |:][start][-|.\s]end[\s:][+\-\.]
	// if ref ID has ':' a space delimited format is preferred
	//   or just separate the ref ID from the coordinate range: [[+/-]ref<space>start[[-..][end]]
	//the safest way would be to parse from the end in case the ref ID has ':' characters
	//if the whole chromosome is intended (no coordinates to speficy)
	   this->start=0;
	   this->end=0;
	   this->strand=0;
	   int slen=strlen(s);
	   if (slen==0) return;
	   while (isspace(s[slen-1])) { slen--; s[slen]=0; } //trim trailing spaces
	   while (isspace(*s)) { ++s; --slen; } //trim prefix spaces
	   char c=*s;
	   if (c=='+' || c=='-') {
	     strand=c;
	     ++s;slen--;
	   }
	   if (strand && (*s==':' || *s==' ')) //ignore
		   { s++;slen--; }
	   char* p=s; //parsing position for coordinate string
	   char* isep=strpbrk(s, " \t");
	   if (isep==NULL) isep=strchr(s, ':');
	   if (isep) { //chr (ref) ID ending found
		  p=isep+1;
		  *isep=0;
	       //character after the delimiter can only be a strand if it's followed by another delimiter
		   //e.g. chr1 + 134551-204326 or chr1:+:134551-204326
		  c=*(isep+1);
		  if (strand==0 && (c=='+' || c=='-' || c=='.') && IS_CHR_DELIM(*(isep+2))) {
			  strand=c;
			  p=isep+3;
		  }
		  if (strand==0) {
			  c=*(isep-1); //character before the delimiter could be the strand
			  if (c=='+' || c=='-') { //not '.', sorry
				isep--;
				strand=c;
				*isep=0; //ref is now parsable
			  }
		  }
		  this->refName=Gstrdup(s,isep-1);
	   }
	   //here we are after ref ID (and possibly strand) delimiter
	   char* pend=p;
	   if (isdigit(*pend)) {
		 //parse the start coordinate then
		 do { pend++; } while (isdigit(*pend));
		 c=*pend;
		 *pend=0;
		 this->start=atoi(p);
		 p=pend;
		 *p=c;
	   }
	   while (*p=='-' || *p=='.' || *p==' ' || *p=='\t') ++p;
	   pend=p;
	   while (isdigit(*pend)) pend++;
	   if (pend>p) { //parse the 2nd coordinate
		   c=*pend;
		   *pend=0;
		   this->end=atoi(p);
		   *pend=c;
	   }
	   if (start && end && end<start) Gswap(this->start, this->end);
	   //if (strand==0) { ?
	   c=s[slen-1]; //peek at the end of the string for strand
	   if (c=='+' || c=='-' || c=='.') {
		   if (end || IS_CHR_DELIM(s[slen-2]))
		   strand=c;
		   //slen--;s[slen]=0;
	   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, (%rax)
movl $0x0, 0x4(%rax)
movb $0x0, 0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x2140
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2fd0
jmp 0x339b
jmp 0x2fd2
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %edi
callq 0x2050
cmpl $0x0, %eax
je 0x3004
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x2fd2
jmp 0x3006
movq -0x10(%rbp), %rax
movsbl (%rax), %edi
callq 0x2050
cmpl $0x0, %eax
je 0x302e
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3006
movq -0x10(%rbp), %rax
movb (%rax), %al
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0x2b, %eax
je 0x3049
movsbl -0x15(%rbp), %eax
cmpl $0x2d, %eax
jne 0x3068
movq -0x38(%rbp), %rax
movb -0x15(%rbp), %cl
movb %cl, 0x10(%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x309f
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0x308a
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x309f
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1100f(%rip), %rsi     # 0x140c1
callq 0x23f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x30d4
movq -0x10(%rbp), %rdi
movl $0x3a, %esi
callq 0x2100
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x31c5
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movb $0x0, (%rcx)
movq -0x28(%rbp), %rcx
movb 0x1(%rcx), %cl
movb %cl, -0x15(%rbp)
movsbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x3161
movsbl -0x15(%rbp), %eax
cmpl $0x2b, %eax
je 0x3124
movsbl -0x15(%rbp), %eax
cmpl $0x2d, %eax
je 0x3124
movsbl -0x15(%rbp), %eax
cmpl $0x2e, %eax
jne 0x3161
movq -0x28(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x20, %eax
je 0x314b
movq -0x28(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x9, %eax
je 0x314b
movq -0x28(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x3a, %eax
jne 0x3161
movq -0x38(%rbp), %rax
movb -0x15(%rbp), %cl
movb %cl, 0x10(%rax)
movq -0x28(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movsbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x31a9
movq -0x28(%rbp), %rax
movb -0x1(%rax), %al
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0x2b, %eax
je 0x318a
movsbl -0x15(%rbp), %eax
cmpl $0x2d, %eax
jne 0x31a7
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
addq $-0x1, %rcx
movq %rcx, -0x28(%rbp)
movb -0x15(%rbp), %cl
movb %cl, 0x10(%rax)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0x31a9
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $-0x1, %rsi
callq 0x2880
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %edi
callq 0x2210
cmpl $0x0, %eax
je 0x322f
jmp 0x31e0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %edi
callq 0x2210
cmpl $0x0, %eax
jne 0x31e0
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x15(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x23b0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
movb -0x15(%rbp), %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
jmp 0x3231
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2d, %ecx
movb %al, -0x39(%rbp)
je 0x3274
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x2e, %ecx
movb %al, -0x39(%rbp)
je 0x3274
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x39(%rbp)
je 0x3274
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x327d
jmp 0x328b
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3231
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %edi
callq 0x2210
cmpl $0x0, %eax
je 0x32b2
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3293
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x32e7
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x15(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x23b0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x4(%rax)
movb -0x15(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
je 0x3315
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x3315
movq -0x38(%rbp), %rcx
movl 0x4(%rcx), %eax
cmpl (%rcx), %eax
jae 0x3315
movq -0x38(%rbp), %rdi
movq %rdi, %rsi
addq $0x4, %rsi
callq 0x5b30
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0x2b, %eax
je 0x3343
movsbl -0x15(%rbp), %eax
cmpl $0x2d, %eax
je 0x3343
movsbl -0x15(%rbp), %eax
cmpl $0x2e, %eax
jne 0x339b
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x338f
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0x338f
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
je 0x338f
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x3399
movq -0x38(%rbp), %rax
movb -0x15(%rbp), %cl
movb %cl, 0x10(%rax)
jmp 0x339b
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)