// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/sam.c
// Function: sam_hdr_read
bam_hdr_t *sam_hdr_read(htsFile *fp)
{
    switch (fp->format.format) {
    case bam:
        return bam_hdr_read(fp->fp.bgzf);

    case cram:
        return cram_header_to_bam(fp->fp.cram->header);

    case sam: {
        kstring_t str;
        bam_hdr_t *h;
        int has_SQ = 0;
        str.l = str.m = 0; str.s = 0;
        while (hts_getline(fp, KS_SEP_LINE, &fp->line) >= 0) {
            if (fp->line.s[0] != '@') break;
            if (fp->line.l > 3 && strncmp(fp->line.s,"@SQ",3) == 0) has_SQ = 1;
            kputsn(fp->line.s, fp->line.l, &str);
            kputc('\n', &str);
        }
        if (! has_SQ && fp->fn_aux) {
            char line[2048];
            FILE *f = fopen(fp->fn_aux, "r");
            if (f == NULL) return NULL;
            while (fgets(line, sizeof line, f)) {
                const char *name = strtok(line, "\t");
                const char *length = strtok(NULL, "\t");
                ksprintf(&str, "@SQ\tSN:%s\tLN:%s\n", name, length);
            }
            fclose(f);
        }
        if (str.l == 0) kputsn("", 0, &str);
        h = sam_hdr_parse(str.l, str.s);
        h->l_text = str.l; h->text = str.s;
        return h;
        }

    default:
        abort();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movq %rdi, %r14
movl 0x44(%rdi), %eax
cmpl $0x3, %eax
je 0x155ef
cmpl $0x6, %eax
je 0x155d1
cmpl $0x4, %eax
jne 0x158e8
movq 0x38(%r14), %rdi
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x141e3
movq 0x38(%r14), %rax
movq 0x18(%rax), %rdi
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39853
leaq 0x10(%r14), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rdx
callq 0xff2b
testl %eax, %eax
js 0x157da
movq $0x0, 0x20(%rsp)
xorl %esi, %esi
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbx, 0x38(%rsp)
movq %r14, 0x28(%rsp)
movq 0x20(%r14), %r13
cmpb $0x40, (%r13)
jne 0x157cd
movq (%rbx), %rax
cmpq $0x4, %rax
jb 0x1566c
cmpb $0x53, 0x1(%r13)
jne 0x1566c
cmpb $0x51, 0x2(%r13)
movq 0x20(%rsp), %rcx
movl $0x1, %edx
cmovel %edx, %ecx
movq %rcx, 0x20(%rsp)
movslq %eax, %rbp
leaq (%r15,%rbp), %rbx
leaq (%r15,%rbp), %rax
addq $0x2, %rax
cmpq %rax, %rsi
jae 0x156ed
movq %rsi, 0x30(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %r14
shrq $0x20, %r14
orq %rcx, %r14
incq %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x48d0
testq %rax, %rax
je 0x157be
movq %rax, %r12
movq %rax, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq 0x28(%rsp), %r14
addq %r12, %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x4420
movq %rbx, (%rsp)
movb $0x0, (%r12,%rbx)
movq (%rsp), %r15
movq 0x8(%rsp), %rbp
leaq 0x2(%r15), %rax
cmpq %rax, %rbp
jae 0x15782
leaq 0x1(%r15), %rbx
movq %rbx, %rax
shrq %rax
orq %rbx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
movq %rax, %r13
shrq $0x20, %r13
orq %rax, %r13
incq %r13
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x48d0
testq %rax, %rax
je 0x1579c
movq %rax, 0x10(%rsp)
movq %r13, 0x8(%rsp)
movq %r13, %rbp
movq %rax, %r12
jmp 0x1578b
movq 0x10(%rsp), %r12
leaq 0x1(%r15), %rbx
movq %rbx, (%rsp)
movb $0xa, (%r12,%r15)
movb $0x0, (%r12,%rbx)
movq %rbx, %r15
movq %r14, %rdi
movl $0x2, %esi
movq 0x38(%rsp), %rbx
movq %rbx, %rdx
callq 0xff2b
testl %eax, %eax
movq %rbp, %rsi
jns 0x15636
jmp 0x157cd
movq 0x28(%rsp), %r14
movq 0x30(%rsp), %rbp
jmp 0x15710
cmpl $0x0, 0x20(%rsp)
jne 0x1587b
jmp 0x157dd
xorl %r15d, %r15d
movq 0x30(%r14), %rdi
testq %rdi, %rdi
je 0x1587b
leaq 0x3c150(%rip), %rsi     # 0x51941
callq 0x4600
testq %rax, %rax
je 0x158e4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0x4860
testq %rax, %rax
je 0x1586f
leaq 0x3e0e9(%rip), %r14     # 0x53909
leaq 0x40(%rsp), %r15
leaq 0x3bb97(%rip), %r12     # 0x513c3
movq %rsp, %r13
movq %r15, %rdi
movq %r14, %rsi
callq 0x4850
movq %rax, %rbp
xorl %edi, %edi
movq %r14, %rsi
callq 0x4850
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x41f38
movq %r15, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x4860
testq %rax, %rax
jne 0x1582f
movq %rbx, %rdi
callq 0x4530
movq (%rsp), %r15
testq %r15, %r15
jne 0x158b9
movq 0x10(%rsp), %rax
cmpq $0x1, 0x8(%rsp)
ja 0x158b3
movl $0x2, %esi
movq %rax, %rdi
callq 0x48d0
testq %rax, %rax
je 0x158b9
movq (%rsp), %rcx
movq %rax, 0x10(%rsp)
movq $0x2, 0x8(%rsp)
jmp 0x158b5
xorl %ecx, %ecx
movb $0x0, (%rax,%rcx)
movq 0x10(%rsp), %rsi
callq 0x15322
movl (%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x158d2
callq 0x42e0