// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x3ea6f
movl %eax, %esi
xorb $0x53, %sil
movl %ecx, %r8d
xorb $0x51, %r8b
orb %sil, %r8b
jne 0x3e97d
cmpb $0x53, (%rdx)
jne 0x3ea6f
cmpb $0x4e, 0x1(%rdx)
jne 0x3ea6f
movq 0x48(%rdi), %rax
movq %rax, 0x8(%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x3eb78
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x3eb80
movb 0x1(%rbx), %al
testb %al, %al
je 0x3eb83
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 0x3e95f
jmp 0x3eb83
movzbl %al, %esi
cmpl $0x50, %esi
je 0x3ea03
cmpl $0x52, %esi
jne 0x3ea6f
cmpb $0x47, %cl
jne 0x3ea6f
cmpb $0x49, (%rdx)
jne 0x3ea6f
cmpb $0x44, 0x1(%rdx)
jne 0x3ea6f
movq 0x60(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %ecx
testl %ecx, %ecx
je 0x3ec44
leal -0x1(%rcx), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
je 0x3ec54
movb 0x1(%rbx), %al
testb %al, %al
je 0x3ec57
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 0x3e9e5
jmp 0x3ec57
cmpb $0x47, %cl
jne 0x3ea6f
cmpb $0x49, (%rdx)
jne 0x3ea6f
cmpb $0x44, 0x1(%rdx)
jne 0x3ea6f
movq 0x80(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x3ec4c
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x3ed10
movb 0x1(%rbx), %al
testb %al, %al
je 0x3ed13
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 0x3ea51
jmp 0x3ed13
movq 0x18(%rdi), %rsi
movl (%rsi), %edi
testl %edi, %edi
je 0x3eae0
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 0x3ead3
testb $0x1, %r15b
jne 0x3eac4
movq 0x18(%rsi), %r15
movl %r8d, %r12d
cmpl %eax, (%r15,%r12,4)
je 0x3ead3
addl %ebp, %r8d
andl %r9d, %r8d
incl %ebp
cmpl %r10d, %r8d
jne 0x3ea94
jmp 0x3eae8
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %edi, %r8d
jmp 0x3eae3
xorl %r8d, %r8d
cmpl %edi, %r8d
jne 0x3eafd
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 0x3eaeb
movq %r10, %rax
movq 0x10(%rax), %rcx
testq %rcx, %rcx
je 0x3eb63
movb (%rdx), %sil
movq 0x8(%rcx), %rdi
cmpb %sil, (%rdi)
jne 0x3eb5b
movb 0x1(%rdi), %r8b
cmpb 0x1(%rdx), %r8b
jne 0x3eb5b
movb 0x3(%rdi), %r9b
movq %rbx, %r8
testb %r9b, %r9b
je 0x3eb55
addq $0x4, %rdi
movq %rbx, %r8
cmpb (%r8), %r9b
jne 0x3eb5b
incq %r8
movb (%rdi), %r9b
incq %rdi
testb %r9b, %r9b
jne 0x3eb42
cmpb $0x0, (%r8)
je 0x3eb70
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3eb1c
movq (%rax), %rax
cmpq %r10, %rax
jne 0x3eb10
jmp 0x3eae8
movq %rax, %r10
jmp 0x3eaeb
xorl %r14d, %r14d
jmp 0x3ec14
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 0x3ebfd
testb $0x1, %al
jne 0x3ebea
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movq 0x20(%rsp), %rdx
movl (%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x3ebfd
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x3eba3
jmp 0x3eaeb
movl %ebp, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x10(%rsp), %rax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rdi
cmpl %eax, %r14d
je 0x3eae8
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 0x3eaeb
xorl %r14d, %r14d
jmp 0x3ece4
xorl %r14d, %r14d
jmp 0x3eda0
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 0x3ecce
testb $0x1, %al
jne 0x3ecbb
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movl %edi, 0x8(%rsp)
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movl 0x8(%rsp), %edi
movl 0x20(%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x3ecce
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x3ec72
jmp 0x3eaeb
movl %ebp, %ecx
shrl %cl, %edi
testb $0x3, %dil
movq 0x10(%rsp), %rcx
cmovnel %ecx, %r14d
movq 0x18(%rsp), %rdi
cmpl %ecx, %r14d
je 0x3eae8
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 0x3ec3c
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 0x3ed8a
testb $0x1, %al
jne 0x3ed77
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movl %edi, 0x8(%rsp)
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movl 0x8(%rsp), %edi
movl 0x20(%rsp), %esi
xorl %r10d, %r10d
testl %eax, %eax
je 0x3ed8a
addl %r13d, %r14d
andl %esi, %r14d
incl %r13d
cmpl %r12d, %r14d
jne 0x3ed2e
jmp 0x3eaeb
movl %ebp, %ecx
shrl %cl, %edi
testb $0x3, %dil
movq 0x10(%rsp), %rax
cmovnel %eax, %r14d
movq 0x18(%rsp), %rdi
cmpl %eax, %r14d
je 0x3eae8
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 0x3ec3c