// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %rbp
orb %al, %cl
jne 0x6c53c
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
movq 0x38(%rdi), %r15
testq %r15, %r15
je 0x6c42d
testq %r13, %r13
sete %al
movzbl (%r14), %ebp
cmpl $0x43, %ebp
je 0x6c443
cmpl $0x50, %ebp
jne 0x6c44a
cmpb $0x47, 0x1(%r14)
jne 0x6c44a
leaq 0x173f1(%rip), %rsi     # 0x83805
leaq 0x17400(%rip), %rdx     # 0x8381b
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rbp
jmp 0x6c53c
movq %rbx, %rdi
callq 0x6933d
testl %eax, %eax
jne 0x6c53c
movq 0x38(%rbx), %r15
jmp 0x6c3f2
cmpb $0x4f, 0x1(%r14)
je 0x6c40d
movb %al, 0x3(%rsp)
movl $0x0, 0x4(%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x6a8fd
testq %rax, %rax
je 0x6c4d3
movq %rax, %r12
movl 0x4(%rsp), %eax
movb 0x3(%rsp), %cl
movb %cl, %al
movl %eax, 0x4(%rsp)
pushq $0x1
popq %r13
movq (%r12), %rdx
cmpq %r12, %rdx
je 0x6c4a2
movq (%rdx), %rbp
movq %r15, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x6ad57
andl %eax, %r13d
movq %rbp, %rdx
jmp 0x6c485
cmpl $0x0, 0x4(%rsp)
je 0x6c4bc
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x6ad57
andl %eax, %r13d
movzbl (%r14), %eax
cmpl $0x52, %eax
je 0x6c50a
cmpl $0x53, %eax
jne 0x6c523
cmpb $0x51, 0x1(%r14)
je 0x6c511
jmp 0x6c523
movq (%r15), %r12
movzbl 0x1(%r14), %eax
shll $0x8, %ebp
orl %eax, %ebp
movq %r12, %rdi
movl %ebp, %esi
callq 0x6c54d
xorl %ebp, %ebp
cmpl (%r12), %eax
je 0x6c53c
movq 0x20(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %r12
testq %r12, %r12
je 0x6c53c
pushq $0x1
popq %rax
jmp 0x6c479
cmpb $0x47, 0x1(%r14)
jne 0x6c523
movq %r15, %rdi
movq %r14, %rsi
callq 0x6c5be
pushq $-0x1
popq %rbp
testl %eax, %eax
jne 0x6c53c
xorl %ebp, %ebp
testl %r13d, %r13d
jne 0x6c53c
cmpl $0x0, 0x90(%r15)
je 0x6c53c
movq %rbx, %rdi
callq 0x6a1b4
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq