// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: sam_hdr_sanitise
static sam_hdr_t *sam_hdr_sanitise(sam_hdr_t *h) {
    if (!h)
        return NULL;

    // Special case for empty headers.
    if (h->l_text == 0)
        return h;

    size_t i;
    unsigned int lnum = 0;
    char *cp = h->text, last = '\n';
    for (i = 0; i < h->l_text; i++) {
        // NB: l_text excludes terminating nul.  This finds early ones.
        if (cp[i] == 0)
            break;

        // Error on \n[^@], including duplicate newlines
        if (last == '\n') {
            lnum++;
            if (cp[i] != '@') {
                hts_log_error("Malformed SAM header at line %u", lnum);
                sam_hdr_destroy(h);
                return NULL;
            }
        }

        last = cp[i];
    }

    if (i < h->l_text) { // Early nul found.  Complain if not just padding.
        size_t j = i;
        while (j < h->l_text && cp[j] == '\0') j++;
        if (j < h->l_text)
            hts_log_warning("Unexpected NUL character in header. Possibly truncated");
    }

    // Add trailing newline and/or trailing nul if required.
    if (last != '\n') {
        hts_log_warning("Missing trailing newline on SAM header. Possibly truncated");

        if (h->l_text < 2 || i >= h->l_text - 2) {
            if (h->l_text >= SIZE_MAX - 2) {
                hts_log_error("No room for extra newline");
                sam_hdr_destroy(h);
                return NULL;
            }

            cp = realloc(h->text, (size_t) h->l_text+2);
            if (!cp) {
                sam_hdr_destroy(h);
                return NULL;
            }
            h->text = cp;
        }
        cp[i++] = '\n';

        // l_text may be larger already due to multiple nul padding
        if (h->l_text < i)
            h->l_text = i;
        cp[h->l_text] = '\0';
    }

    return h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x379d0
movq $0x0, -0x8(%rbp)
jmp 0x37c30
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x379e8
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x37c30
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
movb $0xa, -0x29(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x37aa3
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x37a2c
jmp 0x37aa3
movsbl -0x29(%rbp), %eax
cmpl $0xa, %eax
jne 0x37a84
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x40, %eax
je 0x37a82
movl -0x1c(%rbp), %ecx
movl $0x1, %edi
leaq 0xbabd0(%rip), %rsi     # 0xf262e
leaq 0xbabda(%rip), %rdx     # 0xf263f
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rdi
callq 0x31e70
movq $0x0, -0x8(%rbp)
jmp 0x37c30
jmp 0x37a84
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x29(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x37a07
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x37b22
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rdx
xorl %eax, %eax
cmpq 0x8(%rdx), %rcx
movb %al, -0x39(%rbp)
jae 0x37ae1
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x37aea
jmp 0x37af8
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x37ab9
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x37b20
movl $0x3, %edi
leaq 0xbab1c(%rip), %rsi     # 0xf262e
leaq 0xbab46(%rip), %rdx     # 0xf265f
movb $0x0, %al
callq 0x1b030
jmp 0x37b22
movsbl -0x29(%rbp), %eax
cmpl $0xa, %eax
je 0x37c28
movl $0x3, %edi
leaq 0xbaaf3(%rip), %rsi     # 0xf262e
leaq 0xbab54(%rip), %rdx     # 0xf2696
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rax
cmpq $0x2, 0x8(%rax)
jb 0x37b69
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x2, %rcx
cmpq %rcx, %rax
jb 0x37be7
movq -0x10(%rbp), %rax
cmpq $-0x3, 0x8(%rax)
jb 0x37ba4
movl $0x1, %edi
leaq 0xbaaae(%rip), %rsi     # 0xf262e
leaq 0xbab4a(%rip), %rdx     # 0xf26d1
movb $0x0, %al
callq 0x1b030
movq -0x10(%rbp), %rdi
callq 0x31e70
movq $0x0, -0x8(%rbp)
jmp 0x37c30
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x2, %rsi
callq 0x4820
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x37bdb
movq -0x10(%rbp), %rdi
callq 0x31e70
movq $0x0, -0x8(%rbp)
jmp 0x37c30
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movb $0xa, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x18(%rbp), %rax
jae 0x37c18
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)