// File: /workspace/github_c_makefile_star2_O1/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, %r13
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
orb %al, %cl
jne 0x8aadd
movq %rdx, %rbp
movq %rsi, %r14
movq 0x38(%rdi), %r15
testq %r15, %r15
je 0x8a978
movq %rdi, (%rsp)
testq %rbp, %rbp
sete %bl
leaq 0x19d0f(%rip), %rsi     # 0xa461b
movl $0x2, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x8a959
leaq 0x109cd(%rip), %rsi     # 0x9b2f1
movl $0x2, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x8a959
xorl %eax, %eax
movb %bl, %al
movl %eax, %ebx
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x881f0
testq %rax, %rax
je 0x8a994
movq %rax, %r13
jmp 0x8aa3c
leaq 0x19e36(%rip), %rsi     # 0xa4796
leaq 0x19e45(%rip), %rdx     # 0xa47ac
movl $0x3, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x8aadd
movq %rdi, %rbx
callq 0x866a8
testl %eax, %eax
jne 0x8aadd
movq 0x38(%rbx), %r15
movq %rbx, %rdi
jmp 0x8a8fb
movq (%r15), %rax
movl (%rax), %edx
testl %edx, %edx
je 0x8aa0c
movl %ebx, %r13d
movzwl (%r14), %ecx
rolw $0x8, %cx
movzwl %cx, %edi
leal -0x1(%rdx), %r8d
movl %r8d, %r9d
andl %edi, %r9d
movq 0x10(%rax), %r10
movl $0x1, %r11d
movl %r9d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r10,%rcx,4), %ebp
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebp, %ebx
shrl %cl, %ebx
testb $0x2, %bl
jne 0x8a9fe
testb $0x1, %bl
jne 0x8a9ec
movq 0x18(%rax), %rbx
movl %esi, %r12d
cmpl %edi, (%rbx,%r12,4)
je 0x8a9fe
addl %r11d, %esi
andl %r8d, %esi
incl %r11d
cmpl %r9d, %esi
jne 0x8a9c2
movl %edx, %esi
jmp 0x8aa07
shrl %cl, %ebp
testb $0x3, %bpl
cmovnel %edx, %esi
movl %r13d, %ebx
jmp 0x8aa0e
xorl %esi, %esi
xorl %r12d, %r12d
cmpl %edx, %esi
jne 0x8aa1c
xorl %eax, %eax
xorl %r13d, %r13d
jmp 0x8aa34
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %r13
testq %r13, %r13
setne %al
movl $0x1, %ecx
cmovnel %ecx, %ebx
testb %al, %al
je 0x8aadd
movl %ebx, %r12d
movq (%r13), %rdx
movl $0x1, %ebp
cmpq %r13, %rdx
je 0x8aa67
movq (%rdx), %rbx
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x888c5
andl %eax, %ebp
movq %rbx, %rdx
cmpq %r13, %rbx
jne 0x8aa4d
testl %r12d, %r12d
je 0x8aa7e
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x888c5
andl %eax, %ebp
leaq 0x10736(%rip), %rsi     # 0x9b1bb
movl $0x2, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
je 0x8aaae
leaq 0x10648(%rip), %rsi     # 0x9b0e5
movl $0x2, %edx
movq %r14, %rdi
callq 0x4210
testl %eax, %eax
jne 0x8aac3
movq %r15, %rdi
movq %r14, %rsi
callq 0x8aaef
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x8aadd
xorl %r12d, %r12d
testl %ebp, %ebp
jne 0x8aadd
cmpl $0x0, 0x90(%r15)
je 0x8aadd
movq (%rsp), %rdi
callq 0x879db
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq