// File: /workspace/github_c_makefile_star2_O1/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 0x3d269
cmpl $0x4, 0x58(%rdi)
jg 0x3d269
movl 0x48(%rdi), %r8d
testl %r8d, %r8d
jle 0x3d0e1
movq 0x50(%rdi), %r9
xorl %ecx, %ecx
cmpl $0x504c, (%r9)          # imm = 0x504C
je 0x3d0e3
incq %rcx
addq $0x10, %r9
cmpq %rcx, %r8
jne 0x3d0c7
movl %r8d, %ecx
jmp 0x3d0e3
xorl %ecx, %ecx
cmpl %r8d, %ecx
je 0x3d269
movsbq (%rdx), %r8
leaq 0x7ce9(%rip), %rdx      # 0x44de0
movsbq (%r8,%rdx), %r9
cmpq $0x4, %r9
setge %r10b
andb $-0x21, %r8b
cmpb $0x58, %r8b
sete %r8b
orb %r10b, %r8b
jne 0x3d269
movq 0x28(%rdi), %r8
cmpb $0x0, (%r8)
je 0x3d269
movl %ecx, %ecx
shlq $0x4, %rcx
addq 0x50(%rdi), %rcx
movabsq $-0x100000002, %rax     # imm = 0xFFFFFFFEFFFFFFFE
movq %rax, -0x10(%rsp)
movq %rax, -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 0x3d1a4
movzbl 0x1(%r8,%r9,2), %r10d
cmpl $0x2c, %r10d
je 0x3d175
testl %r10d, %r10d
jne 0x3d264
leaq 0x1(%r9), %r11
movl %ebx, %ebp
andb $-0x21, %bpl
cmpb $0x58, %bpl
jne 0x3d18a
movl %r11d, %eax
jmp 0x3d196
movsbq (%rbx,%rdx), %rbx
movl %ebx, %ebx
movl %r11d, -0x18(%rsp,%rbx,4)
testb %r10b, %r10b
je 0x3d1a4
cmpl $0x2, %r9d
movq %r11, %r9
jne 0x3d156
xorl %edx, %edx
movl -0x18(%rsp,%rdx,4), %r8d
testl %r8d, %r8d
cmovsl %eax, %r8d
movl %r8d, -0x18(%rsp,%rdx,4)
incq %rdx
cmpq $0x4, %rdx
jne 0x3d1a6
cmpl $0x0, 0x5c(%rdi)
jle 0x3d260
xorl %edx, %edx
leaq -0x18(%rsp), %r8
movslq 0x4(%rcx), %r9
movslq %edx, %rax
imulq %r9, %rax
addq 0x8(%rcx), %rax
movq %r8, %r9
xorl %r10d, %r10d
xorl %r11d, %r11d
movl -0x18(%rsp,%r10,4), %ebx
movslq %r11d, %r14
addq %rsi, %r14
xorl %r15d, %r15d
movl (%r9,%r15,4), %r12d
cmpl %r12d, %ebx
movl %r12d, %ebp
cmovll %ebx, %ebp
cmovgl %ebx, %r12d
leal 0x1(%r12), %r13d
imull %r12d, %r13d
movl %r13d, %r12d
shrl $0x1f, %r12d
addl %r13d, %r12d
sarl %r12d
addl %ebp, %r12d
movslq %r12d, %r12
movb (%rax,%r12), %bpl
movb %bpl, (%r14,%r15)
incq %r15
leal (%r10,%r15), %ebp
cmpl $0x4, %ebp
jne 0x3d1f7
addl %r15d, %r11d
incq %r10
addq $0x4, %r9
cmpq $0x4, %r10
jne 0x3d1e9
incq %rdx
movslq 0x5c(%rdi), %r9
addq $0xa, %rsi
xorl %eax, %eax
cmpq %r9, %rdx
jl 0x3d1d1
jmp 0x3d269
xorl %eax, %eax
jmp 0x3d269
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq