// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %r12
movq %rdi, 0x8(%rsp)
xorl %r15d, %r15d
movq %r15, (%rsi)
movq %r15, 0x18(%rsi)
movl $0xffffffff, 0x28(%rsi) # imm = 0xFFFFFFFF
movq $-0x1, 0x20(%rsi)
leaq 0x1(%rdi), %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
movzbl -0x1(%r14), %ecx
testl %ecx, %ecx
je 0x18393
cmpl $0x3a, %ecx
je 0x1837d
addq %rax, %r15
incq %r14
jmp 0x18367
sarq $0x20, %r15
leaq 0x1(%r15), %rax
cmpq 0x8(%rbx), %rax
jae 0x1839d
movq 0x10(%rbx), %rax
xorl %edi, %edi
jmp 0x183e5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x18780
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x2330
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
addq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x2280
addq (%rbx), %r15
movq %r15, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r15)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
cmpq 0x8(%rbx), %rdx
jae 0x18415
movq 0x10(%rbx), %rax
jmp 0x18461
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rsi
shrq $0x10, %rsi
orq %rcx, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x2330
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
xorl %edx, %edx
movb %dl, (%rax,%rcx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb %dl, (%rcx,%rax)
movq %r14, 0x8(%rsp)
callq 0x2460
movq %rax, %r15
movq (%rax), %rax
movsbq (%r14), %rcx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb $0x8, 0x1(%rax,%rcx,2)
je 0x18780
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2270
decl %eax
movl %eax, 0x24(%rbx)
movq (%r12), %r12
cmpb $0x3a, (%r12)
jne 0x18780
leaq 0x1(%r12), %r14
movq %r14, 0x8(%rsp)
movq (%r15), %rax
movsbq 0x1(%r12), %rcx
movzwl (%rax,%rcx,2), %edx
btl $0xb, %edx
jb 0x184f7
btl $0xa, %edx
jb 0x18518
cmpb $0x3a, %cl
jne 0x184ef
movl $0xffffffff, 0x28(%rbx) # imm = 0xFFFFFFFF
movq %r14, %r12
xorl %r14d, %r14d
jmp 0x18537
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2270
movl %eax, 0x28(%rbx)
xorl %r14d, %r14d
movq (%r12), %r12
jmp 0x18537
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movsbq 0x1(%r12), %rdx
incq %r12
incl %ecx
testb $0x4, 0x1(%rax,%rdx,2)
jne 0x1851d
movq %r12, 0x8(%rsp)
movl %ecx, 0x28(%rbx)
cmpb $0x3a, (%r12)
jne 0x18780
leaq 0x1(%r12), %rsi
movq %rsi, 0x8(%rsp)
movl 0x28(%rbx), %r13d
testl %r13d, %r13d
jns 0x18576
movq (%r15), %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %rsi, %rcx
movsbq (%rcx), %rdx
incl %r13d
incq %rcx
testb $0x4, 0x1(%rax,%rdx,2)
jne 0x18561
movl %r13d, 0x28(%rbx)
movq %rsi, 0x18(%rsp)
movb (%rsi), %al
testb %al, %al
je 0x185d3
movq %r15, (%rsp)
movq (%r15), %rcx
movq %rcx, 0x10(%rsp)
xorl %ebp, %ebp
movq %r14, %r15
testq %r14, %r14
je 0x185d7
movsbq %al, %r14
movq 0x10(%rsp), %rax
movzwl (%rax,%r14,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x185d7
callq 0x2030
movq (%rax), %rax
movl (%rax,%r14,4), %ecx
movq %r15, %r14
movsbq (%r15,%rbp), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x185da
movb 0x2(%r12,%rbp), %al
incq %rbp
testb %al, %al
jne 0x1858f
jmp 0x185da
xorl %ebp, %ebp
jmp 0x185de
movq %r15, %r14
movq (%rsp), %r15
addl %ebp, 0x24(%rbx)
subl %ebp, %r13d
movl %r13d, 0x28(%rbx)
movq (%rbx), %rax
movl %ebp, %ecx
movq %rax, %rbp
movq 0x18(%rsp), %r12
movq %rcx, (%rsp)
addq %rcx, %r12
movq %r12, %rdi
callq 0x2170
movslq %eax, %r13
leaq 0x1(,%r13), %rax
addq %rbp, %rax
cmpq 0x8(%rbx), %rax
jae 0x18621
movq 0x10(%rbx), %rax
movq %rbp, %rdi
jmp 0x18669
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
callq 0x2330
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
addq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2280
addq (%rbx), %r13
movq %r13, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r13)
movslq %ebp, %rax
addq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movq %rax, 0x18(%rbx)
testq %r14, %r14
je 0x18753
movq (%rbx), %rax
movl %eax, %ecx
subl %ebp, %ecx
movl 0x28(%rbx), %r13d
cmpl %ecx, %r13d
movl %ecx, 0x24(%rsp)
movl %ecx, %esi
cmovll %r13d, %esi
movq %rbp, %rcx
xorl %ebp, %ebp
movl $0x0, %r12d
testl %esi, %esi
jle 0x18761
addq (%rsp), %r14
movq (%r15), %rdi
movq %rdi, 0x18(%rsp)
movl %esi, %edi
leal -0x1(%r13), %r8d
movq %r8, (%rsp)
notl %ecx
addl %eax, %ecx
movq %rcx, 0x30(%rsp)
negq %rdi
movq %rdi, 0x28(%rsp)
xorl %r12d, %r12d
movq (%rsp), %rax
addl %r12d, %eax
cltq
movq %r14, %r15
movsbq (%r14,%rax), %r14
movq 0x18(%rsp), %rax
testb $0x4, 0x1(%rax,%r14,2)
je 0x18757
movl %esi, %ebp
callq 0x2030
movq (%rax), %rax
movl (%rax,%r14,4), %ecx
movq 0x30(%rsp), %rdx
addl %r12d, %edx
movslq %edx, %rdx
movq 0x10(%rsp), %rsi
movsbq (%rsi,%rdx), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x1875c
decq %r12
cmpq %r12, 0x28(%rsp)
movq %r15, %r14
movl %ebp, %esi
movl $0x0, %ebp
jne 0x186f4
movl %esi, %r12d
jmp 0x18761
xorl %ebp, %ebp
jmp 0x18780
negl %r12d
jmp 0x18761
negl %r12d
xorl %ebp, %ebp
subl %r12d, %r13d
movl %r13d, 0x28(%rbx)
movl 0x24(%rsp), %eax
subl %r12d, %eax
cltq
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %r12d, %eax
subq %rax, (%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq