// File: /workspace/github_cpp_makefile_star2_O3/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
movq $0x0, (%rdi)
movb $0x0, 0x10(%rdi)
movq %rsi, %rdi
callq 0x2140
movq %rax, %r15
testl %r15d, %r15d
je 0x2fc8
movslq %r15d, %rax
movsbl -0x1(%r14,%rax), %edi
callq 0x2050
testl %eax, %eax
je 0x2de6
movslq %r15d, %rax
leaq (%rax,%r14), %r12
decq %r12
movb $0x0, (%r12)
movsbl -0x1(%r12), %edi
decq %r12
callq 0x2050
decl %r15d
testl %eax, %eax
jne 0x2dcc
movb (%r14), %bpl
movsbl %bpl, %edi
callq 0x2050
testl %eax, %eax
je 0x2e02
decl %r15d
movb 0x1(%r14), %bpl
incq %r14
jmp 0x2de9
cmpb $0x2d, %bpl
je 0x2e11
movzbl %bpl, %eax
cmpl $0x2b, %eax
jne 0x2e21
movb %bpl, 0x10(%rbx)
decl %r15d
movb 0x1(%r14), %bpl
incq %r14
jmp 0x2e27
cmpb $0x0, 0x10(%rbx)
je 0x2e3c
cmpb $0x3a, %bpl
je 0x2e36
movzbl %bpl, %eax
cmpl $0x20, %eax
jne 0x2e3c
incq %r14
decl %r15d
leaq 0xb279(%rip), %rsi      # 0xe0bc
movq %r14, %rdi
callq 0x23f0
movabsq $0x680000000000, %r13   # imm = 0x680000000000
testq %rax, %rax
jne 0x2e6f
movq %r14, %rdi
movl $0x3a, %esi
callq 0x2100
movq %r14, %r12
testq %rax, %rax
je 0x2edb
leaq 0x1(%rax), %r12
movb $0x0, (%rax)
cmpb $0x0, 0x10(%rbx)
jne 0x2ec9
movb 0x1(%rax), %cl
movzbl %cl, %edx
cmpl $0x2e, %edx
ja 0x2eb2
movl %edx, %edx
btq %rdx, %r13
jae 0x2eb2
movzbl 0x2(%rax), %edx
cmpq $0x3a, %rdx
ja 0x2eb2
movabsq $0x400000100000200, %rsi # imm = 0x400000100000200
btq %rdx, %rsi
jae 0x2eb2
movb %cl, 0x10(%rbx)
leaq 0x3(%rax), %r12
jmp 0x2ec9
movzbl -0x1(%rax), %ecx
cmpl $0x2d, %ecx
je 0x2ec0
cmpl $0x2b, %ecx
jne 0x2ec9
decq %rax
movb %cl, 0x10(%rbx)
movb $0x0, (%rax)
decq %rax
movq %r14, %rdi
movq %rax, %rsi
callq 0x2978
movq %rax, 0x8(%rbx)
movsbl (%r12), %ebp
movl %ebp, %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2f12
movq %r12, %r13
movsbl 0x1(%r13), %ebp
incq %r13
leal -0x30(%rbp), %eax
cmpl $0xa, %eax
jb 0x2eed
movb $0x0, (%r13)
movq %r12, %rdi
callq 0x23b0
movl %eax, (%rbx)
movb %bpl, (%r13)
jmp 0x2f15
movq %r12, %r13
movabsq $0x600100000200, %rax   # imm = 0x600100000200
cmpb $0x2e, %bpl
ja 0x2f38
movzbl %bpl, %ecx
btq %rcx, %rax
jae 0x2f38
movb 0x1(%r13), %bpl
incq %r13
jmp 0x2f1f
leaq -0x1(%r13), %r12
movsbl 0x1(%r12), %ebp
incq %r12
leal -0x30(%rbp), %eax
cmpl $0xa, %eax
jb 0x2f3c
cmpq %r13, %r12
jbe 0x2f66
movb $0x0, (%r12)
movq %r13, %rdi
callq 0x23b0
movl %eax, 0x4(%rbx)
movb %bpl, (%r12)
movl (%rbx), %eax
testl %eax, %eax
je 0x2f84
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
sete %dl
cmpl %eax, %ecx
setae %sil
orb %dl, %sil
jne 0x2f84
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
movslq %r15d, %rcx
movzbl -0x1(%rcx,%r14), %eax
cmpq $0x2e, %rax
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
ja 0x2fc8
btq %rax, %rdx
jae 0x2fc8
cmpl $0x0, 0x4(%rbx)
jne 0x2fc5
movzbl -0x2(%rcx,%r14), %ecx
cmpq $0x3a, %rcx
ja 0x2fc8
movabsq $0x400000100000200, %rdx # imm = 0x400000100000200
btq %rcx, %rdx
jae 0x2fc8
movb %al, 0x10(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq