// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/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 0x62638
cmpl $0x6, %eax
je 0x6261a
cmpl $0x4, %eax
jne 0x6276f
movq 0x38(%rbx), %rdi
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x613c3
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 0x757ed
leaq 0x10(%rbx), %r14
xorps %xmm0, %xmm0
movq %rsp, %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
xorl %r13d, %r13d
pushq $0x2
popq %rbp
pushq $0xa
popq %r12
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x47a0a
testl %eax, %eax
js 0x6269e
movq 0x20(%rbx), %rdi
cmpb $0x40, (%rdi)
jne 0x6269e
movq (%r14), %rsi
cmpq $0x4, %rsi
jb 0x62689
cmpb $0x53, 0x1(%rdi)
jne 0x62689
cmpb $0x51, 0x2(%rdi)
pushq $0x1
popq %rax
cmovel %eax, %r13d
movq %r15, %rdx
callq 0x62774
movl %r12d, %edi
movq %r15, %rsi
callq 0x62808
jmp 0x62655
testl %r13d, %r13d
je 0x626e6
cmpq $0x0, (%rsp)
jne 0x626bb
leaq 0x24ccc(%rip), %rdi     # 0x8737d
movq %rsp, %rdx
xorl %esi, %esi
callq 0x62774
movq 0x10(%rsp), %rsi
callq 0x62384
movl (%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x626a3
leaq 0x22713(%rip), %rsi     # 0x84e09
callq 0x6880
testq %rax, %rax
je 0x62768
movq %rax, %rbx
leaq 0x20(%rsp), %r14
leaq 0x26089(%rip), %r15     # 0x88798
leaq 0x26c3d(%rip), %r12     # 0x89353
movq %rsp, %r13
movq %r14, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x6c00
testq %rax, %rax
je 0x6275b
movq %r14, %rdi
movq %r15, %rsi
callq 0x6be0
movq %rax, %rbp
xorl %edi, %edi
movq %r15, %rsi
callq 0x6be0
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x5b5f6
jmp 0x62719
movq %rbx, %rdi
callq 0x66e0
jmp 0x626a3
xorl %eax, %eax
jmp 0x626d4
callq 0x63c0