// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bcftools/bcfutils.c
// Function: bcf_gl10
int bcf_gl10(const bcf1_t *b, uint8_t *gl)
{
	int a[4], k, l, map[4], k1, j, i;
	const bcf_ginfo_t *PL;
	char *s;
	if (b->ref[1] != 0 || b->n_alleles > 4) return -1; // ref is not a single base or >4 alleles
	for (i = 0; i < b->n_gi; ++i)
		if (b->gi[i].fmt == bcf_str2int("PL", 2)) break;
	if (i == b->n_gi) return -1; // no PL
	PL = b->gi + i;
	a[0] = nt4_table[(int)b->ref[0]];
	if (a[0] > 3 || a[0] < 0) return -1; // ref is not A/C/G/T
	a[1] = a[2] = a[3] = -2; // -1 has a special meaning
	if (b->alt[0] == 0) return -1; // no alternate allele
	map[0] = map[1] = map[2] = map[3] = -2;
	map[a[0]] = 0;
	for (k = 0, s = b->alt, k1 = -1; k < 3 && *s; ++k, s += 2) {
		if (s[1] != ',' && s[1] != 0) return -1; // ALT is not single base
		a[k+1] = nt4_table[(int)*s];
		if (a[k+1] >= 0) map[a[k+1]] = k+1;
		else k1 = k + 1;
		if (s[1] == 0) break; // the end of the ALT string
	}
	for (k = 0; k < 4; ++k)
		if (map[k] < 0) map[k] = k1;
	for (i = 0; i < b->n_smpl; ++i) {
		const uint8_t *p = PL->data + i * PL->len; // the PL for the i-th individual
		uint8_t *g = gl + 10 * i;
		for (k = j = 0; k < 4; ++k) {
			for (l = k; l < 4; ++l) {
				int t, x = map[k], y = map[l];
				if (x > y) t = x, x = y, y = t; // make sure x is the smaller
				g[j++] = p[y * (y+1) / 2 + x];
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x20(%rdi), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpb $0x0, 0x1(%rdx)
jne 0x3db43
cmpl $0x4, 0x58(%rdi)
jg 0x3db43
movslq 0x48(%rdi), %r8
testq %r8, %r8
jle 0x3d9ae
movq 0x50(%rdi), %r9
xorl %ecx, %ecx
cmpl $0x504c, (%r9)          # imm = 0x504C
je 0x3d9b0
incq %rcx
addq $0x10, %r9
cmpq %rcx, %r8
jne 0x3d994
jmp 0x3db43
xorl %ecx, %ecx
cmpl %r8d, %ecx
je 0x3db43
movsbq (%rdx), %r8
leaq 0x852c(%rip), %rdx      # 0x45ef0
movsbq (%r8,%rdx), %r9
cmpq $0x4, %r9
setge %r10b
andb $-0x21, %r8b
cmpb $0x58, %r8b
sete %r8b
orb %r10b, %r8b
jne 0x3db43
movq 0x28(%rdi), %r8
cmpb $0x0, (%r8)
je 0x3db43
movl %ecx, %ecx
shlq $0x4, %rcx
addq 0x50(%rdi), %rcx
movdqa 0x83fa(%rip), %xmm0     # 0x45e00
movdqa %xmm0, -0x18(%rsp)
movl $0x0, -0x18(%rsp,%r9,4)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
movsbq (%r8,%r9,2), %rbx
testq %rbx, %rbx
je 0x3da6b
movzbl 0x1(%r8,%r9,2), %r10d
cmpl $0x2c, %r10d
je 0x3da3c
testl %r10d, %r10d
jne 0x3db3e
leaq 0x1(%r9), %r11
movl %ebx, %ebp
andb $-0x21, %bpl
cmpb $0x58, %bpl
jne 0x3da51
movl %r11d, %eax
jmp 0x3da5d
movsbq (%rbx,%rdx), %rbx
movl %ebx, %ebx
movl %r11d, -0x18(%rsp,%rbx,4)
testb %r10b, %r10b
je 0x3da6b
cmpl $0x2, %r9d
movq %r11, %r9
jne 0x3da1d
movd %eax, %xmm0
pshufd $0x0, %xmm0, %xmm0      # xmm0 = xmm0[0,0,0,0]
movdqa -0x18(%rsp), %xmm1
pxor %xmm2, %xmm2
pcmpgtd %xmm1, %xmm2
pand %xmm2, %xmm0
pandn %xmm1, %xmm2
por %xmm0, %xmm2
movdqa %xmm2, -0x18(%rsp)
cmpl $0x0, 0x5c(%rdi)
jle 0x3db3a
xorl %edx, %edx
movslq 0x4(%rcx), %r9
movslq %edx, %rax
imulq %r9, %rax
addq 0x8(%rcx), %rax
movl $0x4, %r9d
leaq -0x18(%rsp), %r10
xorl %r11d, %r11d
xorl %ebx, %ebx
movslq %r11d, %r14
addq %rsi, %r14
movl -0x18(%rsp,%rbx,4), %ebp
xorl %r15d, %r15d
movl (%r10,%r15,4), %r12d
cmpl %r12d, %ebp
movl %r12d, %r13d
cmovll %ebp, %r13d
cmovgl %ebp, %r12d
leal 0x1(%r12), %r8d
imull %r12d, %r8d
movl %r8d, %r12d
shrl $0x1f, %r12d
addl %r8d, %r12d
sarl %r12d
addl %r13d, %r12d
movslq %r12d, %r8
movb (%rax,%r8), %r8b
movb %r8b, (%r14,%r15)
incq %r15
leal (%rbx,%r15), %r8d
cmpl $0x4, %r8d
jne 0x3dacc
incq %rbx
addl %r9d, %r11d
decl %r9d
addq $0x4, %r10
cmpq $0x4, %rbx
jne 0x3dabf
incq %rdx
movslq 0x5c(%rdi), %r8
addq $0xa, %rsi
xorl %eax, %eax
cmpq %r8, %rdx
jl 0x3daa0
jmp 0x3db43
xorl %eax, %eax
jmp 0x3db43
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq