// File: /workspace/github_c_makefile_star2_O1/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, %r8
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
orb %al, %cl
jne 0x8b047
movq %rsi, %r12
movq %rdi, %r13
testq %r8, %r8
je 0x8ad38
movq %rdx, %r14
testq %rdx, %rdx
je 0x8b047
movq 0x38(%r13), %rax
testq %rax, %rax
movq %r8, 0x10(%rsp)
je 0x8ad55
movq %rax, 0x18(%rsp)
movq (%rax), %rax
movl (%rax), %edx
xorl %ebp, %ebp
movl $0x0, %esi
testl %edx, %edx
je 0x8ad85
movq %r14, 0x8(%rsp)
movzwl (%r12), %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), %ebx
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %ebx, %r14d
shrl %cl, %r14d
testb $0x2, %r14b
jne 0x8ad73
testb $0x1, %r14b
jne 0x8ad26
movq 0x18(%rax), %r14
movl %esi, %r15d
cmpl %edi, (%r14,%r15,4)
je 0x8ad73
addl %r11d, %esi
andl %r8d, %esi
incl %r11d
cmpl %r9d, %esi
jne 0x8acf8
movl %edx, %esi
jmp 0x8ad7b
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8a8c4
movq %r13, %rdi
callq 0x866a8
testl %eax, %eax
jne 0x8b047
movq 0x38(%r13), %rax
movq 0x10(%rsp), %r8
jmp 0x8acb7
shrl %cl, %ebx
testb $0x3, %bl
cmovnel %edx, %esi
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r14
cmpl %edx, %esi
je 0x8b047
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rbp
testq %rbp, %rbp
je 0x8af4e
movq (%rbp), %rdx
cmpq %rbp, %rdx
je 0x8af72
movq $0x0, (%rsp)
movq %r13, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movq %rbp, 0x28(%rsp)
movq %r14, 0x8(%rsp)
testq %rdx, %rdx
je 0x8adfd
movq 0x20(%rdx), %rcx
testq %rcx, %rcx
je 0x8adfd
movq %rdx, %rsi
movb (%r14), %al
movq 0x8(%rcx), %rdx
cmpb %al, (%rdx)
jne 0x8adee
movb 0x1(%rdx), %dl
cmpb 0x1(%r14), %dl
je 0x8adf8
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x8addd
xorl %ecx, %ecx
movq %rsi, %rdx
jmp 0x8adff
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x8ae55
movq 0x8(%rcx), %rax
testq %rax, %rax
je 0x8ae55
cmpl $0x3, 0x10(%rcx)
jl 0x8ae55
movl (%r8), %ecx
testl %ecx, %ecx
je 0x8ae69
movq %rcx, 0x20(%rsp)
leaq 0x3(%rax), %rcx
movq %rcx, 0x50(%rsp)
movb (%rcx), %cl
testb %cl, %cl
movq %rdx, 0x40(%rsp)
je 0x8ae71
addq $0x4, %rax
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r14d, %ecx
imull $0x1000193, %ecx, %r14d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x8ae3d
jmp 0x8ae77
movq (%rdx), %rbx
movq %rbx, %rdx
cmpq %rbp, %rbx
jne 0x8adc9
jmp 0x8af7a
xorl %r12d, %r12d
jmp 0x8af14
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
movq 0x20(%rsp), %rax
leal -0x1(%rax), %r15d
andl %r15d, %r14d
movq 0x10(%r8), %rsi
movl $0x1, %ebp
movl %r14d, %r12d
movq %rsi, 0x48(%rsp)
movl %r12d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r13d
leal (%r12,%r12), %ebx
andl $0x1e, %ebx
movl %r13d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x8aeee
testb $0x1, %al
jne 0x8aed7
movq 0x18(%r8), %rax
movl %r12d, %ecx
movq (%rax,%rcx,8), %rdi
movq 0x50(%rsp), %rsi
callq 0x46c0
movq 0x48(%rsp), %rsi
movq 0x10(%rsp), %r8
testl %eax, %eax
je 0x8aeee
addl %ebp, %r12d
andl %r15d, %r12d
incl %ebp
cmpl %r14d, %r12d
jne 0x8ae94
movq 0x20(%rsp), %rcx
movl %ecx, %r12d
jmp 0x8af00
movl %ebx, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x20(%rsp), %rcx
cmovnel %ecx, %r12d
movq 0x30(%rsp), %r13
movq 0x8(%rsp), %r14
movq 0x28(%rsp), %rbp
movq 0x40(%rsp), %rdx
movq (%rdx), %rbx
cmpl %ecx, %r12d
jne 0x8af44
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %r12
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x888c5
movq 0x10(%rsp), %r8
movq (%rsp), %rcx
orl %eax, %ecx
movq %rcx, (%rsp)
jmp 0x8ae58
movq 0x38(%rsp), %r12
jmp 0x8ae58
leaq 0x19881(%rip), %rsi     # 0xa47d6
leaq 0x1988f(%rip), %rdx     # 0xa47eb
movl $0x1, %edi
xorl %eax, %eax
callq 0x14378
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x8b047
movq $0x0, (%rsp)
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x8af9f
movb (%r14), %cl
movq 0x8(%rax), %rdx
cmpb %cl, (%rdx)
jne 0x8af97
movb 0x1(%rdx), %dl
cmpb 0x1(%r14), %dl
je 0x8afa1
movq (%rax), %rax
testq %rax, %rax
jne 0x8af86
xorl %eax, %eax
testq %rax, %rax
je 0x8afe1
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x8afe1
cmpl $0x3, 0x10(%rax)
jl 0x8afe1
addq $0x3, %rsi
movq %r8, %rdi
movq %r8, %rbx
callq 0x8b058
cmpl (%rbx), %eax
jne 0x8afe1
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x888c5
orl (%rsp), %eax
movq %rax, (%rsp)
leaq 0x101d3(%rip), %rsi     # 0x9b1bb
movl $0x2, %edx
movq %r12, %rdi
callq 0x4210
testl %eax, %eax
je 0x8b011
leaq 0x100e5(%rip), %rsi     # 0x9b0e5
movl $0x2, %edx
movq %r12, %rdi
callq 0x4210
testl %eax, %eax
jne 0x8b027
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x8aaef
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0x8b047
movq (%rsp), %rbx
testl %ebx, %ebx
jne 0x8b045
movq 0x18(%rsp), %rax
cmpl $0x0, 0x90(%rax)
je 0x8b045
movq %r13, %rdi
callq 0x879db
movl %ebx, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq