// File: /workspace/github_c_makefile_star2_O1/lh3[P]bgt/vcf.c
// Function: bcf_hdr_subset
bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int *imap)
{
	kstring_t str;
	bcf_hdr_t *h;
	str.l = str.m = 0; str.s = 0;
	h = bcf_hdr_init();
	if (h0->n[BCF_DT_SAMPLE] > 0) {
		char *p;
		int i = 0, end = n? 8 : 7;
		while ((p = strstr(h0->text, "#CHROM\t")) != 0)
			if (p > h0->text && *(p-1) == '\n') break;
		while ((p = strchr(p, '\t')) != 0 && i < end) ++i, ++p;
		if (i != end) {
			free(h); free(str.s);
			return 0; // malformated header
		}
		kputsn(h0->text, p - h0->text, &str);
		for (i = 0; i < n; ++i) {
			imap[i] = bcf_id2int(h0, BCF_DT_SAMPLE, samples[i]);
			if (imap[i] < 0) continue;
			kputc('\t', &str);
			kputs(samples[i], &str);
		}
	} else kputsn(h0->text, h0->l_text, &str);
	h->text = str.s;
	h->l_text = str.l + 1; // including NULL
	bcf_hdr_parse(h);
	return h;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, 0x40(%rsp)
movq %rdx, %r13
movl %esi, %ebp
movq %rdi, %r15
callq 0xb807
movq %rax, %r14
cmpl $0x0, 0x10(%r15)
jle 0x10bd2
cmpl $0x1, %ebp
movl $0x8, %ebx
sbbl $0x0, %ebx
movq 0x48(%r15), %rdi
leaq 0xea81(%rip), %rsi      # 0x1f454
movq %rdi, 0x8(%rsp)
callq 0x2440
movq %rax, %rdi
movl $0x9, %esi
callq 0x2180
xorl %r12d, %r12d
testq %rax, %rax
je 0x10a0f
incl %r12d
incq %rax
movq %rax, %rdi
movl $0x9, %esi
callq 0x2180
testq %rax, %rax
je 0x10a0f
cmpl %ebx, %r12d
jb 0x109f2
movl %ebx, 0x1c(%rsp)
cmpl %ebx, %r12d
movq %r14, 0x20(%rsp)
jne 0x10c2e
subl 0x8(%rsp), %eax
movl %ebp, 0x10(%rsp)
movslq %eax, %rbp
leaq 0x1(%rbp), %rax
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, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
incq %rbx
movq %rbx, %rdi
callq 0x22e0
movq %rax, %r14
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x2280
movq %r14, 0x8(%rsp)
movl 0x10(%rsp), %eax
movb $0x0, (%r14,%rbp)
testl %eax, %eax
jle 0x10c41
movl %eax, %eax
movq %rax, 0x38(%rsp)
xorl %r14d, %r14d
movq %r15, 0x30(%rsp)
movq %r13, 0x28(%rsp)
movq (%r13,%r14,8), %rdx
movq %r15, %rdi
movl $0x2, %esi
callq 0x106de
movq 0x40(%rsp), %rcx
movl %eax, (%rcx,%r14,4)
testl %eax, %eax
js 0x10bc2
movq %rbp, %r15
leaq 0x1(%rbp), %rcx
cmpq %rbx, %rcx
movq %rcx, 0x10(%rsp)
jae 0x10ae4
movq 0x8(%rsp), %rbp
jmp 0x10b28
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rbx
shrq $0x10, %rbx
orq %rcx, %rbx
incq %rbx
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x2330
movq %rax, %rbp
movw $0x9, (%rbp,%r15)
movq (%r13,%r14,8), %rdi
movq %rdi, 0x8(%rsp)
callq 0x2170
movslq %eax, %r13
leaq (%r15,%r13), %rax
addq $0x2, %rax
cmpq %rbx, %rax
jb 0x10b91
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, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
incq %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2330
movq %rax, %rbp
movq 0x10(%rsp), %r15
leaq (%r15,%rbp), %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x2280
addq %r15, %r13
movq %rbp, 0x8(%rsp)
movb $0x0, (%rbp,%r13)
movq %r13, %rbp
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r13
incq %r14
cmpq %r14, 0x38(%rsp)
jne 0x10aa9
jmp 0x10c41
movq 0x48(%r15), %rbx
movslq (%r15), %rbp
leaq 0x1(%rbp), %rax
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, %rdi
shrq $0x10, %rdi
orq %rax, %rdi
incq %rdi
callq 0x22e0
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2280
movb $0x0, (%r15,%rbp)
jmp 0x10c52
movq %r14, %rdi
callq 0x2050
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
cmpl 0x1c(%rsp), %r12d
movq 0x20(%rsp), %r14
movq 0x8(%rsp), %r15
jne 0x10c65
movq %r15, 0x48(%r14)
incl %ebp
movl %ebp, (%r14)
movq %r14, %rdi
callq 0xb655
jmp 0x10c68
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq