// File: /workspace/github_c_makefile_star2_O0/lh3[P]bgt/bgt.c
// Function: bgt_prepare
void bgt_prepare(bgt_t *bgt)
{
	int i, *t;
	const fmf_t *f = bgt->f->f;
	kstring_t str = {0,0,0};

	if (bgt->n_groups == 0) bgt_add_group_core(bgt, BGT_SET_ALL_SAMPLES, 0, 0);
	for (i = 0, bgt->n_out = 0; i < f->n_rows; ++i)
		if (bgt->gtag[i] > 0) ++bgt->n_out;
	bgt->out = (int*)realloc(bgt->out, bgt->n_out * sizeof(int));
	bgt->group = (uint32_t*)realloc(bgt->group, bgt->n_out * 4);
	for (i = 0, bgt->n_out = 0; i < f->n_rows; ++i)
		if (bgt->gtag[i] > 0)
			bgt->group[bgt->n_out] = bgt->gtag[i], bgt->out[bgt->n_out++] = i;

	// build ->h_out VCF header
	if (bgt->h_out) bcf_hdr_destroy(bgt->h_out);
	bgt->h_out = bcf_hdr_init();
	kputsn(bgt->f->h0->text, bgt->f->h0->l_text, &str);
	if (str.s[str.l-1] == 0) --str.l;
	if (bgt->n_out > 0) {
		kputs("\tFORMAT", &str);
		for (i = 0; i < bgt->n_out; ++i) {
			kputc('\t', &str);
			kputs(f->rows[bgt->out[i]].name, &str);
		}
	}
	bgt->h_out->text = str.s;
	bgt->h_out->l_text = str.l + 1; // including the last NULL
	bcf_hdr_parse(bgt->h_out);

	// subsetting pbf
	t = (int*)malloc(bgt->n_out * 2 * sizeof(int));
	for (i = 0; i < bgt->n_out; ++i)
		t[i<<1|0] = bgt->out[i]<<1|0, t[i<<1|1] = bgt->out[i]<<1|1;
	pbf_subset(bgt->pb, bgt->n_out<<1, t);
	free(t);

	bgt->b0->shared.l = 0; // mark b0 unread
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x21e0
movq -0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x1cd2a
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x1c850
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x34(%rax)
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x1cd74
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x1cd67
movq -0x8(%rbp), %rax
movl 0x34(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x34(%rax)
jmp 0x1cd69
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1cd3c
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0x34(%rax), %rsi
shlq $0x2, %rsi
callq 0x2340
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
shll $0x2, %eax
movslq %eax, %rsi
callq 0x2340
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0x34(%rax)
movl -0xc(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x1ce3c
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x1ce2f
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x34(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x8(%rbp), %rsi
movl 0x34(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x34(%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x1ce31
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1cdcf
movq -0x8(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x1ce54
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0xfe40
callq 0xfde0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq 0x48(%rax), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl (%rax), %esi
leaq -0x38(%rbp), %rdx
callq 0x1d010
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1ceaa
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jle 0x1cf1d
leaq 0xb5db(%rip), %rdi      # 0x28496
leaq -0x38(%rbp), %rsi
callq 0x1d160
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jge 0x1cf1b
movl $0x9, %edi
leaq -0x38(%rbp), %rsi
callq 0x1d1a0
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
movslq -0xc(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1d160
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1cecb
jmp 0x1cf1d
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0xfb00
movq -0x8(%rbp), %rax
movl 0x34(%rax), %eax
shll %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x22f0
movq %rax, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x34(%rcx), %eax
jge 0x1cfd1
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
shll %edx
orl $0x0, %edx
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
shll %ecx
orl $0x0, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0xc(%rbp), %rcx
movl (%rax,%rcx,4), %edx
shll %edx
orl $0x1, %edx
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
shll %ecx
orl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1cf6e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x34(%rax), %esi
shll %esi
movq -0x18(%rbp), %rdx
callq 0x1c070
movq -0x18(%rbp), %rdi
callq 0x2040
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq $0x0, 0x18(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)