// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
callq 0xdced
movq %rax, %rbx
cmpb $0x0, (%r13)
je 0x15565
leaq 0x3dfa1(%rip), %r15     # 0x5335e
leaq 0x3dfec(%rip), %r14     # 0x533b0
movl $0x4, %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x4280
testl %eax, %eax
je 0x153f5
incq %r13
movzbl -0x1(%r13), %eax
testl %eax, %eax
je 0x153e9
cmpl $0xa, %eax
jne 0x153d8
cmpb $0x0, (%r13)
jne 0x153c4
jmp 0x15565
addq $0x4, %r13
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq %r13, (%rsp)
movl $0x3, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x4280
testl %eax, %eax
je 0x1544e
movl $0x3, %edx
movq %r13, %rdi
leaq 0x3df3b(%rip), %rsi     # 0x53363
callq 0x4280
testl %eax, %eax
jne 0x154b5
addq $0x3, %r13
movq %r13, %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x4760
movq %rax, %r12
jmp 0x154b5
movq %r12, 0x10(%rsp)
movq %rbx, %r12
movq %r14, %rbx
movq %r15, %r14
addq $0x3, %r13
movq %r13, (%rsp)
xorl %r15d, %r15d
movl $0x601, %ecx            # imm = 0x601
movzbl (%r13,%r15), %eax
cmpl $0xa, %eax
ja 0x1547c
btl %eax, %ecx
jb 0x15481
incq %r15
jmp 0x1546c
leaq 0x1(%r15), %rdi
movl $0x1, %esi
callq 0x4360
movq %rax, %rbp
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x42b0
addq %r15, %r13
movq %r13, (%rsp)
movq %r14, %r15
movq %rbx, %r14
movq %r12, %rbx
movq 0x10(%rsp), %r12
movq (%rsp), %r13
movzbl (%r13), %eax
testl %eax, %eax
je 0x154dd
cmpl $0x9, %eax
je 0x154d1
cmpl $0xa, %eax
je 0x154dd
incq %r13
jmp 0x154b9
movq %r13, (%rsp)
incq %r13
jmp 0x15401
movq %r13, (%rsp)
testq %rbp, %rbp
je 0x153d8
testl %r12d, %r12d
js 0x153d8
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xc(%rsp), %rdx
callq 0xe123
cmpl $0x0, 0xc(%rsp)
je 0x15528
movl 0x4(%rbx), %ecx
decl %ecx
shlq $0x20, %rcx
movl %r12d, %edx
orq %rcx, %rdx
movq 0x20(%rbx), %rcx
movl %eax, %eax
movq %rdx, (%rcx,%rax,8)
jmp 0x153d8
leaq 0x4f021(%rip), %rax     # 0x64550
cmpl $0x2, (%rax)
jge 0x15541
movq %rbp, %rdi
callq 0x4610
jmp 0x153d8
movq 0x4ea80(%rip), %rax     # 0x63fc8
movq (%rax), %rdi
leaq 0x3de15(%rip), %rsi     # 0x53367
leaq 0x3de30(%rip), %rdx     # 0x53389
movq %rbp, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x15534
movl $0x1, %edi
movl $0x38, %esi
callq 0x4360
movq %rax, %r14
movq %rbx, 0x30(%rax)
movslq 0x4(%rbx), %r12
movl %r12d, (%rax)
leaq (,%r12,4), %rdi
callq 0x4700
movq %rax, %r15
movq %rax, 0x10(%r14)
shlq $0x3, %r12
movq %r12, %rdi
callq 0x4700
movq %rax, 0x20(%r14)
movl (%rbx), %edx
testq %rdx, %rdx
je 0x155fc
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 0x155f1
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 0x155b6
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq