// File: /workspace/github_cpp_makefile_star2_O1/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 $0x828, %rsp            # imm = 0x828
movq %rdi, %rbx
movl 0x44(%rdi), %eax
cmpl $0x3, %eax
je 0x15670
cmpl $0x6, %eax
je 0x15652
cmpl $0x4, %eax
jne 0x1592d
movq 0x38(%rbx), %rdi
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x141da
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rdi
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a4e1
leaq 0x10(%rbx), %r14
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0xffc2
testl %eax, %eax
js 0x15821
xorl %r15d, %r15d
movq 0x20(%rbx), %r12
cmpb $0x40, (%r12)
jne 0x15818
movq (%r14), %r13
cmpq $0x4, %r13
jb 0x156d6
movl $0x3, %edx
movq %r12, %rdi
leaq 0x3dcd1(%rip), %rsi     # 0x53397
callq 0x4280
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r15d
movslq %r13d, %r13
movq (%rsp), %rax
leaq (%rax,%r13), %rcx
addq $0x2, %rcx
cmpq %rcx, 0x8(%rsp)
jae 0x1574c
addq %r13, %rax
incq %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, %rbp
shrq $0x20, %rbp
orq %rcx, %rbp
incq %rbp
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x48d0
testq %rax, %rax
je 0x15772
movq %rax, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
movq 0x10(%rsp), %rdi
addq (%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4420
addq (%rsp), %r13
movq %r13, (%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax,%r13)
movq (%rsp), %rax
leaq 0x2(%rax), %rcx
cmpq %rcx, 0x8(%rsp)
jae 0x157de
incq %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, %r12
shrq $0x20, %r12
orq %rcx, %r12
incq %r12
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x48d0
testq %rax, %rax
je 0x15800
movq %rax, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rsp)
movb $0xa, (%rcx,%rax)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0xffc2
testl %eax, %eax
jns 0x1569f
testl %r15d, %r15d
jne 0x158c0
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x158c0
leaq 0x3e0e4(%rip), %rsi     # 0x53919
callq 0x4600
testq %rax, %rax
je 0x15919
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0x4860
testq %rax, %rax
je 0x158b3
leaq 0x3fde4(%rip), %r14     # 0x55648
leaq 0x20(%rsp), %r15
leaq 0x3db2b(%rip), %r12     # 0x5339b
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 0x42f92
movq %r15, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x4860
testq %rax, %rax
jne 0x15873
movq %rbx, %rdi
callq 0x4530
testq %rbx, %rbx
je 0x15919
cmpq $0x0, (%rsp)
jne 0x158fe
cmpq $0x1, 0x8(%rsp)
ja 0x158f1
movq 0x10(%rsp), %rdi
movl $0x2, %esi
callq 0x48d0
testq %rax, %rax
je 0x158fe
movq %rax, 0x10(%rsp)
movq $0x2, 0x8(%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x10(%rsp), %rsi
callq 0x15392
movl (%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
jmp 0x1591b
xorl %eax, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x42e0