// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_hdr_remove
void bcf_hdr_remove(bcf_hdr_t *hdr, int type, const char *key)
{
    int i = 0;
    bcf_hrec_t *hrec;
    if ( !key )
    {
        // no key, remove all entries of this type
        while ( i<hdr->nhrec )
        {
            if ( hdr->hrec[i]->type!=type ) { i++; continue; }
            hrec = hdr->hrec[i];
            bcf_hdr_unregister_hrec(hdr, hrec);
            bcf_hdr_remove_from_hdict(hdr, hrec);
            hdr->dirty = 1;
            hdr->nhrec--;
            if ( i < hdr->nhrec )
                memmove(&hdr->hrec[i],&hdr->hrec[i+1],(hdr->nhrec-i)*sizeof(bcf_hrec_t*));
            bcf_hrec_destroy(hrec);
        }
        return;
    }
    while (1)
    {
        if ( type==BCF_HL_FLT || type==BCF_HL_INFO || type==BCF_HL_FMT || type== BCF_HL_CTG )
        {
            hrec = bcf_hdr_get_hrec(hdr, type, "ID", key, NULL);
            if ( !hrec ) return;

            for (i=0; i<hdr->nhrec; i++)
                if ( hdr->hrec[i]==hrec ) break;
            assert( i<hdr->nhrec );

            vdict_t *d = type==BCF_HL_CTG ? (vdict_t*)hdr->dict[BCF_DT_CTG] : (vdict_t*)hdr->dict[BCF_DT_ID];
            khint_t k = kh_get(vdict, d, key);
            kh_val(d, k).hrec[type==BCF_HL_CTG?0:type] = NULL;
        }
        else
        {
            for (i=0; i<hdr->nhrec; i++)
            {
                if ( hdr->hrec[i]->type!=type ) continue;
                if ( type==BCF_HL_GEN )
                {
                    if ( !strcmp(hdr->hrec[i]->key,key) ) break;
                }
                else
                {
                    // not all structured lines have ID, we could be more sophisticated as in bcf_hdr_get_hrec()
                    int j = bcf_hrec_find_key(hdr->hrec[i], "ID");
                    if ( j>=0 && !strcmp(hdr->hrec[i]->vals[j],key) ) break;
                }
            }
            if ( i==hdr->nhrec ) return;
            hrec = hdr->hrec[i];
            bcf_hdr_remove_from_hdict(hdr, hrec);
        }

        hdr->nhrec--;
        if ( i < hdr->nhrec )
            memmove(&hdr->hrec[i],&hdr->hrec[i+1],(hdr->nhrec-i)*sizeof(bcf_hrec_t*));
        bcf_hrec_destroy(hrec);
        hdr->dirty = 1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
movq %rdi, %r14
movq %rdx, (%rsp)
testq %rdx, %rdx
je 0x24c99
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x3, %ebx
sete %cl
movl %ebx, %edx
cmovel %eax, %edx
movq %rdx, 0x10(%rsp)
leaq 0x28(,%rcx,8), %rax
movq %rax, 0x8(%rsp)
cmpl $0x4, %ebx
jae 0x24ba7
movq %r14, %rdi
movl %ebx, %esi
leaq 0x60171(%rip), %rdx     # 0x84cd5
movq (%rsp), %rcx
xorl %r8d, %r8d
callq 0x244fd
testq %rax, %rax
je 0x24d0e
movq %rax, %r13
movl 0x50(%r14), %r15d
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
xorl %r12d, %r12d
cmpq %r12, %rax
je 0x24d1d
movq 0x48(%r14), %rcx
cmpq %r13, (%rcx,%r12,8)
je 0x24c07
incq %r12
jmp 0x24b8f
movl 0x50(%r14), %ebp
testl %ebp, %ebp
movl $0x0, %r12d
cmovgl %ebp, %r12d
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x24c36
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %r13
cmpl %ebx, (%r13)
jne 0x24c02
cmpl $0x5, %ebx
jne 0x24bd8
movq 0x8(%r13), %rdi
jmp 0x24bf5
movq %r13, %rdi
leaq 0x600f3(%rip), %rsi     # 0x84cd5
callq 0x22ef9
testl %eax, %eax
js 0x24c02
movq 0x28(%r13), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rdi
movq (%rsp), %rsi
callq 0x46e0
testl %eax, %eax
je 0x24c33
incq %r15
jmp 0x24bba
movq 0x8(%rsp), %rax
movq (%r14,%rax), %rbp
movq %rbp, %rdi
movq (%rsp), %rsi
callq 0x246ef
movl %eax, %eax
imulq $0x38, %rax, %rax
addq 0x20(%rbp), %rax
movq 0x10(%rsp), %rcx
andq $0x0, 0x18(%rax,%rcx,8)
jmp 0x24c59
movl %r15d, %r12d
cmpl %ebp, %r12d
je 0x24d0e
movq 0x48(%r14), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x24d3c
movl 0x50(%r14), %r15d
decl %r15d
movl %r15d, 0x50(%r14)
subl %r12d, %r15d
jle 0x24c84
movq 0x48(%r14), %rax
movl %r12d, %ecx
leaq (%rax,%rcx,8), %rdi
leaq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
movslq %r15d, %rdx
shlq $0x3, %rdx
callq 0x4850
movq %r13, %rdi
callq 0x22854
movl $0x1, 0x54(%r14)
jmp 0x24b53
xorl %r12d, %r12d
movslq 0x50(%r14), %rax
cmpq %rax, %r12
jge 0x24d0e
movq 0x48(%r14), %rax
movq (%rax,%r12,8), %r15
cmpl %ebx, (%r15)
jne 0x24d09
movq %r14, %rdi
movq %r15, %rsi
callq 0x24494
movq %r14, %rdi
movq %r15, %rsi
callq 0x24d3c
movl $0x1, 0x54(%r14)
movslq 0x50(%r14), %rax
decq %rax
movl %eax, 0x50(%r14)
cmpq %rax, %r12
jge 0x24cff
movq 0x48(%r14), %rcx
leaq (%rcx,%r12,8), %rdi
leaq (%rcx,%r12,8), %rsi
addq $0x8, %rsi
subl %r12d, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x4850
movq %r15, %rdi
callq 0x22854
jmp 0x24c9c
incq %r12
jmp 0x24c9c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x618db(%rip), %rdi     # 0x865ff
leaq 0x615f8(%rip), %rsi     # 0x86323
leaq 0x618da(%rip), %rcx     # 0x8660c
movl $0x562, %edx            # imm = 0x562
callq 0x42e0