// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x860, %rsp            # imm = 0x860
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x85c(%rbp)
subl $0x3, %eax
je 0xa78b0
jmp 0xa7863
movl -0x85c(%rbp), %eax
subl $0x4, %eax
je 0xa7880
jmp 0xa7870
movl -0x85c(%rbp), %eax
subl $0x6, %eax
je 0xa7896
jmp 0xa7a73
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xa55d0
movq %rax, -0x8(%rbp)
jmp 0xa7a78
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rdi
callq 0xcb2b0
movq %rax, -0x8(%rbp)
jmp 0xa7a78
movl $0x0, -0x34(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x10, %rdx
movl $0x2, %esi
callq 0x728d0
cmpl $0x0, %eax
jl 0xa795a
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
je 0xa78fc
jmp 0xa795a
movq -0x10(%rbp), %rax
cmpq $0x3, 0x10(%rax)
jbe 0xa792c
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x3cb03(%rip), %rsi     # 0xe4419
movl $0x3, %edx
callq 0x6320
cmpl $0x0, %eax
jne 0xa792c
movl $0x1, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %esi
leaq -0x28(%rbp), %rdx
callq 0xa7a90
movl $0xa, %edi
leaq -0x28(%rbp), %rsi
callq 0xa7c00
jmp 0xa78cf
cmpl $0x0, -0x34(%rbp)
jne 0xa7a24
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0xa7a24
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
leaq 0x38414(%rip), %rsi     # 0xdfd96
callq 0x6860
movq %rax, -0x848(%rbp)
cmpq $0x0, -0x848(%rbp)
jne 0xa79a5
movq $0x0, -0x8(%rbp)
jmp 0xa7a78
jmp 0xa79a7
leaq -0x840(%rbp), %rdi
movq -0x848(%rbp), %rdx
movl $0x800, %esi            # imm = 0x800
callq 0x6c00
cmpq $0x0, %rax
je 0xa7a18
leaq -0x840(%rbp), %rdi
leaq 0x3da1a(%rip), %rsi     # 0xe53ed
callq 0x6be0
movq %rax, -0x850(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x3da03(%rip), %rsi     # 0xe53ed
callq 0x6be0
movq %rax, -0x858(%rbp)
movq -0x850(%rbp), %rdx
movq -0x858(%rbp), %rcx
leaq -0x28(%rbp), %rdi
leaq 0x3ca0e(%rip), %rsi     # 0xe441d
movb $0x0, %al
callq 0x9a250
jmp 0xa79a7
movq -0x848(%rbp), %rdi
callq 0x66e0
cmpq $0x0, -0x28(%rbp)
jne 0xa7a3d
leaq 0x3d9d4(%rip), %rdi     # 0xe5406
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
callq 0xa7a90
movq -0x28(%rbp), %rax
movl %eax, %edi
movq -0x18(%rbp), %rsi
callq 0xa7430
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xa7a78
callq 0x63b0
movq -0x8(%rbp), %rax
addq $0x860, %rsp            # imm = 0x860
popq %rbp
retq
nopw %cs:(%rax,%rax)