// File: /workspace/github_c_makefile_star2_O2/lh3[P]bgt/bgt.c
// Function: bgt_al_parse
int bgt_al_parse(const char *al, bgt_allele_t *a) // TODO: add bgt_al_atomize()
{
	char *p = (char*)al, *ref = 0, *alt = 0;
	int sep = ':', off, tmp, i;
	a->chr.l = 0; a->al = 0; a->pos = -1; a->rlen = -1; a->rid = -1;
	for (; *p && *p != sep; ++p);
	if (*p == 0) return -1;
	kputsn(al, p - al, &a->chr); kputc(0, &a->chr);
	++p; // skip the delimiter
	if (!isdigit(*p)) return -1;
	a->pos = strtol(p, &p, 10) - 1; // read position
	if (*p != sep) return -1;
	++p; // skip the delimiter
	if (isdigit(*p)) {
		a->rlen = strtol(p, &p, 10);
	} else if (isalpha(*p)) {
		ref = p;
		for (; isalpha(*p); ++p);
		a->rlen = p - ref;
	} else if (*p == sep) { // a reference allele
		a->rlen = -1;
	}
	if (*p != sep) return -1;
	alt = ++p;
	if (a->rlen < 0) {
		for (i = 0; isalpha(alt[i]); ++i);
		a->rlen = i;
	}
	for (off = 0; *p && isalpha(*p); ++p)
		if (ref && toupper(*p) == toupper(ref[off])) ++off;
		else break;
	a->pos += off; a->rlen -= off;
	tmp = a->chr.l;
	kputs(alt + off, &a->chr);
	a->al = a->chr.s + tmp;
	if (ref) {
		int l_alt = a->chr.s + a->chr.l - a->al;
		int min_l = l_alt < a->rlen? l_alt : a->rlen;
		ref += off;
		for (off = 0; off < min_l && isalpha(ref[a->rlen - 1 - off]) && toupper(ref[a->rlen - 1 - off]) == toupper(a->al[l_alt - 1 - off]); ++off);
		a->rlen -= off;
		a->al[l_alt - off] = 0;
		a->chr.l -= off;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
andq $0x0, (%rsi)
andq $0x0, 0x18(%rsi)
movq %rdi, %r14
orl $-0x1, 0x28(%rsi)
orq $-0x1, 0x20(%rsi)
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0x12d15
cmpl $0x3a, %eax
je 0x12c7f
incq %r15
jmp 0x12c68
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x11a85
xorl %edi, %edi
movq %rbx, %rsi
callq 0x11b3c
addq %r14, %r15
incq %r15
movq %r15, (%rsp)
callq 0x2470
movq %rax, 0x8(%rsp)
movq (%rax), %rax
movsbq (%r15), %rcx
pushq $-0x1
popq %rbp
testb $0x8, 0x1(%rax,%rcx,2)
je 0x12d18
movq %rsp, %r12
pushq $0xa
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2270
decl %eax
movl %eax, 0x24(%rbx)
movq (%r12), %r12
cmpb $0x3a, (%r12)
jne 0x12d18
leaq 0x1(%r12), %r15
movq %r15, (%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsbq 0x1(%r12), %rcx
movzwl (%rax,%rcx,2), %edx
btl $0xb, %edx
jb 0x12d29
btl $0xa, %edx
jb 0x12d46
cmpb $0x3a, %cl
jne 0x12d0d
orl $-0x1, 0x28(%rbx)
movq %r15, %r12
xorl %r15d, %r15d
jmp 0x12d62
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %r12
pushq $0xa
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2270
movl %eax, 0x28(%rbx)
xorl %r15d, %r15d
movq (%r12), %r12
jmp 0x12d62
pushq $-0x1
popq %rcx
movsbq 0x1(%r12), %rdx
incq %r12
incl %ecx
testb $0x4, 0x1(%rax,%rdx,2)
jne 0x12d49
movq %r12, (%rsp)
movl %ecx, 0x28(%rbx)
cmpb $0x3a, (%r12)
jne 0x12d18
incq %r12
movq %r12, (%rsp)
movl 0x28(%rbx), %ebp
testl %ebp, %ebp
jns 0x12d98
movq 0x8(%rsp), %rax
movq (%rax), %rax
pushq $-0x1
popq %rbp
movq %r12, %rcx
movsbq (%rcx), %rdx
incl %ebp
incq %rcx
testb $0x4, 0x1(%rax,%rdx,2)
jne 0x12d85
movl %ebp, 0x28(%rbx)
xorl %r13d, %r13d
movsbq (%r12,%r13), %r14
testq %r14, %r14
je 0x12dd9
testq %r15, %r15
je 0x12dd9
movq 0x8(%rsp), %rax
movq (%rax), %rax
movzwl (%rax,%r14,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x12dd9
callq 0x2030
movq (%rax), %rax
movl (%rax,%r14,4), %ecx
movsbq (%r15,%r13), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x12dd9
incq %r13
jmp 0x12d9b
addl %r13d, 0x24(%rbx)
subl %r13d, %ebp
movl %ebp, 0x28(%rbx)
movq (%rbx), %r14
movl %r13d, %r13d
addq %r13, %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x11b19
movslq %r14d, %rax
addq 0x10(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbx)
testq %r15, %r15
je 0x12ec4
movl (%rbx), %eax
movl 0x28(%rbx), %edx
movl %eax, %ecx
subl %r14d, %ecx
cmpl %ecx, %edx
movl %ecx, 0x14(%rsp)
cmovll %edx, %ecx
addq %r13, %r15
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
movq %rdx, 0x28(%rsp)
decl %edx
movq %rdx, 0x30(%rsp)
notl %r14d
addl %eax, %r14d
movq %rcx, 0x20(%rsp)
movq %rcx, %r13
negq %r13
cmpq %rbp, %r13
je 0x12e9f
movq %r14, %r12
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rcx
addl %ebp, %ecx
movslq %ecx, %rcx
movsbq (%r15,%rcx), %r14
testb $0x4, 0x1(%rax,%r14,2)
je 0x12e9b
callq 0x2030
movq (%rax), %rax
movl (%rax,%r14,4), %ecx
leal (%r12,%rbp), %edx
movslq %edx, %rdx
movq 0x18(%rsp), %rsi
movsbq (%rsi,%rdx), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x12e9b
movq %r12, %r14
decq %rbp
jmp 0x12e4a
negl %ebp
jmp 0x12ea4
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %rax
subl %ebp, %eax
movl %eax, 0x28(%rbx)
movl 0x14(%rsp), %eax
subl %ebp, %eax
cltq
movq 0x18(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %ebp, %eax
subq %rax, (%rbx)
xorl %ebp, %ebp
jmp 0x12d18