// File: /workspace/github_cpp_makefile_star2_O1/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 0x300e
movslq %r15d, %rax
movsbl -0x1(%r14,%rax), %edi
callq 0x2050
testl %eax, %eax
je 0x2e34
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 0x2e1a
movb (%r14), %bpl
movsbl %bpl, %edi
callq 0x2050
testl %eax, %eax
je 0x2e50
decl %r15d
movb 0x1(%r14), %bpl
incq %r14
jmp 0x2e37
cmpb $0x2d, %bpl
je 0x2e5f
movzbl %bpl, %eax
cmpl $0x2b, %eax
jne 0x2e69
movb %bpl, 0x10(%rbx)
incq %r14
decl %r15d
cmpb $0x0, 0x10(%rbx)
je 0x2e83
movzbl (%r14), %eax
cmpl $0x3a, %eax
je 0x2e7d
cmpl $0x20, %eax
jne 0x2e83
incq %r14
decl %r15d
leaq 0xb232(%rip), %rsi      # 0xe0bc
movq %r14, %rdi
callq 0x23f0
testq %rax, %rax
jne 0x2ea4
movq %r14, %rdi
movl $0x3a, %esi
callq 0x2100
movabsq $0x680000000000, %rsi   # imm = 0x680000000000
movq %r14, %r12
testq %rax, %rax
je 0x2f26
leaq 0x1(%rax), %r12
movb $0x0, (%rax)
cmpb $0x0, 0x10(%rbx)
jne 0x2ef7
movb 0x1(%rax), %cl
movzbl %cl, %edx
cmpl $0x2e, %edx
ja 0x2ef7
movl %edx, %edx
btq %rdx, %rsi
jae 0x2ef7
movzbl 0x2(%rax), %edx
cmpq $0x3a, %rdx
ja 0x2ef7
movabsq $0x400000100000200, %rsi # imm = 0x400000100000200
btq %rdx, %rsi
jae 0x2ef7
movb %cl, 0x10(%rbx)
leaq 0x3(%rax), %r12
cmpb $0x0, 0x10(%rbx)
jne 0x2f14
movzbl -0x1(%rax), %ecx
cmpl $0x2d, %ecx
je 0x2f0b
cmpl $0x2b, %ecx
jne 0x2f14
decq %rax
movb %cl, 0x10(%rbx)
movb $0x0, (%rax)
decq %rax
movq %r14, %rdi
movq %rax, %rsi
callq 0x29ac
movq %rax, 0x8(%rbx)
movsbl (%r12), %eax
addl $-0x30, %eax
cmpl $0x9, %eax
ja 0x2f5b
movq %r12, %r13
movsbl 0x1(%r13), %ebp
incq %r13
leal -0x30(%rbp), %eax
cmpl $0xa, %eax
jb 0x2f36
movb $0x0, (%r13)
movq %r12, %rdi
callq 0x23b0
movl %eax, (%rbx)
movb %bpl, (%r13)
jmp 0x2f5e
movq %r12, %r13
movabsq $0x600100000200, %rax   # imm = 0x600100000200
movzbl (%r13), %ecx
cmpq $0x2e, %rcx
ja 0x2f7e
btq %rcx, %rax
jae 0x2f7e
incq %r13
jmp 0x2f68
leaq -0x1(%r13), %r12
movsbl 0x1(%r12), %ebp
incq %r12
leal -0x30(%rbp), %eax
cmpl $0xa, %eax
jb 0x2f82
cmpq %r13, %r12
jbe 0x2fac
movb $0x0, (%r12)
movq %r13, %rdi
callq 0x23b0
movl %eax, 0x4(%rbx)
movb %bpl, (%r12)
movl (%rbx), %eax
testl %eax, %eax
je 0x2fca
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
sete %dl
cmpl %eax, %ecx
setae %sil
orb %dl, %sil
jne 0x2fca
movl %ecx, (%rbx)
movl %eax, 0x4(%rbx)
movslq %r15d, %rcx
movzbl -0x1(%rcx,%r14), %eax
cmpq $0x2e, %rax
movabsq $0x680000000000, %rdx   # imm = 0x680000000000
ja 0x300e
btq %rax, %rdx
jae 0x300e
cmpl $0x0, 0x4(%rbx)
jne 0x300b
movzbl -0x2(%rcx,%r14), %ecx
cmpq $0x3a, %rcx
ja 0x300e
movabsq $0x400000100000200, %rdx # imm = 0x400000100000200
btq %rcx, %rdx
jae 0x300e
movb %al, 0x10(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq