// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x111a0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1ce85
movq -0x28(%rbp), %rdi
leaq 0x5e138(%rip), %rsi     # 0x7ad40
movl $0x4, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x1ce38
movq $0x0, -0x38(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x5e831(%rip), %rsi     # 0x7b472
movl $0x3, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x1ccf2
movq -0x18(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x45(%rbp)
je 0x1cc9a
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x45(%rbp)
je 0x1cc9a
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x1cca3
jmp 0x1ccb3
jmp 0x1cca5
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1cc68
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
subq %rax, %rdi
addq $0x1, %rdi
movl $0x1, %esi
callq 0x4370
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rax
subq %rax, %rdx
callq 0x42c0
movq -0x20(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x1cd27
movq -0x18(%rbp), %rdi
leaq 0x5e77a(%rip), %rsi     # 0x7b477
movl $0x3, %edx
callq 0x4290
cmpl $0x0, %eax
jne 0x1cd25
movq -0x18(%rbp), %rdi
addq $0x3, %rdi
leaq -0x18(%rbp), %rsi
movl $0xa, %edx
callq 0x4820
movl %eax, -0x3c(%rbp)
jmp 0x1cd27
jmp 0x1cd29
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x46(%rbp)
je 0x1cd5b
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x46(%rbp)
je 0x1cd5b
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x46(%rbp)
movb -0x46(%rbp), %al
testb $0x1, %al
jne 0x1cd64
jmp 0x1cd72
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x1cd29
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1cd8a
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x1cd8c
jmp 0x1cd9f
jmp 0x1cd8e
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x1cc36
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1ce36
cmpl $0x0, -0x3c(%rbp)
jl 0x1ce36
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x11900
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x1ce0c
leaq 0x6d807(%rip), %rax     # 0x8a5e0
cmpl $0x2, (%rax)
jl 0x1ce01
movq 0x6d1eb(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x38(%rbp), %rcx
leaq 0x5e636(%rip), %rsi     # 0x7b429
leaq 0x5e651(%rip), %rdx     # 0x7b44b
movb $0x0, %al
callq 0x4830
movq -0x38(%rbp), %rdi
callq 0x46a0
jmp 0x1ce34
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x20, %rdx
movslq -0x3c(%rbp), %rax
orq %rax, %rdx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x40(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x1ce36
jmp 0x1ce38
jmp 0x1ce3a
movq -0x28(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x47(%rbp)
je 0x1ce5b
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x47(%rbp)
movb -0x47(%rbp), %al
testb $0x1, %al
jne 0x1ce64
jmp 0x1ce72
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1ce3a
jmp 0x1ce74
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1cbf0
movq -0x30(%rbp), %rdi
callq 0x1cea0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)