// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam.c
// Function: bam_read1
int bam_read1(BGZF *fp, bam1_t *b)
{
    bam1_core_t *c = &b->core;
    int32_t block_len, ret, i;
    uint32_t new_l_data;
    uint8_t tmp[32], *x;

    b->l_data = 0;

    if ((ret = bgzf_read_small(fp, &block_len, 4)) != 4) {
        if (ret == 0) return -1; // normal end-of-file
        else return -2; // truncated
    }
    if (fp->is_be)
        ed_swap_4p(&block_len);
    if (block_len < 32) return -4;  // block_len includes core data
    if (fp->block_length - fp->block_offset > 32) {
        // Avoid bgzf_read and a temporary copy to a local buffer
        x = (uint8_t *)fp->uncompressed_block + fp->block_offset;
        fp->block_offset += 32;
    } else {
        x = tmp;
        if (bgzf_read(fp, x, 32) != 32) return -3;
    }

    c->tid        = le_to_u32(x);
    c->pos        = le_to_i32(x+4);
    uint32_t x2   = le_to_u32(x+8);
    c->bin        = x2>>16;
    c->qual       = x2>>8&0xff;
    c->l_qname    = x2&0xff;
    c->l_extranul = (c->l_qname%4 != 0)? (4 - c->l_qname%4) : 0;
    uint32_t x3   = le_to_u32(x+12);
    c->flag       = x3>>16;
    c->n_cigar    = x3&0xffff;
    c->l_qseq     = le_to_u32(x+16);
    c->mtid       = le_to_u32(x+20);
    c->mpos       = le_to_i32(x+24);
    c->isize      = le_to_i32(x+28);

    new_l_data = block_len - 32 + c->l_extranul;
    if (new_l_data > INT_MAX || c->l_qseq < 0 || c->l_qname < 1) return -4;
    if (((uint64_t) c->n_cigar << 2) + c->l_qname + c->l_extranul
        + (((uint64_t) c->l_qseq + 1) >> 1) + c->l_qseq > (uint64_t) new_l_data)
        return -4;
    if (realloc_bam_data(b, new_l_data) < 0) return -4;
    b->l_data = new_l_data;

    if (bgzf_read_small(fp, b->data, c->l_qname) != c->l_qname) return -4;
    if (b->data[c->l_qname - 1] != '\0') { // try to fix missing nul termination
        if (fixup_missing_qname_nul(b) < 0) return -4;
    }
    for (i = 0; i < c->l_extranul; ++i) b->data[c->l_qname+i] = '\0';
    c->l_qname += c->l_extranul;
    if (b->l_data < c->l_qname ||
        bgzf_read_small(fp, b->data + c->l_qname, b->l_data - c->l_qname) != b->l_data - c->l_qname)
        return -4;
    if (fp->is_be) swap_data(c, b->l_data, b->data, 0);
    if (bam_tag2cigar(b, 0, 0) < 0)
        return -4;

    // TODO: consider making this conditional
    if (c->n_cigar > 0) { // recompute "bin" and check CIGAR-qlen consistency
        hts_pos_t rlen, qlen;
        bam_cigar2rqlens(c->n_cigar, bam_get_cigar(b), &rlen, &qlen);
        if ((b->core.flag & BAM_FUNMAP) || rlen == 0) rlen = 1;
        b->core.bin = hts_reg2bin(b->core.pos, b->core.pos + rlen, 14, 5);
        // Sanity check for broken CIGAR alignments
        if (c->l_qseq > 0 && !(c->flag & BAM_FUNMAP) && qlen != c->l_qseq) {
            hts_log_error("CIGAR and query sequence lengths differ for %s",
                    bam_get_qname(b));
            return -4;
        }
    }

    return 4 + block_len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbp
movq %rdi, %r14
andl $0x0, 0x40(%rsi)
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x1e849
testl %eax, %eax
je 0x1e5aa
cmpl $0x4, %eax
jne 0x1e5ae
testb $0x8, 0x2(%r14)
movl 0xc(%rsp), %eax
je 0x1e582
bswapl %eax
movl %eax, 0xc(%rsp)
pushq $-0x4
popq %r13
cmpl $0x20, %eax
jl 0x1e5b2
movl 0x8(%r14), %edx
movslq 0x10(%r14), %rcx
subl %ecx, %edx
cmpl $0x21, %edx
jl 0x1e5c4
movq %rcx, %r15
addq 0x28(%r14), %r15
addl $0x20, %ecx
movl %ecx, 0x10(%r14)
jmp 0x1e5e5
pushq $-0x1
jmp 0x1e5b0
pushq $-0x2
popq %r13
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %r15
pushq $0x20
popq %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0xab95
cmpq $0x20, %rax
jne 0x1e707
movl 0xc(%rsp), %eax
movl (%r15), %ecx
movl %ecx, 0x8(%rbp)
movslq 0x4(%r15), %rcx
movq %rcx, (%rbp)
movl 0x8(%r15), %ebx
movl %ebx, %ecx
shrl $0x10, %ecx
movw %cx, 0xc(%rbp)
movb %bh, 0xe(%rbp)
movzbl %bl, %ecx
movw %cx, 0x12(%rbp)
andl $0x3, %ebx
movb $0x4, %dl
subb %bl, %dl
testl %ebx, %ebx
movzbl %dl, %edx
cmovel %ebx, %edx
movb %dl, 0xf(%rbp)
movl 0xc(%r15), %edi
movzwl %di, %esi
shrl $0x10, %edi
movw %di, 0x10(%rbp)
movl %esi, 0x14(%rbp)
movl 0x10(%r15), %edi
movl %edi, 0x18(%rbp)
movl 0x14(%r15), %r8d
movl %r8d, 0x1c(%rbp)
movslq 0x18(%r15), %r8
movq %r8, 0x20(%rbp)
movslq 0x1c(%r15), %r8
movq %r8, 0x28(%rbp)
leal -0x20(%rdx), %r8d
movsbl %r8b, %r15d
addl %eax, %r15d
js 0x1e5b2
testl %edi, %edi
js 0x1e5b2
testw %cx, %cx
je 0x1e5b2
movzwl %cx, %eax
movzbl %dl, %ecx
addq %rax, %rcx
leaq 0x1(%rdi), %rax
shrq %rax
leaq (%rcx,%rsi,4), %rcx
addq %rdi, %rax
addq %rcx, %rax
movl %r15d, %esi
cmpq %rsi, %rax
ja 0x1e5b2
movq %rbp, %rdi
callq 0x1e02a
testl %eax, %eax
js 0x1e5b2
movl %r15d, 0x40(%rbp)
movq 0x38(%rbp), %rsi
movzwl 0x12(%rbp), %edx
movq %r14, %rdi
callq 0x1e849
movzwl 0x12(%rbp), %ecx
cmpq %rcx, %rax
jne 0x1e5b2
movq 0x38(%rbp), %rdx
cmpb $0x0, -0x1(%rdx,%rax)
je 0x1e6ec
cmpb $0x0, 0xf(%rbp)
je 0x1e7f8
incl %ecx
movw %cx, 0x12(%rbp)
movb $0x0, (%rdx,%rax)
movb 0xf(%rbp), %al
decb %al
movb %al, 0xf(%rbp)
xorl %eax, %eax
movzbl 0xf(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1e70e
movzwl 0x12(%rbp), %ecx
addq 0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
incq %rax
jmp 0x1e6ee
pushq $-0x3
jmp 0x1e5b0
addw 0x12(%rbp), %cx
movw %cx, 0x12(%rbp)
movl 0x40(%rbp), %eax
movzwl %cx, %ecx
subl %ecx, %eax
jl 0x1e5b2
movl %ecx, %esi
addq 0x38(%rbp), %rsi
movslq %eax, %rdx
movq %r14, %rdi
callq 0x1e849
movslq 0x40(%rbp), %rcx
movzwl 0x12(%rbp), %edx
subq %rdx, %rcx
cmpq %rcx, %rax
jne 0x1e5b2
testb $0x8, 0x2(%r14)
je 0x1e75c
movq 0x38(%rbp), %rsi
movq %rbp, %rdi
callq 0x1e89a
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1e8b9
testl %eax, %eax
js 0x1e5b2
movl 0x14(%rbp), %edi
testl %edi, %edi
je 0x1e83b
movq 0x38(%rbp), %r14
movzwl 0x12(%rbp), %esi
addq %r14, %rsi
leaq 0x18(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdx
callq 0x1e412
movzwl 0x10(%rbp), %r12d
movq (%r15), %rsi
testq %rsi, %rsi
pushq $0x1
popq %rax
cmoveq %rax, %rsi
testb $0x4, %r12b
cmovneq %rax, %rsi
movq (%rbp), %rdi
addq %rdi, %rsi
callq 0x1e461
movw %ax, 0xc(%rbp)
movslq 0x18(%rbp), %rax
testq %rax, %rax
jle 0x1e83b
testb $0x4, %r12b
jne 0x1e83b
cmpq %rax, 0x10(%rsp)
je 0x1e83b
leaq 0x5af64(%rip), %rsi     # 0x79743
leaq 0x5af67(%rip), %rdx     # 0x7974d
pushq $0x1
popq %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x110c6
jmp 0x1e5b2
movslq 0x40(%rbp), %rsi
cmpq $0x7ffffffb, %rsi       # imm = 0x7FFFFFFB
jg 0x1e5b2
addq $0x4, %rsi
movq %rbp, %rdi
callq 0x1e02a
testl %eax, %eax
js 0x1e5b2
addl $0x4, 0x40(%rbp)
movq 0x38(%rbp), %rax
movzwl 0x12(%rbp), %ecx
leal 0x1(%rcx), %edx
movw %dx, 0x12(%rbp)
movb $0x0, (%rax,%rcx)
movb $0x3, %al
jmp 0x1e6e9
movl 0xc(%rsp), %r13d
addl $0x4, %r13d
jmp 0x1e5b2