// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/header.c
// Function: sam_hrecs_find_type_id
sam_hrec_type_t *sam_hrecs_find_type_id(sam_hrecs_t *hrecs, const char *type,
                                     const char *ID_key, const char *ID_value) {
    if (!hrecs || !type)
        return NULL;
    sam_hrec_type_t *t1, *t2;
    khint_t k;

    /* Special case for types we have prebuilt hashes on */
    if (ID_key) {
        if (!ID_value)
            return NULL;

        if (type[0]   == 'S' && type[1]   == 'Q' &&
            ID_key[0] == 'S' && ID_key[1] == 'N') {
            k = kh_get(m_s2i, hrecs->ref_hash, ID_value);
            return k != kh_end(hrecs->ref_hash)
                ? hrecs->ref[kh_val(hrecs->ref_hash, k)].ty
                : NULL;
        }

        if (type[0]   == 'R' && type[1]   == 'G' &&
            ID_key[0] == 'I' && ID_key[1] == 'D') {
            k = kh_get(m_s2i, hrecs->rg_hash, ID_value);
            return k != kh_end(hrecs->rg_hash)
                ? hrecs->rg[kh_val(hrecs->rg_hash, k)].ty
                : NULL;
        }

        if (type[0]   == 'P' && type[1]   == 'G' &&
            ID_key[0] == 'I' && ID_key[1] == 'D') {
            k = kh_get(m_s2i, hrecs->pg_hash, ID_value);
            return k != kh_end(hrecs->pg_hash)
                ? hrecs->pg[kh_val(hrecs->pg_hash, k)].ty
                : NULL;
        }
    }

    k = kh_get(sam_hrecs_t, hrecs->h, TYPEKEY(type));
    if (k == kh_end(hrecs->h))
        return NULL;

    if (!ID_key)
        return kh_val(hrecs->h, k);

    t1 = t2 = kh_val(hrecs->h, k);
    do {
        sam_hrec_tag_t *tag;
        for (tag = t1->tag; tag; tag = tag->next) {
            if (tag->str[0] == ID_key[0] && tag->str[1] == ID_key[1]) {
                const char *cp1 = tag->str+3;
                const char *cp2 = ID_value;
                while (*cp1 && *cp1 == *cp2)
                    cp1++, cp2++;
                if (*cp2 || *cp1)
                    continue;
                return t1;
            }
        }
        t1 = t1->next;
    } while (t1 != t2);

    return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rcx, %rbx
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x6a9a5
movq %rdx, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x6a985
testq %rbx, %rbx
je 0x6a9a5
movzbl (%rsi), %eax
cmpl $0x50, %eax
je 0x6aa66
cmpl $0x52, %eax
je 0x6aa19
cmpl $0x53, %eax
jne 0x6a987
movb $0x53, %al
cmpb $0x51, 0x1(%rsi)
jne 0x6a987
cmpb $0x53, (%r14)
jne 0x6a987
cmpb $0x4e, 0x1(%r14)
jne 0x6a987
movq 0x38(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b87d
cmpl (%r14), %eax
je 0x6a9a5
movq 0x30(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
imulq $0x18, %rax, %rax
movq 0x10(%rcx,%rax), %rax
jmp 0x6a9a7
movb (%rsi), %al
movq (%r15), %r15
movzbl %al, %eax
movzbl 0x1(%rsi), %ecx
shll $0x8, %eax
orl %ecx, %eax
movq %r15, %rdi
movl %eax, %esi
callq 0x6c54d
cmpl (%r15), %eax
jne 0x6a9ad
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
movq 0x20(%r15), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
testq %r14, %r14
je 0x6aa14
xorl %eax, %eax
movq %rcx, %rdx
leaq 0x20(%rdx), %rsi
movq (%rsi), %rsi
testq %rsi, %rsi
je 0x6aa05
movq 0x8(%rsi), %rdi
movb (%rdi), %r8b
cmpb (%r14), %r8b
jne 0x6a9c5
movb 0x1(%rdi), %r8b
cmpb 0x1(%r14), %r8b
jne 0x6a9c5
xorl %r8d, %r8d
movb 0x3(%rdi,%r8), %r9b
movb (%rbx,%r8), %r10b
testb %r9b, %r9b
je 0x6a9fe
cmpb %r10b, %r9b
jne 0x6a9c5
incq %r8
jmp 0x6a9e6
testb %r10b, %r10b
jne 0x6a9c5
jmp 0x6aa0f
movq (%rdx), %rdx
cmpq %rcx, %rdx
jne 0x6a9c1
jmp 0x6a9a7
movq %rdx, %rax
jmp 0x6a9a7
movq %rcx, %rax
jmp 0x6a9a7
movb $0x52, %al
cmpb $0x47, 0x1(%rsi)
jne 0x6a987
cmpb $0x49, (%r14)
jne 0x6a987
cmpb $0x44, 0x1(%r14)
jne 0x6a987
movq 0x50(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b87d
cmpl (%r14), %eax
je 0x6a9a5
movq 0x48(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
imulq $0x18, %rax, %rax
jmp 0x6aab1
movb $0x50, %al
cmpb $0x47, 0x1(%rsi)
jne 0x6a987
cmpb $0x49, (%r14)
jne 0x6a987
cmpb $0x44, 0x1(%r14)
jne 0x6a987
movq 0x70(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6b87d
cmpl (%r14), %eax
je 0x6a9a5
movq 0x68(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
shlq $0x5, %rax
movq 0x8(%rcx,%rax), %rax
jmp 0x6a9a7