// File: /workspace/github_c_makefile_star2_O1/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 0x62c39
movl %ecx, %esi
movl %eax, %r9d
xorb $0x53, %r9b
movl %ecx, %r8d
xorb $0x51, %r8b
orb %r9b, %r8b
jne 0x62b52
cmpb $0x53, (%rdx)
jne 0x62b52
cmpb $0x4e, 0x1(%rdx)
jne 0x62b52
movq 0x48(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x62d5c
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x62d74
movb 0x1(%rbx), %al
testb %al, %al
je 0x62d77
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 0x62b34
jmp 0x62d77
movl %eax, %r8d
xorb $0x52, %r8b
xorb $0x47, %sil
orb %sil, %r8b
jne 0x62bc6
cmpb $0x49, (%rdx)
jne 0x62bc6
cmpb $0x44, 0x1(%rdx)
jne 0x62bc6
movq 0x60(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x62d64
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x62e33
movb 0x1(%rbx), %al
testb %al, %al
je 0x62e36
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 0x62ba8
jmp 0x62e36
movl %eax, %r8d
xorb $0x50, %r8b
orb %sil, %r8b
jne 0x62c39
cmpb $0x49, (%rdx)
jne 0x62c39
cmpb $0x44, 0x1(%rdx)
jne 0x62c39
movq 0x80(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x62d6c
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
je 0x62ef2
movb 0x1(%rbx), %al
testb %al, %al
je 0x62ef5
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 0x62c1b
jmp 0x62ef5
movq 0x18(%rdi), %rsi
movl (%rsi), %edi
testl %edi, %edi
je 0x62cad
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 0x62ca0
testb $0x1, %r15b
jne 0x62c8e
movq 0x18(%rsi), %r15
movl %r8d, %r12d
cmpl %eax, (%r15,%r12,4)
je 0x62ca0
addl %ebp, %r8d
andl %r9d, %r8d
incl %ebp
cmpl %r10d, %r8d
jne 0x62c5e
movl %edi, %r8d
jmp 0x62cb0
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %edi, %r8d
jmp 0x62cb0
xorl %r8d, %r8d
cmpl %edi, %r8d
je 0x62f8a
movq 0x20(%rsi), %rax
movl %r8d, %ecx
movq (%rax,%rcx,8), %rax
testq %rdx, %rdx
je 0x62f8c
movq %rax, %rsi
movq 0x10(%rsi), %r8
testq %r8, %r8
sete %dil
je 0x62d41
movb (%rdx), %r9b
movq 0x8(%r8), %r14
cmpb %r9b, (%r14)
jne 0x62d35
movb 0x1(%r14), %r10b
cmpb 0x1(%rdx), %r10b
jne 0x62d35
movb 0x3(%r14), %r10b
testb %r10b, %r10b
je 0x62d18
addq $0x4, %r14
movq %rbx, %r11
cmpb (%r11), %r10b
jne 0x62d20
incq %r11
movb (%r14), %r10b
incq %r14
testb %r10b, %r10b
jne 0x62d03
jmp 0x62d1b
movq %rbx, %r11
movq %rsi, %r14
jmp 0x62d26
movb $0x1, %r10b
movq %rcx, %r14
movb (%r11), %r11b
testb %r11b, %r11b
cmoveq %r14, %rcx
orb %r11b, %r10b
je 0x62d44
movq (%r8), %r8
testq %r8, %r8
sete %dil
jne 0x62ce0
movq (%rsi), %rsi
testb $0x1, %dil
je 0x62d54
cmpq %rax, %rsi
jne 0x62cd0
jmp 0x62f8a
movq %rcx, %rax
jmp 0x62f8c
xorl %r15d, %r15d
jmp 0x62e07
xorl %r15d, %r15d
jmp 0x62ec6
xorl %r15d, %r15d
jmp 0x62f85
xorl %r12d, %r12d
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %r13d
movl %r12d, %r15d
movl %esi, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x62df0
testb $0x1, %al
jne 0x62dd8
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x62df0
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x62d94
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x62e02
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
je 0x62f8a
movq 0x40(%rdi), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r15d, %edx
movslq (%rcx,%rdx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x10, %rax
jmp 0x62fba
xorl %r12d, %r12d
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %r13d
movl %r12d, %r15d
movl %esi, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x62eaf
testb $0x1, %al
jne 0x62e97
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x62eaf
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x62e53
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x62ec1
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
je 0x62f8a
movq 0x58(%rdi), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r15d, %edx
movslq (%rcx,%rdx,4), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x8, %rax
jmp 0x62fba
xorl %r12d, %r12d
andl %esi, %r12d
movq (%rsp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %r13d
movl %r12d, %r15d
movl %esi, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r14d
leal (%r15,%r15), %ebp
andl $0x1e, %ebp
movl %r14d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x62f6e
testb $0x1, %al
jne 0x62f56
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x6a50
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x62f6e
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x62f12
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x62f80
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
jne 0x62f9b
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x78(%rdi), %rax
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movl %r15d, %edx
movslq (%rcx,%rdx,4), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x8, %rax
movq (%rax), %rax
jmp 0x62f8c