// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
callq 0xdc6f
movq %rax, %rbx
cmpb $0x0, (%r14)
je 0x154e4
leaq 0x3c042(%rip), %r15     # 0x5138e
leaq 0x14(%rsp), %r13
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4280
testl %eax, %eax
je 0x15381
incq %r14
movzbl -0x1(%r14), %eax
testl %eax, %eax
je 0x15376
cmpl $0xa, %eax
jne 0x15365
cmpb $0x0, (%r14)
jne 0x15351
jmp 0x154e4
addq $0x4, %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq %r14, 0x8(%rsp)
movzbl (%r14), %eax
cmpl $0x4c, %eax
je 0x153df
cmpl $0x53, %eax
jne 0x1543e
cmpb $0x4e, 0x1(%r14)
jne 0x1543e
cmpb $0x3a, 0x2(%r14)
jne 0x1543e
addq $0x3, %r14
movq %r14, 0x8(%rsp)
xorl %r13d, %r13d
movzbl (%r14,%r13), %eax
cmpl $0xa, %eax
ja 0x153da
movl $0x601, %ecx            # imm = 0x601
btl %eax, %ecx
jb 0x1540d
incq %r13
jmp 0x153c6
cmpb $0x4e, 0x1(%r14)
jne 0x1543e
cmpb $0x3a, 0x2(%r14)
jne 0x1543e
addq $0x3, %r14
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x4760
movq %rax, %rbp
movq 0x8(%rsp), %r14
jmp 0x1543e
leaq 0x1(%r13), %rdi
movl $0x1, %esi
callq 0x4360
movq %rax, %r12
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x42b0
addq %r13, %r14
movq %r14, 0x8(%rsp)
leaq 0x14(%rsp), %r13
jmp 0x1543e
incq %r14
movzbl (%r14), %eax
testl %eax, %eax
je 0x1545f
cmpl $0x9, %eax
je 0x15452
cmpl $0xa, %eax
jne 0x1543b
jmp 0x1545f
movq %r14, 0x8(%rsp)
incq %r14
jmp 0x1538d
movq %r14, 0x8(%rsp)
testq %r12, %r12
je 0x15365
testl %ebp, %ebp
js 0x15365
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xe06f
cmpl $0x0, 0x14(%rsp)
je 0x154a7
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 0x15365
leaq 0x4d0a2(%rip), %rax     # 0x62550
cmpl $0x2, (%rax)
jge 0x154c0
movq %r12, %rdi
callq 0x4610
jmp 0x15365
movq 0x4cb01(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0x3bec2(%rip), %rsi     # 0x51393
leaq 0x3bedd(%rip), %rdx     # 0x513b5
movq %r12, %rcx
xorl %eax, %eax
callq 0x4770
jmp 0x154b3
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 0x1557b
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 0x15570
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 0x15535
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq