// File: /workspace/github_c_makefile_star2_O1/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 0x88282
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
testq %rdx, %rdx
je 0x88327
testq %r8, %r8
je 0x88438
movzbl (%rsi), %eax
cmpl $0x50, %eax
je 0x882dd
cmpl $0x52, %eax
je 0x88293
cmpl $0x53, %eax
jne 0x88327
cmpb $0x51, 0x1(%rsi)
jne 0x88285
cmpb $0x53, (%rdx)
jne 0x88285
cmpb $0x4e, 0x1(%rdx)
jne 0x88285
movq 0x38(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x8991e
cmpl (%r14), %eax
je 0x88438
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 0x8831f
xorl %eax, %eax
retq
cmpl $0x50, %eax
je 0x882dd
cmpl $0x52, %eax
jne 0x88327
cmpb $0x47, 0x1(%rsi)
jne 0x882d8
cmpb $0x49, (%rdx)
jne 0x882d8
cmpb $0x44, 0x1(%rdx)
jne 0x882d8
movq 0x50(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x8991e
cmpl (%r14), %eax
je 0x88438
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 0x8831f
cmpl $0x50, %eax
jne 0x88327
cmpb $0x47, 0x1(%rsi)
jne 0x88327
cmpb $0x49, (%rdx)
jne 0x88327
cmpb $0x44, 0x1(%rdx)
jne 0x88327
movq 0x70(%rbx), %r14
movq %r14, %rdi
movq %r8, %rsi
callq 0x8991e
cmpl (%r14), %eax
je 0x88438
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 0x8843a
movq (%rbx), %rax
movl (%rax), %edi
testl %edi, %edi
je 0x8839b
movzwl (%rsi), %ecx
rolw $0x8, %cx
movzwl %cx, %r9d
leal -0x1(%rdi), %r10d
movl %r10d, %r11d
andl %r9d, %r11d
movq 0x10(%rax), %rbx
movl $0x1, %ebp
movl %r11d, %esi
movl %esi, %ecx
shrl $0x4, %ecx
movl (%rbx,%rcx,4), %r14d
leal (%rsi,%rsi), %ecx
andl $0x1e, %ecx
movl %r14d, %r15d
shrl %cl, %r15d
testb $0x2, %r15b
jne 0x8838f
testb $0x1, %r15b
jne 0x8837f
movq 0x18(%rax), %r15
movl %esi, %r12d
cmpl %r9d, (%r15,%r12,4)
je 0x8838f
addl %ebp, %esi
andl %r10d, %esi
incl %ebp
cmpl %r11d, %esi
jne 0x88351
movl %edi, %esi
jmp 0x8839d
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %edi, %esi
jmp 0x8839d
xorl %esi, %esi
cmpl %edi, %esi
je 0x88438
movq 0x20(%rax), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rax
testq %rdx, %rdx
je 0x8843a
movq %rax, %rsi
movq 0x20(%rsi), %r9
testq %r9, %r9
sete %dil
je 0x8842a
movb (%rdx), %r10b
movq 0x8(%r9), %r14
cmpb %r10b, (%r14)
jne 0x8841e
movb 0x1(%r14), %r11b
cmpb 0x1(%rdx), %r11b
jne 0x8841e
movb 0x3(%r14), %r11b
testb %r11b, %r11b
je 0x88403
addq $0x4, %r14
movq %r8, %rbx
cmpb (%rbx), %r11b
jne 0x8840b
incq %rbx
movb (%r14), %r11b
incq %r14
testb %r11b, %r11b
jne 0x883ee
jmp 0x88406
movq %r8, %rbx
movq %rsi, %r14
jmp 0x88411
movb $0x1, %r11b
movq %rcx, %r14
movb (%rbx), %bl
testb %bl, %bl
cmoveq %r14, %rcx
orb %bl, %r11b
je 0x8842d
movq (%r9), %r9
testq %r9, %r9
sete %dil
jne 0x883cb
movq (%rsi), %rsi
testb $0x1, %dil
je 0x88443
cmpq %rax, %rsi
jne 0x883bb
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rax
jmp 0x8843a