// File: /workspace/github_c_makefile_star2_O3/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:
movq %rcx, %r8
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x85bec
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rdx, %rdx
je 0x85bef
testq %r8, %r8
je 0x85c71
movzbl (%rsi), %eax
cmpl $0x50, %eax
je 0x85d54
cmpl $0x52, %eax
je 0x85d01
cmpl $0x53, %eax
jne 0x85bf1
movb $0x53, %al
cmpb $0x51, 0x1(%rsi)
jne 0x85bf1
cmpb $0x53, (%rdx)
jne 0x85bf1
cmpb $0x4e, 0x1(%rdx)
jne 0x85bf1
movq 0x38(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x871f4
cmpl (%r14), %eax
je 0x85c71
movq 0x30(%rbx), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $0x10, %rax
jmp 0x85da4
xorl %eax, %eax
retq
movb (%rsi), %al
movq (%rbx), %rdi
movl (%rdi), %r9d
testl %r9d, %r9d
je 0x85c6a
movzbl 0x1(%rsi), %ecx
movzbl %al, %r10d
shll $0x8, %r10d
orl %ecx, %r10d
leal -0x1(%r9), %r11d
movl %r11d, %ebx
andl %r10d, %ebx
movq 0x10(%rdi), %r14
movl $0x1, %ebp
xorl %eax, %eax
movl %ebx, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%r14,%rcx,4), %r15d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r15d, %r12d
shrl %cl, %r12d
testb $0x2, %r12b
jne 0x85c5d
testb $0x1, %r12b
jne 0x85c50
movq 0x18(%rdi), %r12
movl %esi, %r13d
cmpl %r10d, (%r12,%r13,4)
je 0x85c5d
addl %ebp, %esi
andl %r11d, %esi
incl %ebp
cmpl %ebx, %esi
jne 0x85c22
jmp 0x85c73
shrl %cl, %r15d
testb $0x3, %r15b
cmovnel %r9d, %esi
jmp 0x85c6c
xorl %esi, %esi
cmpl %r9d, %esi
jne 0x85c82
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rdi), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rcx
testq %rdx, %rdx
je 0x85cf9
xorl %eax, %eax
movq %rcx, %rsi
movq 0x20(%rsi), %rdi
testq %rdi, %rdi
je 0x85ce7
movb (%rdx), %r9b
movq 0x8(%rdi), %r10
cmpb %r9b, (%r10)
jne 0x85cdf
movb 0x1(%r10), %r11b
cmpb 0x1(%rdx), %r11b
jne 0x85cdf
movb 0x3(%r10), %bl
movq %r8, %r11
testb %bl, %bl
je 0x85cd9
addq $0x4, %r10
movq %r8, %r11
cmpb (%r11), %bl
jne 0x85cdf
incq %r11
movb (%r10), %bl
incq %r10
testb %bl, %bl
jne 0x85cc7
cmpb $0x0, (%r11)
je 0x85cf1
movq (%rdi), %rdi
testq %rdi, %rdi
jne 0x85ca2
movq (%rsi), %rsi
cmpq %rcx, %rsi
jne 0x85c96
jmp 0x85c73
movq %rsi, %rax
jmp 0x85c73
movq %rcx, %rax
jmp 0x85c73
movb $0x52, %al
cmpb $0x47, 0x1(%rsi)
jne 0x85bf1
cmpb $0x49, (%rdx)
jne 0x85bf1
cmpb $0x44, 0x1(%rdx)
jne 0x85bf1
movq 0x50(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x871f4
cmpl (%r14), %eax
je 0x85c71
movq 0x48(%rbx), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $0x8, %rax
jmp 0x85da4
movb $0x50, %al
cmpb $0x47, 0x1(%rsi)
jne 0x85bf1
cmpb $0x49, (%rdx)
jne 0x85bf1
cmpb $0x44, 0x1(%rdx)
jne 0x85bf1
movq 0x70(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x871f4
cmpl (%r14), %eax
je 0x85c71
movq 0x68(%rbx), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
shlq $0x5, %rax
addq %rcx, %rax
addq $0x8, %rax
movq (%rax), %rax
jmp 0x85c73