// File: /workspace/github_c_makefile_star2_O1/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 0x6e22d
cmpl $0x6, %eax
je 0x6e20f
cmpl $0x4, %eax
jne 0x6e4c3
movq 0x38(%rbx), %rdi
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6cdfe
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 0x86c12
leaq 0x10(%rbx), %r14
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0x4e761
testl %eax, %eax
js 0x6e3b7
xorl %ebp, %ebp
movl $0x1, %r15d
movq 0x20(%rbx), %r12
cmpb $0x40, (%r12)
jne 0x6e3af
movq (%r14), %r13
cmpq $0x4, %r13
jb 0x6e293
movl $0x3, %edx
movq %r12, %rdi
leaq 0x2c1ff(%rip), %rsi     # 0x9a487
callq 0x6330
testl %eax, %eax
cmovel %r15d, %ebp
movq (%rsp), %rax
movslq %r13d, %r13
addq %r13, %rax
incq %rax
cmpq 0x8(%rsp), %rax
jb 0x6e2f4
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rsp), %rdi
callq 0x6c80
testq %rax, %rax
je 0x6e31a
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
addq (%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x6570
addq (%rsp), %r13
movq %r13, (%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax,%r13)
movq (%rsp), %rax
incq %rax
cmpq 0x8(%rsp), %rax
jb 0x6e375
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x8(%rsp)
movq 0x10(%rsp), %rdi
callq 0x6c80
testq %rax, %rax
je 0x6e397
movq %rax, 0x10(%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 0x4e761
testl %eax, %eax
jns 0x6e261
testl %ebp, %ebp
jne 0x6e456
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0x6e456
leaq 0x27a5e(%rip), %rsi     # 0x95e29
callq 0x6880
testq %rax, %rax
je 0x6e4af
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
movl $0x800, %esi            # imm = 0x800
movq %rax, %rdx
callq 0x6c00
testq %rax, %rax
je 0x6e449
leaq 0x2b3e6(%rip), %r14     # 0x997e0
leaq 0x20(%rsp), %r15
leaq 0x2c085(%rip), %r12     # 0x9a48b
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 0x662d8
movq %r15, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x6c00
testq %rax, %rax
jne 0x6e409
movq %rbx, %rdi
callq 0x66e0
testq %rbx, %rbx
je 0x6e4af
cmpq $0x0, (%rsp)
jne 0x6e494
cmpq $0x1, 0x8(%rsp)
ja 0x6e487
movq $0x2, 0x8(%rsp)
movq 0x10(%rsp), %rdi
movl $0x2, %esi
callq 0x6c80
testq %rax, %rax
je 0x6e494
movq %rax, 0x10(%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq 0x10(%rsp), %rsi
callq 0x6df4f
movl (%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rax)
jmp 0x6e4b1
xorl %eax, %eax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x63c0