// File: /workspace/github_c_makefile_star2_O3/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 $0x838, %rsp            # imm = 0x838
movq %rdi, %rbx
movl 0x44(%rdi), %eax
cmpl $0x3, %eax
je 0x6e15a
cmpl $0x6, %eax
je 0x6e13c
cmpl $0x4, %eax
jne 0x6e40e
movq 0x38(%rbx), %rdi
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6cdb3
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rdi
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x867b8
leaq 0x10(%rbx), %rbp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
movq %rbp, %rdx
callq 0x4e97b
testl %eax, %eax
js 0x6e2f0
movq $0x0, 0x20(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbp, 0x28(%rsp)
movq 0x20(%rbx), %r13
cmpb $0x40, (%r13)
jne 0x6e2f5
movq (%rbp), %rax
cmpq $0x4, %rax
jb 0x6e1d4
cmpb $0x53, 0x1(%r13)
jne 0x6e1d4
cmpb $0x51, 0x2(%r13)
movq 0x20(%rsp), %rcx
movl $0x1, %edx
cmovel %edx, %ecx
movq %rcx, 0x20(%rsp)
movslq %eax, %rbp
leaq (%r14,%rbp), %rax
incq %rax
cmpq %r12, %rax
jb 0x6e234
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, %r12
shrq $0x10, %r12
orq %rax, %r12
incq %r12
movq %r12, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x6c80
testq %rax, %rax
je 0x6e258
movq %rax, %r15
movq %rax, 0x10(%rsp)
leaq (%r15,%r14), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x6570
addq %rbp, %r14
movq %r14, (%rsp)
movb $0x0, (%r15,%r14)
movq (%rsp), %r14
movq 0x8(%rsp), %r12
leaq 0x1(%r14), %r13
cmpq %r12, %r13
movq 0x28(%rsp), %rbp
jae 0x6e26d
movq 0x10(%rsp), %r15
jmp 0x6e2c3
movq %r13, %rax
shrq %rax
orq %r13, %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, %r12
shrq $0x10, %r12
orq %rcx, %r12
incq %r12
movq %r12, 0x8(%rsp)
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x6c80
testq %rax, %rax
je 0x6e2eb
movq %rax, 0x10(%rsp)
movq %rax, %r15
movq %r13, (%rsp)
movw $0xa, (%r15,%r14)
movq %r13, %r14
movq %rbx, %rdi
movl $0x2, %esi
movq %rbp, %rdx
callq 0x4e97b
testl %eax, %eax
jns 0x6e19d
jmp 0x6e2f8
movq %r14, %r13
jmp 0x6e2d1
xorl %r13d, %r13d
jmp 0x6e303
movq %r14, %r13
cmpl $0x0, 0x20(%rsp)
jne 0x6e3a1
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x6e3a1
leaq 0x27bf2(%rip), %rsi     # 0x95f09
callq 0x6880
testq %rax, %rax
je 0x6e40a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0x6c00
testq %rax, %rax
je 0x6e395
leaq 0x2b6c3(%rip), %r14     # 0x99a09
leaq 0x30(%rsp), %r15
leaq 0x2c361(%rip), %r12     # 0x9a6b3
movq %rsp, %r13
movq %r15, %rdi
movq %r14, %rsi
callq 0x6be0
movq %rax, %rbp
xorl %edi, %edi
movq %r14, %rsi
callq 0x6be0
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6629a
movq %r15, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x6c00
testq %rax, %rax
jne 0x6e355
movq %rbx, %rdi
callq 0x66e0
movq (%rsp), %r13
testq %r13, %r13
jne 0x6e3df
movq 0x10(%rsp), %rax
cmpq $0x1, 0x8(%rsp)
jbe 0x6e3b7
xorl %ecx, %ecx
jmp 0x6e3db
movq $0x2, 0x8(%rsp)
movl $0x2, %esi
movq %rax, %rdi
callq 0x6c80
testq %rax, %rax
je 0x6e3df
movq (%rsp), %rcx
movq %rax, 0x10(%rsp)
movb $0x0, (%rax,%rcx)
movq 0x10(%rsp), %rsi
callq 0x6de8d
movl (%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
addq $0x838, %rsp            # imm = 0x838
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x6e3f8
callq 0x63c0