// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/htslib/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\t", 4) == 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 != '\0'; ++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 != '\0') ++q;
                if (*q == '\0' || *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 != '\0' && *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
callq 0xb951
movq %rax, %rbx
leaq 0x3262e(%rip), %r14     # 0x442ee
pushq $0x4
popq %r12
cmpb $0x0, (%r15)
je 0x11e56
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4280
testl %eax, %eax
je 0x11cf3
incq %r15
movzbl -0x1(%r15), %eax
testl %eax, %eax
je 0x11cc4
cmpl $0xa, %eax
jne 0x11ce0
jmp 0x11cc4
addq $0x4, %r15
xorl %r13d, %r13d
pushq $-0x1
popq %rax
movl %eax, %ebp
movq %r15, 0x8(%rsp)
movzbl (%r15), %eax
cmpl $0x4c, %eax
je 0x11d51
cmpl $0x53, %eax
jne 0x11dae
cmpb $0x4e, 0x1(%r15)
jne 0x11dae
cmpb $0x3a, 0x2(%r15)
jne 0x11dae
addq $0x3, %r15
movq %r15, 0x8(%rsp)
xorl %r14d, %r14d
movzbl (%r15,%r14), %eax
cmpl $0xa, %eax
ja 0x11d4c
movl $0x601, %ecx            # imm = 0x601
btl %eax, %ecx
jb 0x11d7d
incq %r14
jmp 0x11d38
cmpb $0x4e, 0x1(%r15)
jne 0x11dae
cmpb $0x3a, 0x2(%r15)
jne 0x11dae
addq $0x3, %r15
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x4760
movq %rax, %rbp
movq 0x8(%rsp), %r15
jmp 0x11dae
leaq 0x1(%r14), %rdi
pushq $0x1
popq %rsi
callq 0x4370
movq %rax, %r13
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x42c0
addq %r14, %r15
movq %r15, 0x8(%rsp)
leaq 0x32545(%rip), %r14     # 0x442ee
jmp 0x11dae
incq %r15
movzbl (%r15), %eax
testl %eax, %eax
je 0x11dcf
cmpl $0x9, %eax
je 0x11dc2
cmpl $0xa, %eax
jne 0x11dab
jmp 0x11dcf
movq %r15, 0x8(%rsp)
incq %r15
jmp 0x11cff
movq %r15, 0x8(%rsp)
testq %r13, %r13
je 0x11ce0
testl %ebp, %ebp
js 0x11ce0
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x14(%rsp), %rdx
callq 0xbd19
cmpl $0x0, 0x14(%rsp)
je 0x11e19
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 0x11ce0
leaq 0x45728(%rip), %rax     # 0x57548
cmpl $0x2, (%rax)
jge 0x11e32
movq %r13, %rdi
callq 0x4600
jmp 0x11ce0
movq 0x45197(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0x324b0(%rip), %rsi     # 0x442f3
leaq 0x324cb(%rip), %rdx     # 0x44315
movq %r13, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x11e25
callq 0x10b38
movq %rax, %r14
movq %rbx, 0x30(%rax)
movslq 0x4(%rbx), %r12
movl %r12d, (%rax)
leaq (,%r12,4), %rdi
callq 0x46f0
movq %rax, %r15
movq %rax, 0x10(%r14)
shlq $0x3, %r12
movq %r12, %rdi
callq 0x46f0
movq %rax, 0x20(%r14)
movl (%rbx), %edx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x11ee0
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 0x11ed8
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 0x11e93
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq