// File: /workspace/github_c_makefile_star2_O3/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 $0x58, %rsp
movq %rcx, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
orb %al, %cl
jne 0x887c8
movq %rsi, %r13
movq %rdi, %r12
testq %rbx, %rbx
je 0x884f1
testq %rdx, %rdx
je 0x887c8
movq 0x38(%r12), %r14
testq %r14, %r14
movq %rdx, 0x18(%rsp)
je 0x8850e
movq (%r14), %rax
movl (%rax), %r8d
xorl %ebp, %ebp
movl $0x0, %esi
testl %r8d, %r8d
je 0x88548
movq %rbx, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movzwl (%r13), %ecx
rolw $0x8, %cx
movzwl %cx, %edi
movq %r8, %rdx
decl %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), %ebx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebx, %r14d
shrl %cl, %r14d
testb $0x2, %r14b
jne 0x8852d
testb $0x1, %r14b
jne 0x884dc
movq 0x18(%rax), %r14
movl %esi, %r15d
cmpl %edi, (%r14,%r15,4)
je 0x8852d
addl %r11d, %esi
andl %r8d, %esi
incl %r11d
cmpl %r9d, %esi
jne 0x884ae
xorl %ebp, %ebp
jmp 0x887c8
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x880be
movq %r12, %rdi
callq 0x8413e
testl %eax, %eax
jne 0x887c8
movq 0x38(%r12), %r14
movq 0x18(%rsp), %rdx
jmp 0x88469
shrl %cl, %ebx
testb $0x3, %bl
movq %rdx, %r8
cmovnel %r8d, %esi
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rdx
cmpl %r8d, %esi
je 0x887c8
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rbp
testq %rbp, %rbp
je 0x886fa
movq (%rbp), %r15
cmpq %rbp, %r15
je 0x8871e
movl $0x0, 0x4(%rsp)
movq %r12, 0x38(%rsp)
movq %r13, 0x30(%rsp)
movq %rbp, 0x28(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
testq %r15, %r15
je 0x885fd
movq 0x20(%r15), %rcx
testq %rcx, %rcx
je 0x885fd
movb (%rdx), %dil
movq 0x8(%rcx), %rax
cmpb %dil, (%rax)
jne 0x885b6
movb 0x1(%rax), %sil
cmpb 0x1(%rdx), %sil
je 0x885c0
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x885a3
jmp 0x885fd
cmpl $0x3, 0x10(%rcx)
jl 0x885fd
movl (%rbx), %esi
testl %esi, %esi
je 0x8860a
leaq 0x3(%rax), %rcx
movq %rcx, 0x50(%rsp)
movb (%rcx), %cl
testb %cl, %cl
je 0x88612
addq $0x4, %rax
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r12d, %ecx
imull $0x1000193, %ecx, %r12d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x885e5
jmp 0x88618
movq (%r15), %r15
cmpq %rbp, %r15
jne 0x88592
jmp 0x88726
xorl %r14d, %r14d
jmp 0x886a4
movl $0x811c9dc5, %r12d      # imm = 0x811C9DC5
movq %rsi, 0x40(%rsp)
decl %esi
andl %esi, %r12d
movq 0x10(%rbx), %rdi
movl $0x1, %ebx
movl %r12d, %r14d
movl %esi, 0x24(%rsp)
movq %rdi, 0x48(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rdi,%rax,4), %r13d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r13d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x88692
testb $0x1, %al
jne 0x88683
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x50(%rsp), %rsi
callq 0x46c0
movq 0x48(%rsp), %rdi
movl 0x24(%rsp), %esi
movq 0x18(%rsp), %rdx
testl %eax, %eax
je 0x88692
addl %ebx, %r14d
andl %esi, %r14d
incl %ebx
cmpl %r12d, %r14d
jne 0x88637
jmp 0x886a9
movl %ebp, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x40(%rsp), %rsi
cmovnel %esi, %r14d
cmpl %esi, %r14d
jne 0x886d9
movq (%r15), %rbx
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0x30(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x86215
movq 0x18(%rsp), %rdx
orl %eax, 0x4(%rsp)
movq %rbx, %r15
movq 0x38(%rsp), %r12
jmp 0x886eb
movq (%r15), %r15
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %r13
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbx
movq 0x28(%rsp), %rbp
jmp 0x88600
leaq 0x19854(%rip), %rsi     # 0xa1f55
leaq 0x19862(%rip), %rdx     # 0xa1f6a
movl $0x1, %edi
xorl %eax, %eax
callq 0x13de5
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x887c8
movl $0x0, 0x4(%rsp)
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x88777
movb (%rdx), %cl
movq 0x8(%rax), %rsi
cmpb %cl, (%rsi)
jne 0x88743
movb 0x1(%rsi), %dil
cmpb 0x1(%rdx), %dil
je 0x8874d
movq (%rax), %rax
testq %rax, %rax
jne 0x88731
jmp 0x88777
cmpl $0x3, 0x10(%rax)
jl 0x88777
addq $0x3, %rsi
movq %rbx, %rdi
callq 0x887d9
cmpl (%rbx), %eax
jne 0x88777
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x86215
orl %eax, 0x4(%rsp)
movzbl (%r13), %eax
cmpl $0x52, %eax
je 0x8878f
cmpl $0x53, %eax
jne 0x887aa
cmpb $0x51, 0x1(%r13)
je 0x88796
jmp 0x887aa
cmpb $0x47, 0x1(%r13)
jne 0x887aa
movq %r14, %rdi
movq %r13, %rsi
callq 0x882ba
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x887c8
movl 0x4(%rsp), %eax
movl %eax, %ebp
testl %eax, %eax
jne 0x887c8
xorl %ebp, %ebp
cmpl $0x0, 0x90(%r14)
je 0x887c8
movq %r12, %rdi
callq 0x853ed
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq