// File: /workspace/github_cpp_makefile_star2_O2/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 0x11f54
cmpl $0x6, %eax
je 0x11f36
cmpl $0x4, %eax
jne 0x1208b
movq 0x38(%rbx), %rdi
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c7b
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 0x2ebf0
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 0xd37f
testl %eax, %eax
js 0x11fba
movq 0x20(%rbx), %rdi
cmpb $0x40, (%rdi)
jne 0x11fba
movq (%r14), %rsi
cmpq $0x4, %rsi
jb 0x11fa5
cmpb $0x53, 0x1(%rdi)
jne 0x11fa5
cmpb $0x51, 0x2(%rdi)
pushq $0x1
popq %rax
cmovel %eax, %r13d
movq %r15, %rdx
callq 0x12090
movl %r12d, %edi
movq %r15, %rsi
callq 0x120dc
jmp 0x11f71
testl %r13d, %r13d
je 0x12002
cmpq $0x0, (%rsp)
jne 0x11fd7
leaq 0x31c1f(%rip), %rdi     # 0x43bec
movq %rsp, %rdx
xorl %esi, %esi
callq 0x12090
movq 0x10(%rsp), %rsi
callq 0x11ca0
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 0x11fbf
leaq 0x328a3(%rip), %rsi     # 0x448b5
callq 0x45f0
testq %rax, %rax
je 0x12084
movq %rax, %rbx
leaq 0x20(%rsp), %r14
leaq 0x3463d(%rip), %r15     # 0x46668
leaq 0x322f1(%rip), %r12     # 0x44323
movq %rsp, %r13
movq %r14, %rdi
movl $0x800, %esi            # imm = 0x800
movq %rbx, %rdx
callq 0x4850
testq %rax, %rax
je 0x12077
movq %r14, %rdi
movq %r15, %rsi
callq 0x4840
movq %rax, %rbp
xorl %edi, %edi
movq %r15, %rsi
callq 0x4840
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x35818
jmp 0x12035
movq %rbx, %rdi
callq 0x4530
jmp 0x11fbf
xorl %eax, %eax
jmp 0x11ff0
callq 0x42f0