// File: /workspace/github_c_makefile_star2_O3/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, %r15
xorl %eax, %eax
callq 0x4f74
movq %rax, %rbx
movb (%r15), %al
testb %al, %al
je 0x9920
cmpb $0x40, %al
jne 0x98ed
cmpb $0x53, 0x1(%r15)
jne 0x98ed
cmpb $0x51, 0x2(%r15)
jne 0x98ed
addq $0x4, %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %r15, %r13
xorl %r12d, %r12d
movq %r13, 0x8(%rsp)
movzbl (%r13), %eax
cmpl $0x4c, %eax
je 0x9853
cmpl $0x53, %eax
jne 0x987f
cmpb $0x4e, 0x1(%r13)
jne 0x987f
cmpb $0x3a, 0x2(%r13)
jne 0x987f
leaq 0x3(%r13), %r15
movq %r15, 0x8(%rsp)
addq $0x2, %r13
movq $-0x1, %r14
movb 0x1(%r13), %al
incq %r13
addb $-0x9, %al
incq %r14
cmpb $0x1, %al
ja 0x981d
leaq 0x1(%r14), %rdi
movl $0x1, %esi
callq 0x21f0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x2080
movq %r13, 0x8(%rsp)
jmp 0x987f
cmpb $0x4e, 0x1(%r13)
jne 0x987f
cmpb $0x3a, 0x2(%r13)
jne 0x987f
addq $0x3, %r13
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x2230
movq %rax, %rbp
movq 0x8(%rsp), %r13
movb (%r13), %al
leal -0x9(%rax), %ecx
incq %r13
cmpb $0x1, %cl
ja 0x987f
leaq -0x1(%r13), %r15
movq %r15, 0x8(%rsp)
cmpb $0xa, %al
jne 0x97e3
testq %r12, %r12
je 0x98ed
testl %ebp, %ebp
js 0x98ed
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x14(%rsp), %rdx
callq 0x5340
cmpl $0x0, 0x14(%rsp)
je 0x98d9
movl 0x4(%rbx), %ecx
decl %ecx
shlq $0x20, %rcx
movl %ebp, %edx
orq %rcx, %rdx
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq %rdx, (%rcx,%rax,8)
jmp 0x98ed
leaq 0x8940(%rip), %rax      # 0x12220
cmpl $0x2, (%rax)
jge 0x98fc
movq %r12, %rdi
callq 0x2050
cmpb $0xa, (%r15)
leaq 0x1(%r15), %r15
jne 0x98ed
jmp 0x97ab
movq 0x86f5(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x4c99(%rip), %rsi      # 0xe5a6
leaq 0x4cb4(%rip), %rdx      # 0xe5c8
movq %r12, %rcx
xorl %eax, %eax
callq 0x2220
jmp 0x98e5
movl $0x1, %edi
movl $0x38, %esi
callq 0x21f0
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
testq %rdx, %rdx
je 0x99b7
movq 0x10(%rbx), %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 0x99ac
movq 0x18(%rbx), %rcx
movq 0x20(%rbx), %r9
movq (%rcx,%r8,8), %rcx
movq (%r9,%r8,8), %r10
movq %r10, %r11
sarq $0x20, %r11
movq %rcx, (%rax,%r11,8)
movl %r10d, (%r15,%r11,4)
movq %r11, (%r9,%r8,8)
incq %r8
addl $0x2, %edi
cmpq %r8, %rdx
jne 0x9971
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq