// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/htslib/cram/sam_header.c
// Function: sam_hdr_find
SAM_hdr_type *sam_hdr_find(SAM_hdr *hdr, char *type,
			   char *ID_key, char *ID_value) {
    SAM_hdr_type *t1, *t2;
    int itype = (type[0]<<8)|(type[1]);
    khint_t k;

    /* Special case for types we have prebuilt hashes on */
    if (ID_key) {
	if (type[0]   == 'S' && type[1]   == 'Q' &&
	    ID_key[0] == 'S' && ID_key[1] == 'N') {
	    k = kh_get(m_s2i, hdr->ref_hash, ID_value);
	    return k != kh_end(hdr->ref_hash)
		? hdr->ref[kh_val(hdr->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, hdr->rg_hash, ID_value);
	    return k != kh_end(hdr->rg_hash)
		? hdr->rg[kh_val(hdr->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, hdr->pg_hash, ID_value);
	    return k != kh_end(hdr->pg_hash)
		? hdr->pg[kh_val(hdr->pg_hash, k)].ty
		: NULL;
	}
    }

    k = kh_get(sam_hdr, hdr->h, itype);
    if (k == kh_end(hdr->h))
	return NULL;
    
    if (!ID_key)
	return kh_val(hdr->h, k);

    t1 = t2 = kh_val(hdr->h, k);
    do {
	SAM_hdr_tag *tag;
	for (tag = t1->tag; tag; tag = tag->next) {
	    if (tag->str[0] == ID_key[0] && tag->str[1] == ID_key[1]) {
		char *cp1 = tag->str+3;
		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
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %r15
movsbl (%rsi), %esi
movsbl 0x1(%rax), %eax
testq %rdx, %rdx
je 0x58e95
movl %esi, %ecx
xorb $0x53, %cl
movl %eax, %edx
xorb $0x51, %dl
orb %cl, %dl
jne 0x58e0d
cmpb $0x53, (%r14)
jne 0x58e95
cmpb $0x4e, 0x1(%r14)
jne 0x58e95
movq 0x48(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x58f17
cmpl (%r14), %eax
je 0x58eab
movq 0x40(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
shlq $0x5, %rax
movq 0x10(%rcx,%rax), %rax
jmp 0x58f11
movzbl %sil, %ecx
cmpl $0x50, %ecx
je 0x58e54
cmpl $0x52, %ecx
jne 0x58e95
cmpb $0x47, %al
jne 0x58e95
cmpb $0x49, (%r14)
jne 0x58e95
cmpb $0x44, 0x1(%r14)
jne 0x58e95
movq 0x60(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x58f17
cmpl (%r14), %eax
je 0x58eab
movq 0x58(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
shlq $0x5, %rax
jmp 0x58e8e
cmpb $0x47, %al
jne 0x58e95
cmpb $0x49, (%r14)
jne 0x58e95
cmpb $0x44, 0x1(%r14)
jne 0x58e95
movq 0x80(%r15), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x58f17
cmpl (%r14), %eax
je 0x58eab
movq 0x78(%r15), %rcx
movq 0x20(%r14), %rdx
movl %eax, %eax
movslq (%rdx,%rax,4), %rax
imulq $0x28, %rax, %rax
movq 0x8(%rcx,%rax), %rax
jmp 0x58f11
shll $0x8, %esi
orl %eax, %esi
movq 0x18(%r15), %r15
movq %r15, %rdi
callq 0x58fd8
cmpl (%r15), %eax
jne 0x58eaf
xorl %eax, %eax
jmp 0x58f11
movq 0x20(%r15), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
testq %r14, %r14
je 0x58f11
movq %rax, %rcx
leaq 0x10(%rcx), %rdx
movq (%rdx), %rdx
testq %rdx, %rdx
je 0x58f04
movq 0x8(%rdx), %rsi
movb (%rsi), %dil
cmpb (%r14), %dil
jne 0x58ec5
movb 0x1(%rsi), %dil
cmpb 0x1(%r14), %dil
jne 0x58ec5
xorl %edi, %edi
movb 0x3(%rsi,%rdi), %r8b
movb (%rbx,%rdi), %r9b
testb %r8b, %r8b
je 0x58efd
cmpb %r9b, %r8b
jne 0x58ec5
incq %rdi
jmp 0x58ee5
testb %r9b, %r9b
jne 0x58ec5
jmp 0x58f0e
movq (%rcx), %rcx
cmpq %rax, %rcx
jne 0x58ec1
jmp 0x58eab
movq %rcx, %rax
popq %rbx
popq %r14
popq %r15
retq