// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/sam.c
// Function: sam_hdr_parse
bam_hdr_t *sam_hdr_parse(int l_text, const char *text)
{
	const char *q, *r, *p;
	khash_t(s2i) *d;
	d = kh_init(s2i);
	for (p = text; *p; ++p) {
		if (strncmp(p, "@SQ", 3) == 0) {
			char *sn = 0;
			int ln = -1;
			for (q = p + 4;; ++q) {
				if (strncmp(q, "SN:", 3) == 0) {
					q += 3;
					for (r = q; *r != '\t' && *r != '\n'; ++r);
					sn = (char*)calloc(r - q + 1, 1);
					strncpy(sn, q, r - q);
					q = r;
				} else if (strncmp(q, "LN:", 3) == 0)
					ln = strtol(q + 3, (char**)&q, 10);
				while (*q != '\t' && *q != '\n') ++q;
				if (*q == '\n') break;
			}
			p = q;
			if (sn && ln >= 0) {
				khint_t k;
				int absent;
				k = kh_put(s2i, d, sn, &absent);
				if (!absent) {
					if (hts_verbose >= 2)
						fprintf(stderr, "[W::%s] duplicated sequence '%s'\n", __func__, sn);
					free(sn);
				} else kh_val(d, k) = (int64_t)(kh_size(d) - 1)<<32 | ln;
			}
		}
		while (*p != '\n') ++p;
	}
	return hdr_from_dict(d);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbp
xorl %eax, %eax
callq 0x49c2
movq %rax, %rbx
movzbl (%rbp), %eax
cmpl $0x40, %eax
je 0x866f
testl %eax, %eax
jne 0x8793
jmp 0x87cb
cmpb $0x53, 0x1(%rbp)
jne 0x8793
cmpb $0x51, 0x2(%rbp)
jne 0x8793
addq $0x4, %rbp
movq %rbp, %r14
xorl %r15d, %r15d
pushq $-0x1
popq %rax
movl %eax, %r13d
movq %r14, 0x8(%rsp)
movzbl (%r14), %eax
cmpl $0x4c, %eax
je 0x86fa
cmpl $0x53, %eax
jne 0x8724
cmpb $0x4e, 0x1(%r14)
jne 0x8724
cmpb $0x3a, 0x2(%r14)
jne 0x8724
leaq 0x3(%r14), %rbp
movq %rbp, 0x8(%rsp)
addq $0x2, %r14
pushq $-0x1
popq %r12
movb 0x1(%r14), %al
incq %r14
addb $-0x9, %al
incq %r12
cmpb $0x1, %al
ja 0x86c5
leaq 0x1(%r12), %rdi
pushq $0x1
popq %rsi
callq 0x21f0
movq %rax, %r15
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2080
movq %r14, 0x8(%rsp)
jmp 0x8724
cmpb $0x4e, 0x1(%r14)
jne 0x8724
cmpb $0x3a, 0x2(%r14)
jne 0x8724
addq $0x3, %r14
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2230
movq %rax, %r13
movq 0x8(%rsp), %r14
movb (%r14), %al
leal -0x9(%rax), %ecx
incq %r14
cmpb $0x1, %cl
ja 0x8724
leaq -0x1(%r14), %rbp
movq %rbp, 0x8(%rsp)
cmpb $0xa, %al
jne 0x8693
testq %r15, %r15
je 0x8793
testl %r13d, %r13d
js 0x8793
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x14(%rsp), %rdx
callq 0x4d79
cmpl $0x0, 0x14(%rsp)
je 0x877f
movl 0x4(%rbx), %ecx
decl %ecx
shlq $0x20, %rcx
movl %r13d, %edx
orq %rcx, %rdx
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq %rdx, (%rcx,%rax,8)
jmp 0x8793
leaq 0x8aaa(%rip), %rax      # 0x11230
cmpl $0x2, (%rax)
jge 0x87a7
movq %r15, %rdi
callq 0x2050
movq %rbp, %rax
leaq 0x1(%rax), %rbp
cmpb $0xa, (%rax)
movq %rbp, %rax
jne 0x8796
jmp 0x8659
movq 0x884a(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x3d5e(%rip), %rsi      # 0xc516
leaq 0x3d79(%rip), %rdx      # 0xc538
movq %r15, %rcx
xorl %eax, %eax
callq 0x2220
jmp 0x878b
callq 0x7ad8
movq %rax, %r14
movq %rbx, 0x30(%rax)
movslq 0x4(%rbx), %r12
movl %r12d, (%rax)
leaq (,%r12,4), %rdi
callq 0x22a0
movq %rax, %r15
movq %rax, 0x10(%r14)
shlq $0x3, %r12
movq %r12, %rdi
callq 0x22a0
movq %rax, 0x20(%r14)
movl (%rbx), %edx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x8855
movq 0x10(%rbx), %rcx
movl %edi, %r8d
shrl $0x4, %r8d
movl (%rcx,%r8,4), %r8d
movl %esi, %ecx
andb $0x1e, %cl
shrl %cl, %r8d
testb $0x3, %r8b
jne 0x884d
movq 0x18(%rbx), %rcx
movq 0x20(%rbx), %r8
movq (%rcx,%rdi,8), %rcx
movq (%r8,%rdi,8), %r9
movq %r9, %r10
sarq $0x20, %r10
movq %rcx, (%rax,%r10,8)
movl %r9d, (%r15,%r10,4)
movq %r10, (%r8,%rdi,8)
incq %rdi
addl $0x2, %esi
jmp 0x8808
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq