// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r15
movq %rdi, 0x8(%rsp)
xorl %eax, %eax
movq %rax, (%rsi)
movq %rax, 0x18(%rsi)
movl $0xffffffff, 0x28(%rsi) # imm = 0xFFFFFFFF
movq $-0x1, 0x20(%rsi)
movq 0x8(%rsp), %r12
leaq 0x1(%r12), %r14
shlq $0x20, %r12
movq %rdi, %rax
shlq $0x20, %rax
subq %rax, %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
movzbl -0x1(%r14), %ecx
testl %ecx, %ecx
je 0x17c7d
cmpl $0x3a, %ecx
je 0x17b1c
incq %r14
addq %rax, %r12
jmp 0x17b02
leaq -0x1(%r14), %rax
movq %rax, 0x8(%rsp)
sarq $0x20, %r12
leaq 0x1(%r12), %rax
cmpq 0x8(%rbx), %rax
jb 0x17b79
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 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2280
addq (%rbx), %r12
movq %r12, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r12)
movq (%rbx), %rax
incq %rax
cmpq 0x8(%rbx), %rax
jb 0x17beb
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), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
xorl %edx, %edx
movb %dl, (%rcx,%rax)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
movb %dl, (%rcx,%rax)
movq %r14, 0x8(%rsp)
callq 0x2460
movq %rax, %r13
movq (%rax), %rax
movsbq (%r14), %rcx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb $0x8, 0x1(%rax,%rcx,2)
je 0x17c8a
leaq 0x8(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x2270
decl %eax
movl %eax, 0x24(%rbx)
movq (%r12), %rdx
cmpb $0x3a, (%rdx)
jne 0x17c8a
leaq 0x1(%rdx), %r14
movq %r14, 0x8(%rsp)
movq (%r13), %rcx
movsbq 0x1(%rdx), %rsi
movzwl (%rcx,%rsi,2), %eax
btl $0xb, %eax
jb 0x17c9b
btl $0xa, %eax
jb 0x17cb2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
cmpb $0x3a, %sil
je 0x17cd6
jmp 0x17cd9
decq %r14
movq %r14, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movl $0xa, %edx
callq 0x2270
xorl %r14d, %r14d
jmp 0x17cd6
movq 0x8(%rsp), %rax
leaq -0x1(%rax), %rsi
subl %edx, %eax
addl $-0x2, %eax
movsbq 0x1(%rsi), %rdx
incq %rsi
incl %eax
testb $0x4, 0x1(%rcx,%rdx,2)
jne 0x17cc0
movq %rsi, 0x8(%rsp)
movl %eax, 0x28(%rbx)
movq 0x8(%rsp), %r12
cmpb $0x3a, (%r12)
jne 0x17c8a
incq %r12
movq %r12, 0x8(%rsp)
cmpl $0x0, 0x28(%rbx)
jns 0x17d12
movq (%r13), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r12, %rdx
movsbq (%rdx), %rsi
incl %eax
incq %rdx
testb $0x4, 0x1(%rcx,%rsi,2)
jne 0x17cff
movl %eax, 0x28(%rbx)
movq 0x8(%rsp), %r15
movb (%r15), %al
testb %al, %al
movq %r13, 0x28(%rsp)
je 0x17d71
movq %r12, 0x18(%rsp)
movq (%r13), %rbp
xorl %r13d, %r13d
testq %r14, %r14
je 0x17d67
movsbq %al, %r12
movzwl (%rbp,%r12,2), %eax
andl $0x400, %eax            # imm = 0x400
je 0x17d67
callq 0x2030
movq (%rax), %rax
movl (%rax,%r12,4), %ecx
movsbq (%r14,%r13), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x17d67
movb 0x1(%r15,%r13), %al
incq %r13
testb %al, %al
jne 0x17d2f
addq %r13, %r15
movq 0x18(%rsp), %r12
jmp 0x17d74
xorl %r13d, %r13d
movq %r15, 0x8(%rsp)
addl %r13d, 0x24(%rbx)
subl %r13d, 0x28(%rbx)
movq (%rbx), %r15
movl %r13d, %ebp
addq %rbp, %r12
movq %r12, %rdi
callq 0x2170
movslq %eax, %r13
leaq (%r15,%r13), %rax
incq %rax
cmpq 0x8(%rbx), %rax
jb 0x17de7
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 0x10(%rbx), %rdi
addq (%rbx), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2280
addq (%rbx), %r13
movq %r13, (%rbx)
movq 0x10(%rbx), %rax
movb $0x0, (%rax,%r13)
movslq %r15d, %rax
addq 0x10(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbx)
testq %r14, %r14
je 0x17ee0
movq %rbp, %rsi
movq (%rbx), %rax
movl %eax, %ecx
subl %r15d, %ecx
movl 0x28(%rbx), %edx
cmpl %ecx, %edx
movl %ecx, %edi
cmovll %edx, %edi
xorl %ebp, %ebp
movl $0x0, %r13d
testl %edi, %edi
jle 0x17ef3
movl %ecx, 0x14(%rsp)
addq %rsi, %r14
movq 0x28(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0x28(%rsp)
movl %edi, 0x34(%rsp)
movl %edi, %ecx
notl %r15d
addl %eax, %r15d
shlq $0x20, %r15
movq %rdx, 0x20(%rsp)
leal -0x1(%rdx), %eax
movq %rax, 0x40(%rsp)
negq %rcx
movq %rcx, 0x38(%rsp)
xorl %r13d, %r13d
movq 0x40(%rsp), %rax
addl %r13d, %eax
cltq
movsbq (%r14,%rax), %r12
movq 0x28(%rsp), %rax
testb $0x4, 0x1(%rax,%r12,2)
je 0x17ee7
callq 0x2030
movq (%rax), %rax
movl (%rax,%r12,4), %ecx
movq %r15, %rdx
sarq $0x20, %rdx
movq 0x18(%rsp), %rsi
movsbq (%rsi,%rdx), %rdx
cmpl (%rax,%rdx,4), %ecx
jne 0x17ee7
decq %r13
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rax, %r15
cmpq %r13, 0x38(%rsp)
jne 0x17e82
movl 0x34(%rsp), %eax
movl %eax, %r13d
jmp 0x17eea
xorl %ebp, %ebp
jmp 0x17c8a
negl %r13d
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %rdx
subl %r13d, %edx
movl %edx, 0x28(%rbx)
subl %r13d, %ecx
movslq %ecx, %rax
movq 0x18(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movl %r13d, %eax
subq %rax, (%rbx)
jmp 0x17c8a