// File: /workspace/github_cpp_makefile_star2_O1/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 0x3f913
movl %ecx, %esi
movl %eax, %r9d
xorb $0x53, %r9b
movl %ecx, %r8d
xorb $0x51, %r8b
orb %r9b, %r8b
jne 0x3f82c
cmpb $0x53, (%rdx)
jne 0x3f82c
cmpb $0x4e, 0x1(%rdx)
jne 0x3f82c
movq 0x48(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x3fa36
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x3fa4e
movb 0x1(%rbx), %al
testb %al, %al
je 0x3fa51
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 0x3f80e
jmp 0x3fa51
movl %eax, %r8d
xorb $0x52, %r8b
xorb $0x47, %sil
orb %sil, %r8b
jne 0x3f8a0
cmpb $0x49, (%rdx)
jne 0x3f8a0
cmpb $0x44, 0x1(%rdx)
jne 0x3f8a0
movq 0x60(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x3fa3e
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
movq %rax, 0x10(%rsp)
je 0x3fb0d
movb 0x1(%rbx), %al
testb %al, %al
je 0x3fb10
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 0x3f882
jmp 0x3fb10
movl %eax, %r8d
xorb $0x50, %r8b
orb %sil, %r8b
jne 0x3f913
cmpb $0x49, (%rdx)
jne 0x3f913
cmpb $0x44, 0x1(%rdx)
jne 0x3f913
movq 0x80(%rdi), %rax
movq %rax, (%rsp)
movl (%rax), %eax
testl %eax, %eax
je 0x3fa46
movq %rax, 0x10(%rsp)
leal -0x1(%rax), %esi
movsbl (%rbx), %r12d
testl %r12d, %r12d
movq %rdi, 0x18(%rsp)
je 0x3fbcc
movb 0x1(%rbx), %al
testb %al, %al
je 0x3fbcf
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 0x3f8f5
jmp 0x3fbcf
movq 0x18(%rdi), %rsi
movl (%rsi), %edi
testl %edi, %edi
je 0x3f987
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 0x3f97a
testb $0x1, %r15b
jne 0x3f968
movq 0x18(%rsi), %r15
movl %r8d, %r12d
cmpl %eax, (%r15,%r12,4)
je 0x3f97a
addl %ebp, %r8d
andl %r9d, %r8d
incl %ebp
cmpl %r10d, %r8d
jne 0x3f938
movl %edi, %r8d
jmp 0x3f98a
shrl %cl, %r14d
testb $0x3, %r14b
cmovnel %edi, %r8d
jmp 0x3f98a
xorl %r8d, %r8d
cmpl %edi, %r8d
je 0x3fc64
movq 0x20(%rsi), %rax
movl %r8d, %ecx
movq (%rax,%rcx,8), %rax
testq %rdx, %rdx
je 0x3fc66
movq %rax, %rsi
movq 0x10(%rsi), %r8
testq %r8, %r8
sete %dil
je 0x3fa1b
movb (%rdx), %r9b
movq 0x8(%r8), %r14
cmpb %r9b, (%r14)
jne 0x3fa0f
movb 0x1(%r14), %r10b
cmpb 0x1(%rdx), %r10b
jne 0x3fa0f
movb 0x3(%r14), %r10b
testb %r10b, %r10b
je 0x3f9f2
addq $0x4, %r14
movq %rbx, %r11
cmpb (%r11), %r10b
jne 0x3f9fa
incq %r11
movb (%r14), %r10b
incq %r14
testb %r10b, %r10b
jne 0x3f9dd
jmp 0x3f9f5
movq %rbx, %r11
movq %rsi, %r14
jmp 0x3fa00
movb $0x1, %r10b
movq %rcx, %r14
movb (%r11), %r11b
testb %r11b, %r11b
cmoveq %r14, %rcx
orb %r11b, %r10b
je 0x3fa1e
movq (%r8), %r8
testq %r8, %r8
sete %dil
jne 0x3f9ba
movq (%rsi), %rsi
testb $0x1, %dil
je 0x3fa2e
cmpq %rax, %rsi
jne 0x3f9aa
jmp 0x3fc64
movq %rcx, %rax
jmp 0x3fc66
xorl %r15d, %r15d
jmp 0x3fae1
xorl %r15d, %r15d
jmp 0x3fba0
xorl %r15d, %r15d
jmp 0x3fc5f
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 0x3faca
testb $0x1, %al
jne 0x3fab2
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x3faca
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x3fa6e
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x3fadc
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
je 0x3fc64
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 0x3fc94
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 0x3fb89
testb $0x1, %al
jne 0x3fb71
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x3fb89
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x3fb2d
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x3fb9b
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
je 0x3fc64
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 0x3fc94
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 0x3fc48
testb $0x1, %al
jne 0x3fc30
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x4750
movq 0x20(%rsp), %rdx
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x3fc48
addl %r13d, %r15d
andl %esi, %r15d
incl %r13d
cmpl %r12d, %r15d
jne 0x3fbec
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x3fc5a
movl %ebp, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %rdi
cmpl %eax, %r15d
jne 0x3fc75
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 0x3fc66