// File: /workspace/github_c_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movsbl (%rsi), %eax
movsbl 0x1(%rsi), %ecx
testq %rdx, %rdx
je 0x62d98
movl %eax, %esi
xorb $0x53, %sil
movl %ecx, %r8d
xorb $0x51, %r8b
orb %sil, %r8b
jne 0x62ca6
cmpb $0x53, (%rdx)
jne 0x62d98
cmpb $0x4e, 0x1(%rdx)
jne 0x62d98
movq 0x48(%rdi), %rax
movq %rax, 0x8(%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x62ea1
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x62ea9
movb 0x1(%rbx), %al
testb %al, %al
je 0x62eac
leaq 0x2(%rbx), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x62c88
jmp 0x62eac
movzbl %al, %esi
cmpl $0x50, %esi
je 0x62d2c
cmpl $0x52, %esi
jne 0x62d98
cmpb $0x47, %cl
jne 0x62d98
cmpb $0x49, (%rdx)
jne 0x62d98
cmpb $0x44, 0x1(%rdx)
jne 0x62d98
movq 0x60(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %ecx
testl %ecx, %ecx
je 0x62f6d
leal -0x1(%rcx), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
je 0x62f7d
movb 0x1(%rbx), %al
testb %al, %al
je 0x62f80
leaq 0x2(%rbx), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x62d0e
jmp 0x62f80
cmpb $0x47, %cl
jne 0x62d98
cmpb $0x49, (%rdx)
jne 0x62d98
cmpb $0x44, 0x1(%rdx)
jne 0x62d98
movq 0x80(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x62f75
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x63039
movb 0x1(%rbx), %al
testb %al, %al
je 0x6303c
leaq 0x2(%rbx), %rcx
movl %r12d, %edx
shll $0x5, %edx
subl %r12d, %edx
movsbl %al, %r12d
addl %edx, %r12d
movb (%rcx), %al
incq %rcx
testb %al, %al
jne 0x62d7a
jmp 0x6303c
movq 0x18(%rdi), %rsi
movl (%rsi), %edi
testl %edi, %edi
je 0x62e09
shll $0x8, %eax
orl %ecx, %eax
leal -0x1(%rdi), %r9d
movl %r9d, %r10d
andl %eax, %r10d
movq 0x10(%rsi), %r11
movl $0x1, %ebp
movl %r10d, %r8d
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%r11,%rcx,4), %r14d
leal (%r8,%r8), %ecx
andl $0x1e, %ecx
movl %r14d, %r15d
shrl %cl, %r15d
testb $0x2, %r15b
jne 0x62dfc
testb $0x1, %r15b
jne 0x62ded
movq 0x18(%rsi), %r15
movl %r8d, %r12d
cmpl %eax, (%r15,%r12,4)
je 0x62dfc
addl %ebp, %r8d
andl %r9d, %r8d
incl %ebp
cmpl %r10d, %r8d
jne 0x62dbd
jmp 0x62e11
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %edi, %r8d
jmp 0x62e0c
xorl %r8d, %r8d
cmpl %edi, %r8d
jne 0x62e26
xorl %r10d, %r10d
movq %r10, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsi), %rax
movl %r8d, %ecx
movq (%rax,%rcx,8), %r10
testq %rdx, %rdx
je 0x62e14
movq %r10, %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
je 0x62e8c
movb (%rdx), %sil
movq 0x8(%rcx), %rdi
cmpb %sil, (%rdi)
jne 0x62e84
movb 0x1(%rdi), %r8b
cmpb 0x1(%rdx), %r8b
jne 0x62e84
movb 0x3(%rdi), %r9b
movq %rbx, %r8
testb %r9b, %r9b
je 0x62e7e
addq $0x4, %rdi
movq %rbx, %r8
cmpb (%r8), %r9b
jne 0x62e84
incq %r8
movb (%rdi), %r9b
incq %rdi
testb %r9b, %r9b
jne 0x62e6b
cmpb $0x0, (%r8)
je 0x62e99
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x62e45
movq (%rax), %rax
cmpq %r10, %rax
jne 0x62e39
jmp 0x62e11
movq %rax, %r10
jmp 0x62e14
xorl %r14d, %r14d
jmp 0x62f3d
xorl %r12d, %r12d
andl %esi, %r12d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %r13d
xorl %r10d, %r10d
movl %r12d, %r14d
movl %esi, (%rsp)
movq %rdx, 0x20(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r15d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r15d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x62f26
testb $0x1, %al
jne 0x62f13
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movq 0x20(%rsp), %rdx
movl (%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x62f26
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x62ecc
jmp 0x62e14
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x10(%rsp), %rax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rdi
cmpl %eax, %r14d
je 0x62e11
movq 0x40(%rdi), %rax
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r14d, %edx
movslq (%rcx,%rdx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x10, %rax
movq (%rax), %r10
jmp 0x62e14
xorl %r14d, %r14d
jmp 0x6300d
xorl %r14d, %r14d
jmp 0x630c9
xorl %r12d, %r12d
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %r15
movl $0x1, %r13d
xorl %r10d, %r10d
movl %r12d, %r14d
movl %esi, 0x20(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %edi
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %edi, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x62ff7
testb $0x1, %al
jne 0x62fe4
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movl %edi, 0x8(%rsp)
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movl 0x8(%rsp), %edi
movl 0x20(%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x62ff7
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x62f9b
jmp 0x62e14
movl %ebp, %ecx
shrl %cl, %edi
testb $0x3, %dil
movq 0x10(%rsp), %rcx
cmovnel %ecx, %r14d
movq 0x18(%rsp), %rdi
cmpl %ecx, %r14d
je 0x62e11
movq 0x58(%rdi), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r14d, %edx
movslq (%rcx,%rdx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x8, %rax
jmp 0x62f65
xorl %r12d, %r12d
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %r15
movl $0x1, %r13d
xorl %r10d, %r10d
movl %r12d, %r14d
movl %esi, 0x20(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %edi
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %edi, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x630b3
testb $0x1, %al
jne 0x630a0
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movl %edi, 0x8(%rsp)
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movl 0x8(%rsp), %edi
movl 0x20(%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x630b3
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x63057
jmp 0x62e14
movl %ebp, %ecx
shrl %cl, %edi
testb $0x3, %dil
movq 0x10(%rsp), %rax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rdi
cmpl %eax, %r14d
je 0x62e11
movq 0x78(%rdi), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r14d, %edx
movslq (%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x8, %rax
jmp 0x62f65