// File: /workspace/github_c_makefile_star2_O1/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 0x4ec3
movq %rax, 0x10(%rsp)
cmpb $0x0, (%rbp)
je 0x973a
leaq 0x4f5e(%rip), %rbx      # 0xe522
leaq 0x4f98(%rip), %r15      # 0xe563
movl $0x3, %edx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2090
testl %eax, %eax
jne 0x9700
addq $0x4, %rbp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq %rbp, %r14
xorl %ebx, %ebx
movq %r14, (%rsp)
movl $0x3, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2090
testl %eax, %eax
je 0x963b
movl $0x3, %edx
movq %r14, %rdi
leaq 0x4f0d(%rip), %rsi      # 0xe526
callq 0x2090
testl %eax, %eax
jne 0x9681
addq $0x3, %r14
movq %r14, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x2230
movq %rax, %r12
jmp 0x9681
leaq 0x3(%r14), %rbp
movq %rbp, (%rsp)
addq $0x2, %r14
movq $-0x1, %r13
movb 0x1(%r14), %al
incq %r14
addb $-0x9, %al
incq %r13
cmpb $0x1, %al
ja 0x964e
leaq 0x1(%r13), %rdi
movl $0x1, %esi
callq 0x21f0
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2080
movq %r14, (%rsp)
movq (%rsp), %r14
movb (%r14), %al
leal -0x9(%rax), %ecx
incq %r14
cmpb $0x1, %cl
ja 0x9685
leaq -0x1(%r14), %rbp
movq %rbp, (%rsp)
cmpb $0xa, %al
jne 0x95f2
testq %rbx, %rbx
je 0x96f9
testl %r12d, %r12d
js 0x96f9
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0xc(%rsp), %rdx
callq 0x529d
cmpl $0x0, 0xc(%rsp)
je 0x96e5
movl 0x4(%r14), %ecx
decl %ecx
shlq $0x20, %rcx
movl %r12d, %edx
orq %rcx, %rdx
movq 0x20(%r14), %rcx
movl %eax, %eax
movq %rdx, (%rcx,%rax,8)
jmp 0x96f9
leaq 0x8b34(%rip), %rax      # 0x12220
cmpl $0x2, (%rax)
jge 0x9716
movq %rbx, %rdi
callq 0x2050
leaq 0x4e22(%rip), %rbx      # 0xe522
cmpb $0xa, (%rbp)
leaq 0x1(%rbp), %rbp
jne 0x9700
cmpb $0x0, (%rbp)
jne 0x95cb
jmp 0x973a
movq 0x88db(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x4e03(%rip), %rsi      # 0xe52a
leaq 0x4e1e(%rip), %rdx      # 0xe54c
movq %rbx, %rcx
xorl %eax, %eax
callq 0x2220
jmp 0x96f1
movl $0x1, %edi
movl $0x38, %esi
callq 0x21f0
movq %rax, %rbx
movq 0x10(%rsp), %r12
movq %r12, 0x30(%rax)
movslq 0x4(%r12), %r15
movl %r15d, (%rax)
leaq (,%r15,4), %rdi
callq 0x22a0
movq %rax, %r14
movq %rax, 0x10(%rbx)
shlq $0x3, %r15
movq %r15, %rdi
callq 0x22a0
movq %rax, 0x20(%rbx)
movl (%r12), %edx
testq %rdx, %rdx
je 0x97dc
movq 0x10(%r12), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl %r8d, %ecx
shrl $0x4, %ecx
movl (%rsi,%rcx,4), %r9d
movl %edi, %ecx
andb $0x1e, %cl
shrl %cl, %r9d
testb $0x3, %r9b
jne 0x97d1
movq 0x18(%r12), %rcx
movq 0x20(%r12), %r9
movq (%rcx,%r8,8), %rcx
movq (%r9,%r8,8), %r10
movq %r10, %r11
sarq $0x20, %r11
movq %rcx, (%rax,%r11,8)
movl %r10d, (%r14,%r11,4)
movq %r11, (%r9,%r8,8)
incq %r8
addl $0x2, %edi
cmpq %r8, %rdx
jne 0x9794
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq