// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
andq $0x0, (%rdi)
movb $0x0, 0x10(%rdi)
movq %rsi, %rdi
callq 0x2140
testl %eax, %eax
je 0x2dbb
cltq
leaq (%rax,%r14), %r12
decq %r12
movl %eax, %ebp
negl %ebp
xorl %r15d, %r15d
movsbl (%r12,%r15), %edi
callq 0x2050
testl %eax, %eax
je 0x2bd9
movb $0x0, (%r12,%r15)
decq %r15
jmp 0x2bc1
incq %r14
subl %r15d, %ebp
movb -0x1(%r14), %r15b
movsbl %r15b, %edi
callq 0x2050
testl %eax, %eax
je 0x2bf7
incq %r14
incl %ebp
jmp 0x2bdf
movzbl %r15b, %eax
cmpl $0x2d, %eax
je 0x2c05
cmpl $0x2b, %eax
jne 0x2c10
movb %r15b, 0x10(%rbx)
notl %ebp
movb (%r14), %r15b
jmp 0x2c1b
decq %r14
negl %ebp
cmpb $0x0, 0x10(%rbx)
je 0x2c2f
cmpb $0x3a, %r15b
je 0x2c2a
movzbl %r15b, %eax
cmpl $0x20, %eax
jne 0x2c2f
incq %r14
decl %ebp
leaq 0x9486(%rip), %rsi      # 0xc0bc
movq %r14, %rdi
callq 0x23f0
movabsq $0x680000000000, %r12   # imm = 0x680000000000
testq %rax, %rax
jne 0x2c60
pushq $0x3a
popq %rsi
movq %r14, %rdi
callq 0x2100
movq %r14, %r15
testq %rax, %rax
je 0x2ccc
leaq 0x1(%rax), %r15
movb $0x0, (%rax)
cmpb $0x0, 0x10(%rbx)
jne 0x2cba
movb 0x1(%rax), %cl
movzbl %cl, %edx
cmpl $0x2e, %edx
ja 0x2ca3
movl %edx, %edx
btq %rdx, %r12
jae 0x2ca3
movzbl 0x2(%rax), %edx
cmpq $0x3a, %rdx
ja 0x2ca3
movabsq $0x400000100000200, %rsi # imm = 0x400000100000200
btq %rdx, %rsi
jae 0x2ca3
movb %cl, 0x10(%rbx)
leaq 0x3(%rax), %r15
jmp 0x2cba
movzbl -0x1(%rax), %ecx
cmpl $0x2d, %ecx
je 0x2cb1
cmpl $0x2b, %ecx
jne 0x2cba
decq %rax
movb %cl, 0x10(%rbx)
movb $0x0, (%rax)
decq %rax
movq %r14, %rdi
movq %rax, %rsi
callq 0x2788
movq %rax, 0x8(%rbx)
movsbl (%r15), %r13d
movl %r13d, %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2d05
movq %r15, %r12
movsbl 0x1(%r12), %r13d
incq %r12
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0x2cde
movb $0x0, (%r12)
movq %r15, %rdi
callq 0x23b0
movl %eax, (%rbx)
movb %r13b, (%r12)
jmp 0x2d08
movq %r15, %r12
movabsq $0x600100000200, %rax   # imm = 0x600100000200
cmpb $0x2e, %r13b
ja 0x2d2c
movzbl %r13b, %ecx
btq %rcx, %rax
jae 0x2d2c
movb 0x1(%r12), %r13b
incq %r12
jmp 0x2d12
leaq -0x1(%r12), %r15
movsbl 0x1(%r15), %r13d
incq %r15
leal -0x30(%r13), %eax
cmpl $0xa, %eax
jb 0x2d31
cmpq %r12, %r15
jbe 0x2d59
movb $0x0, (%r15)
movq %r12, %rdi
callq 0x23b0
movl %eax, 0x4(%rbx)
movb %r13b, (%r15)
movl (%rbx), %eax
testl %eax, %eax
je 0x2d77
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
sete %dl
cmpl %eax, %ecx
setae %sil
orb %dl, %sil
jne 0x2d77
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
movslq %ebp, %rcx
movzbl -0x1(%rcx,%r14), %eax
cmpq $0x2e, %rax
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
ja 0x2dbb
btq %rax, %rdx
jae 0x2dbb
cmpl $0x0, 0x4(%rbx)
jne 0x2db8
movzbl -0x2(%rcx,%r14), %ecx
cmpq $0x3a, %rcx
ja 0x2dbb
movabsq $0x400000100000200, %rdx # imm = 0x400000100000200
btq %rcx, %rdx
jae 0x2dbb
movb %al, 0x10(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq