// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl $0x0, 0x40(%rsi)
movl 0x8(%rdi), %ecx
movslq 0x10(%rdi), %rax
subl %eax, %ecx
cmpl $0x5, %ecx
jl 0x23ba4
movq 0x28(%r14), %rcx
movl (%rcx,%rax), %ecx
movl %ecx, 0xc(%rsp)
addl $0x4, %eax
movl %eax, 0x10(%r14)
addq $0x4, 0x20(%r14)
movl $0x4, %eax
jmp 0x23bb6
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0xbf5d
testl %eax, %eax
je 0x23bde
cmpl $0x4, %eax
jne 0x23be5
testb $0x8, 0x2(%r14)
je 0x23bd0
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0xc(%rsp)
cmpl $0x20, 0xc(%rsp)
jge 0x23bf5
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
jmp 0x23bea
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x23bea
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r14), %ecx
movslq 0x10(%r14), %rax
subl %eax, %ecx
cmpl $0x21, %ecx
jl 0x23c14
movq %rax, %r15
addq 0x28(%r14), %r15
addl $0x20, %eax
movl %eax, 0x10(%r14)
jmp 0x23c37
leaq 0x10(%rsp), %r15
movl $0x20, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0xbf5d
movq %rax, %rcx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq $0x20, %rcx
jne 0x23bea
movl (%r15), %eax
movl %eax, 0x8(%rbx)
movslq 0x4(%r15), %rax
movq %rax, (%rbx)
movl 0x8(%r15), %edx
movl %edx, %eax
shrl $0x10, %eax
movw %ax, 0xc(%rbx)
movb %dh, 0xe(%rbx)
movzbl %dl, %eax
andl $0x3, %edx
movb $0x4, %cl
subb %dl, %cl
testl %edx, %edx
movzbl %cl, %ecx
cmovel %edx, %ecx
movw %ax, 0x12(%rbx)
movb %cl, 0xf(%rbx)
movl 0xc(%r15), %esi
movzwl %si, %edx
shrl $0x10, %esi
movw %si, 0x10(%rbx)
movl %edx, 0x14(%rbx)
movl 0x10(%r15), %esi
movl %esi, 0x18(%rbx)
movl 0x14(%r15), %edi
movl %edi, 0x1c(%rbx)
movslq 0x18(%r15), %rdi
movq %rdi, 0x20(%rbx)
movslq 0x1c(%r15), %rdi
movq %rdi, 0x28(%rbx)
leal -0x20(%rcx), %edi
movsbl %dil, %ebp
addl 0xc(%rsp), %ebp
js 0x23bd7
testl %esi, %esi
js 0x23bd7
testw %ax, %ax
je 0x23bd7
movzwl %ax, %eax
movzbl %cl, %ecx
addq %rax, %rcx
leaq 0x1(%rsi), %rax
shrq %rax
leaq (%rcx,%rdx,4), %rcx
addq %rsi, %rax
addq %rcx, %rax
movl %ebp, %esi
cmpq %rsi, %rax
ja 0x23bd7
cmpl %ebp, 0x44(%rbx)
jae 0x23cf8
movq %rbx, %rdi
callq 0x23476
testl %eax, %eax
js 0x23bd7
movl %ebp, 0x40(%rbx)
movq 0x38(%rbx), %rsi
movzwl 0x12(%rbx), %edx
movq %r14, %rdi
callq 0x23ee6
movzwl 0x12(%rbx), %ecx
cmpq %rcx, %rax
jne 0x23bd7
movq 0x38(%rbx), %rax
cmpb $0x0, -0x1(%rax,%rcx)
je 0x23d33
movq %rbx, %rdi
callq 0x23f37
testl %eax, %eax
js 0x23bd7
movb 0xf(%rbx), %al
testb %al, %al
je 0x23d53
xorl %ecx, %ecx
movzwl 0x12(%rbx), %eax
addq 0x38(%rbx), %rax
movb $0x0, (%rcx,%rax)
movzbl 0xf(%rbx), %eax
incq %rcx
cmpl %eax, %ecx
jb 0x23d3c
movzbl %al, %ecx
addw 0x12(%rbx), %cx
movw %cx, 0x12(%rbx)
movl 0x40(%rbx), %eax
movzwl %cx, %ecx
subl %ecx, %eax
jl 0x23bd7
movl %ecx, %esi
addq 0x38(%rbx), %rsi
movslq %eax, %rdx
movq %r14, %rdi
callq 0x23ee6
movslq 0x40(%rbx), %rdx
movzwl 0x12(%rbx), %ecx
subq %rcx, %rdx
cmpq %rdx, %rax
jne 0x23bd7
testb $0x8, 0x2(%r14)
je 0x23db7
cmpl $0x0, 0x14(%rbx)
je 0x23db7
addq 0x38(%rbx), %rcx
xorl %eax, %eax
movl (%rcx,%rax,4), %edx
bswapl %edx
movl %edx, (%rcx,%rax,4)
incq %rax
movl 0x14(%rbx), %edx
cmpq %rdx, %rax
jb 0x23da4
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x23fae
testl %eax, %eax
js 0x23bd7
movl 0x14(%rbx), %esi
testq %rsi, %rsi
je 0x23eda
movq 0x38(%rbx), %rax
xorl %edx, %edx
testl %esi, %esi
jle 0x23e32
movzwl 0x12(%rbx), %r8d
addq %rax, %r8
movl $0x3c1a7, %r9d          # imm = 0x3C1A7
xorl %edi, %edi
xorl %r10d, %r10d
movl (%r8,%r10,4), %r11d
leal (%r11,%r11), %ecx
movl $0x3c1a7, %r14d         # imm = 0x3C1A7
shrl %cl, %r14d
shrl $0x4, %r11d
btl %ecx, %r9d
movl $0x0, %ecx
sbbl %ecx, %ecx
andl %r11d, %ecx
addq %rcx, %rdi
shll $0x1e, %r14d
sarl $0x1f, %r14d
andl %r11d, %r14d
addq %r14, %rdx
incq %r10
cmpq %r10, %rsi
jne 0x23df4
jmp 0x23e34
xorl %edi, %edi
movzwl 0x10(%rbx), %r8d
testq %rdx, %rdx
movl $0x1, %ecx
cmoveq %rcx, %rdx
testb $0x4, %r8b
cmovneq %rcx, %rdx
movq (%rbx), %r10
leaq -0x1(%r10,%rdx), %r11
movl $0x1249, %r9d           # imm = 0x1249
movl $0xe, %edx
movl $0x6, %ebp
movl $0xc, %esi
movq %r10, %r14
movl %edx, %ecx
sarq %cl, %r14
movq %r11, %r15
sarq %cl, %r15
cmpq %r15, %r14
je 0x23e9e
addq $0x3, %rdx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %r14d
addl %r14d, %r9d
decl %ebp
addl $-0x3, %esi
cmpl $0x1, %ebp
ja 0x23e6a
xorl %r9d, %r9d
jmp 0x23ea1
addl %r14d, %r9d
movw %r9w, 0xc(%rbx)
testb $0x4, %r8b
jne 0x23eda
movl 0x18(%rbx), %ecx
testl %ecx, %ecx
jle 0x23eda
cmpq %rcx, %rdi
je 0x23eda
leaq 0x76924(%rip), %rsi     # 0x9a7e3
leaq 0x76927(%rip), %rdx     # 0x9a7ed
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x14378
jmp 0x23bd7
movl 0xc(%rsp), %eax
addl $0x4, %eax
jmp 0x23bea