// File: /workspace/github_c_makefile_star2_O0/lh3[P]bgt/bgt.c
// Function: bgtm_read_core
int bgtm_read_core(bgtm_t *bm, bcf1_t *b)
{
	int i, j, off = 0, n_rest = 0, max_allele = 0, l_ref, al_ret = 0;
	const bcf1_t *b0 = 0;

	// fill the buffer
	for (i = n_rest = 0; i < bm->n_bgt; ++i) {
		if (bm->r[i].b0 == 0)
			bgt_read_rec(bm->bgt[i], &bm->r[i]);
		n_rest += (bm->r[i].b0 != 0);
		if (bm->r[i].b0) bm->n_gt_read += bm->bgt[i]->n_out;
	}
	if (n_rest == 0) return -1;
	// search for the smallest allele
	for (i = 0; i < bm->n_bgt; ++i) {
		bgt_rec_t *r = &bm->r[i];
		if (r->b0 == 0) continue;
		if (b0) {
			j = bcfcmp(b0, r->b0);
			if (j > 0) b0 = r->b0, max_allele = b0->n_allele;
			else if (j == 0)
				max_allele = r->b0->n_allele > max_allele? r->b0->n_allele : max_allele;
		} else b0 = r->b0, max_allele = b0->n_allele;
	}
	assert(b0 && max_allele >= 2);
	// fill bcf1_t up to INFO, excluding AC/AN/etc
	l_ref = bcfcpy_min(b, b0, max_allele > 2? "<M>" : 0);
	if (l_ref != b->rlen) {
		int32_t val = b->pos + b->rlen;
		bcf_append_info_ints(bm->h_out, b, "END", 1, &val);
	}
	// generate bm->a
	for (i = 0; i < bm->n_bgt; ++i) {
		bgt_rec_t *r = &bm->r[i];
		bgt_t *bgt = bm->bgt[i];
		if (bgt->n_out == 0) continue;
		if (r->b0 && bcfcmp(b, r->b0) == 0) { // copy
			r->b0 = 0;
			memcpy(bm->a[0] + off, r->a[0], bgt->n_out<<1);
			memcpy(bm->a[1] + off, r->a[1], bgt->n_out<<1);
		} else { // add missing values
			memset(bm->a[0] + off, 0, bgt->n_out<<1);
			memset(bm->a[1] + off, 1, bgt->n_out<<1);
		}
		off += bgt->n_out<<1;
	}
	// find samples having a set of alleles, or do haplotype counting
	if (bm->h_al) {
		// test if the current record matches an allele
		al_ret = al_present((khash_t(str)*)bm->h_al, bm->h_out, b);
		if (al_ret == 0) return 1;
	}
	// fill AC/AN/etc and test site_flt
	if ((bm->flag & BGT_F_SET_AC) || bm->site_flt || bm->n_fields > 0 || bm->n_groups > 1) {
		bgt_info_t ss;
		bgtm_cal_info(bm, &ss);
		bgtm_fill_info(bm->h_out, &ss, b);
		if (bm->n_fields > 0)
			bgtm_gen_tbl_line(bm, &ss, b);
		if (!bgtm_pass_site_flt(&ss, bm->site_flt))
			return 1;
	}
	if (bm->h_al) {
		// +1 to samples having the allele
		if ((bm->flag&BGT_F_CNT_AL) && bm->alcnt) {
			int is_ref = (al_ret == 2);
			for (i = 0; i < bm->n_out; ++i) {
				int g1 = bm->a[0][i<<1|0] | bm->a[1][i<<1|0]<<1;
				int g2 = bm->a[0][i<<1|1] | bm->a[1][i<<1|1]<<1;
				if (is_ref) bm->alcnt[i] += (g1 == 0 || g2 == 0);
				else bm->alcnt[i] += (g1 == 1 || g2 == 1);
			}
		}
		// generate haplotype
		if ((bm->flag&BGT_F_CNT_HAP) && bm->hap) {
			for (i = 0; i < bm->n_out<<1; ++i)
				if (bm->a[0][i] == 1 && bm->a[1][i] == 0) bm->hap[i] |= 1ULL<<bm->n_aal;
		}
		bgt_al_from_bcf(bm->h_out, b, &bm->aal[bm->n_aal++], 0);
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x208a3
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x20835
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
movslq -0x1c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x1db90
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
setne %al
andb $0x1, %al
movzbl %al, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x20893
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x34(%rax), %rcx
movq -0x10(%rbp), %rax
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x20895
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x207e5
cmpl $0x0, -0x28(%rbp)
jne 0x208b5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x20eaa
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x209ba
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x208f1
jmp 0x209ac
cmpq $0x0, -0x40(%rbp)
je 0x2098a
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rax
movq (%rax), %rsi
callq 0x15610
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x20937
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0x2c(%rbp)
jmp 0x20988
cmpl $0x0, -0x20(%rbp)
jne 0x20986
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
cmpl -0x2c(%rbp), %eax
jle 0x20974
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0x200(%rbp)
jmp 0x2097d
movl -0x2c(%rbp), %eax
movl %eax, -0x200(%rbp)
movl -0x200(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x20988
jmp 0x209aa
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
movl %eax, -0x2c(%rbp)
jmp 0x209ac
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x208bc
cmpq $0x0, -0x40(%rbp)
je 0x209c9
cmpl $0x2, -0x2c(%rbp)
jl 0x209c9
jmp 0x209e8
leaq 0x7f4b(%rip), %rdi      # 0x2891b
leaq 0x7ade(%rip), %rsi      # 0x284b5
movl $0x335, %edx            # imm = 0x335
leaq 0x7f4e(%rip), %rcx      # 0x28931
callq 0x21b0
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
movl %eax, %edx
leaq 0x79f8(%rip), %rax      # 0x283f6
cmpl $0x2, %ecx
cmovgq %rax, %rdx
callq 0x15710
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x20a4b
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
addl 0x8(%rcx), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0x788c(%rip), %rdx      # 0x282c9
movl $0x1, %ecx
leaq -0x4c(%rbp), %r8
callq 0x158b0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x20b7b
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x20a9b
jmp 0x20b6d
movq -0x58(%rbp), %rax
cmpq $0x0, (%rax)
je 0x20b17
movq -0x18(%rbp), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rsi
callq 0x15610
cmpl $0x0, %eax
jne 0x20b17
movq -0x58(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x60(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
movslq %eax, %rdx
callq 0x2290
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x60(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
movslq %eax, %rdx
callq 0x2290
jmp 0x20b5e
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x60(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x21e0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movq -0x60(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
movslq %eax, %rdx
movl $0x1, %esi
callq 0x21e0
movq -0x60(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20a52
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x20bbc
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x1da80
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x20bba
movl $0x1, -0x4(%rbp)
jmp 0x20eaa
jmp 0x20bbc
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x20bea
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x20bea
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jg 0x20bea
movq -0x10(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jle 0x20c57
movq -0x10(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x200f0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rsi
callq 0x1ffa0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jle 0x20c30
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rsi
callq 0x20470
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x1ff30
cmpl $0x0, %eax
jne 0x20c55
movl $0x1, -0x4(%rbp)
jmp 0x20eaa
jmp 0x20c57
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x20ea3
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x20dc6
movq -0x10(%rbp), %rax
cmpq $0x0, 0xa8(%rax)
je 0x20dc6
cmpl $0x2, -0x34(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1f4(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x20dc4
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
orl $0x0, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
orl $0x0, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll %ecx
orl %ecx, %eax
movl %eax, -0x1f8(%rbp)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
orl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq 0x60(%rcx), %rcx
movl -0x1c(%rbp), %edx
shll %edx
orl $0x1, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll %ecx
orl %ecx, %eax
movl %eax, -0x1fc(%rbp)
cmpl $0x0, -0x1f4(%rbp)
je 0x20d73
movb $0x1, %al
cmpl $0x0, -0x1f8(%rbp)
movb %al, -0x201(%rbp)
je 0x20d51
cmpl $0x0, -0x1fc(%rbp)
sete %al
movb %al, -0x201(%rbp)
movb -0x201(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movslq -0x1c(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x20db4
movb $0x1, %al
cmpl $0x1, -0x1f8(%rbp)
movb %al, -0x202(%rbp)
je 0x20d94
cmpl $0x1, -0x1fc(%rbp)
sete %al
movb %al, -0x202(%rbp)
movb -0x202(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rax
movslq -0x1c(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x20db6
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20ca7
jmp 0x20dc6
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x20e62
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
je 0x20e62
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jge 0x20e60
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x20e53
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x20e53
movq -0x10(%rbp), %rax
movl 0x90(%rax), %eax
movl %eax, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x1c(%rbp), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x20e55
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20dee
jmp 0x20e62
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rdx
movq -0x10(%rbp), %rcx
movl 0x90(%rcx), %eax
movl %eax, %r8d
addl $0x1, %r8d
movl %r8d, 0x90(%rcx)
cltq
imulq $0x30, %rax, %rax
addq %rax, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x20ec0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
nopw %cs:(%rax,%rax)