// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xdc4a6
cmpq $0x0, -0x18(%rbp)
jne 0xdc4b2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdc6bd
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xdc4ea
movq -0x10(%rbp), %rdi
callq 0xd7490
cmpl $0x0, %eax
je 0xdc4de
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdc6bd
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x3c(%rbp)
cmpq $0x0, -0x20(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x1bb6a(%rip), %rsi     # 0xf8076
movl $0x2, %edx
callq 0x4200
cmpl $0x0, %eax
je 0xdc535
movq -0x18(%rbp), %rdi
leaq 0x162f8(%rip), %rsi     # 0xf281e
movl $0x2, %edx
callq 0x4200
cmpl $0x0, %eax
jne 0xdc55b
movl $0x3, %edi
leaq 0x1bcb0(%rip), %rsi     # 0xf81f1
leaq 0x1bcbf(%rip), %rdx     # 0xf8207
movb $0x0, %al
callq 0x1b030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdc6bd
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xd9960
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xdc5e7
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0xdabd0
movq -0x60(%rbp), %rdi
movl %eax, %esi
callq 0xdc6d0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
jne 0xdc5b7
movl $0x0, -0x4(%rbp)
jmp 0xdc6bd
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xdc5e0
movl $0x0, -0x4(%rbp)
jmp 0xdc6bd
movl $0x1, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0xdc62a
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq 0xda1c0
andl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0xdc5f2
cmpl $0x0, -0x40(%rbp)
je 0xdc649
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rdx
xorl %ecx, %ecx
callq 0xda1c0
andl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x16098(%rip), %rsi     # 0xf26ec
movl $0x2, %edx
callq 0x4200
cmpl $0x0, %eax
je 0xdc67d
movq -0x18(%rbp), %rdi
leaq 0x15fa8(%rip), %rsi     # 0xf2616
movl $0x2, %edx
callq 0x4200
cmpl $0x0, %eax
jne 0xdc69a
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xdc810
cmpl $0x0, %eax
je 0xdc698
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xdc6bd
jmp 0xdc69a
cmpl $0x0, -0x3c(%rbp)
jne 0xdc6b6
movq -0x30(%rbp), %rax
cmpl $0x0, 0x90(%rax)
je 0xdc6b6
movq -0x10(%rbp), %rdi
callq 0xd8e20
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)