// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/header.c
// Function: sam_hdr_remove_lines
int sam_hdr_remove_lines(sam_hdr_t *bh, const char *type, const char *id, void *vrh) {
    sam_hrecs_t *hrecs;
    rmhash_t *rh = (rmhash_t *)vrh;

    if (!bh || !type)
        return -1;
    if (!rh) // remove all lines
        return sam_hdr_remove_except(bh, type, NULL, NULL);
    if (!id)
        return -1;

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

    khint_t k = kh_get(sam_hrecs_t, hrecs->h, TYPEKEY(type));
    if (k == kh_end(hrecs->h)) // nothing to remove from
        return 0;

    sam_hrec_type_t *head = kh_val(hrecs->h, k);
    if (!head) {
        hts_log_error("Header inconsistency");
        return -1;
    }

    int ret = 0;
    sam_hrec_type_t *step = head->next;
    while (step != head) {
        sam_hrec_tag_t *tag = sam_hrecs_find_key(step, id, NULL);
        if (tag && tag->str && tag->len >= 3) {
           k = kh_get(rm, rh, tag->str+3);
           if (k == kh_end(rh)) { // value is not in the hash table, so remove
               sam_hrec_type_t *to_remove = step;
               step = step->next;
               ret |= sam_hrecs_remove_line(hrecs, type, to_remove, 0);
           } else {
               step = step->next;
           }
        } else { // tag is not on the line, so skip to next line
            step = step->next;
        }
    }

    // process the first line
    sam_hrec_tag_t * tag = sam_hrecs_find_key(head, id, NULL);
    if (tag && tag->str && tag->len >= 3) {
       k = kh_get(rm, rh, tag->str+3);
       if (k == kh_end(rh)) { // value is not in the hash table, so remove
           sam_hrec_type_t *to_remove = head;
           head = head->next;
           ret |= sam_hrecs_remove_line(hrecs, type, to_remove, 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 ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
pushq $-0x1
popq %rbp
orb %al, %cl
jne 0x6c86a
movq %rsi, %r14
movq %rdi, %rbx
testq %r12, %r12
je 0x6c772
movq %rdx, %r13
testq %rdx, %rdx
je 0x6c86a
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0x6c78f
movq %rax, 0x8(%rsp)
movq (%rax), %r15
movzwl (%r14), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %r15, %rdi
callq 0x6c54d
xorl %ebp, %ebp
cmpl (%r15), %eax
je 0x6c86a
movq 0x20(%r15), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rbp
testq %rbp, %rbp
je 0x6c810
movq %rbx, 0x10(%rsp)
movq (%rbp), %rbx
movq $0x0, (%rsp)
cmpq %rbp, %rbx
je 0x6c7a8
movq %rbx, %r15
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x6b93e
testq %rax, %rax
je 0x6c76d
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x6c76d
cmpl $0x3, 0x10(%rax)
jl 0x6c76d
addq $0x3, %rsi
movq %r12, %rdi
callq 0x6c87b
movq (%r15), %rbx
cmpl (%r12), %eax
jne 0x6c70d
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x6ad57
movq (%rsp), %rcx
orl %eax, %ecx
movq %rcx, (%rsp)
jmp 0x6c70d
movq (%r15), %rbx
jmp 0x6c70d
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c3bb
movq %rbx, %rdi
callq 0x6933d
testl %eax, %eax
jne 0x6c86a
movq 0x38(%rbx), %rax
jmp 0x6c6c3
movq %rbp, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x6b93e
testq %rax, %rax
movq 0x10(%rsp), %rbx
je 0x6c7f9
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x6c7f9
cmpl $0x3, 0x10(%rax)
jl 0x6c7f9
addq $0x3, %rsi
movq %r12, %rdi
callq 0x6c87b
cmpl (%r12), %eax
jne 0x6c7f9
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x6ad57
orl (%rsp), %eax
movq %rax, (%rsp)
movzbl (%r14), %eax
cmpl $0x52, %eax
je 0x6c82d
cmpl $0x53, %eax
jne 0x6c848
cmpb $0x51, 0x1(%r14)
je 0x6c834
jmp 0x6c848
leaq 0x1702e(%rip), %rsi     # 0x83845
leaq 0x1703c(%rip), %rdx     # 0x8385a
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
pushq $-0x1
popq %rbp
jmp 0x6c86a
cmpb $0x47, 0x1(%r14)
jne 0x6c848
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x6c5be
pushq $-0x1
popq %rbp
testl %eax, %eax
jne 0x6c86a
movq (%rsp), %rax
movl %eax, %ebp
testl %eax, %eax
jne 0x6c86a
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
cmpl $0x0, 0x90(%rax)
je 0x6c86a
movq %rbx, %rdi
callq 0x6a1b4
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq