// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/header.c
// Function: sam_hdr_remove_except
int sam_hdr_remove_except(sam_hdr_t *bh, const char *type, const char *ID_key, const char *ID_value) {
    sam_hrecs_t *hrecs;
    if (!bh || !type)
        return -1;

    if (!(hrecs = bh->hrecs)) {
        if (sam_hdr_fill_hrecs(bh) != 0)
            return -1;
        hrecs = bh->hrecs;
    }

    sam_hrec_type_t *step;
    int ret = 1, remove_all = (ID_key == NULL);

    if (!strncmp(type, "PG", 2) || !strncmp(type, "CO", 2)) {
        hts_log_warning("Removing PG or CO lines is not supported!");
        return -1;
    }

    sam_hrec_type_t *type_found = sam_hrecs_find_type_id(hrecs, type, ID_key, ID_value);
    if (!type_found) { // remove all line of this type
        khint_t k = kh_get(sam_hrecs_t, hrecs->h, TYPEKEY(type));
        if (k == kh_end(hrecs->h))
            return 0;
        type_found =  kh_val(hrecs->h, k);
        if (!type_found)
            return 0;
        remove_all = 1;
    }

    step = type_found->next;
    while (step != type_found) {
        sam_hrec_type_t *to_remove = step;
        step = step->next;
        ret &= sam_hrecs_remove_line(hrecs, type, to_remove, 0);
    }

    if (remove_all)
        ret &= sam_hrecs_remove_line(hrecs, type, type_found, 0);

    /* if RG or SQ, delete then rebuild the hashes (as it is faster
       to rebuild than delete one by one).
    */

    if ((strncmp(type, "SQ", 2) == 0) || (strncmp(type, "RG", 2) == 0)) {
        if (rebuild_hash(hrecs, type)) {
            return -1;
        }
    }

    if (!ret && hrecs->dirty)
        redact_header_text(bh);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
orb %al, %cl
jne 0x882a9
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
movq 0x38(%rdi), %r15
testq %r15, %r15
je 0x88135
movq %rbx, (%rsp)
testq %r13, %r13
sete %al
movzbl (%r14), %ebx
cmpl $0x43, %ebx
je 0x8814b
cmpl $0x50, %ebx
jne 0x88152
cmpb $0x47, 0x1(%r14)
jne 0x88152
leaq 0x19df8(%rip), %rsi     # 0xa1f15
leaq 0x19e07(%rip), %rdx     # 0xa1f2b
movl $0x3, %edi
xorl %eax, %eax
callq 0x13de5
jmp 0x882a9
movq %rbx, %rdi
callq 0x8413e
testl %eax, %eax
jne 0x882a9
movq 0x38(%rbx), %r15
jmp 0x880f7
cmpb $0x4f, 0x1(%r14)
je 0x88116
movl %eax, %ebp
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x85b55
testq %rax, %rax
je 0x881d4
movq %rax, %r12
xorl %eax, %eax
movb %bpl, %al
movl %eax, %ebp
movq (%r12), %rdx
movl $0x1, %ebx
cmpq %r12, %rdx
je 0x8819c
movq (%rdx), %r13
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x86215
andl %eax, %ebx
movq %r13, %rdx
cmpq %r12, %r13
jne 0x88182
testl %ebp, %ebp
je 0x881b2
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x86215
andl %eax, %ebx
movzbl (%r14), %eax
cmpl $0x52, %eax
je 0x88244
cmpl $0x53, %eax
jne 0x8825f
cmpb $0x51, 0x1(%r14)
je 0x8824b
jmp 0x8825f
movq (%r15), %rax
movl (%rax), %edx
movl $0x0, %esi
testl %edx, %edx
je 0x88284
movzbl 0x1(%r14), %ecx
shll $0x8, %ebx
orl %ecx, %ebx
leal -0x1(%rdx), %edi
movl %edi, %r8d
andl %ebx, %r8d
movq 0x10(%rax), %r9
movl $0x1, %r10d
movl %r8d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r9,%rcx,4), %r11d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r11d, %ebp
shrl %cl, %ebp
testb $0x2, %bpl
jne 0x8827a
testb $0x1, %bpl
jne 0x88233
movq 0x18(%rax), %r12
movl %esi, %r13d
cmpl %ebx, (%r12,%r13,4)
je 0x8827a
addl %r10d, %esi
andl %edi, %esi
incl %r10d
xorl %ebp, %ebp
cmpl %r8d, %esi
jne 0x88206
jmp 0x882a9
cmpb $0x47, 0x1(%r14)
jne 0x8825f
movq %r15, %rdi
movq %r14, %rsi
callq 0x882ba
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x882a9
xorl %ebp, %ebp
testl %ebx, %ebx
jne 0x882a9
cmpl $0x0, 0x90(%r15)
je 0x882a9
movq (%rsp), %rdi
callq 0x853ed
jmp 0x882a9
shrl %cl, %r11d
testb $0x3, %r11b
cmovnel %edx, %esi
cmpl %edx, %esi
jne 0x8828c
xorl %ebp, %ebp
jmp 0x882a9
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %r12
movl $0x1, %eax
movl $0x0, %ebp
testq %r12, %r12
jne 0x88172
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq