// File: /workspace/github_c_makefile_star2_O3/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 0x23199
movq 0x28(%r14), %rcx
movl (%rcx,%rax), %ecx
movl %ecx, 0xc(%rsp)
addl $0x4, %eax
movl %eax, 0x10(%r14)
addq $0x4, 0x20(%r14)
jmp 0x231b8
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0xbefc
testl %eax, %eax
je 0x231f7
cmpl $0x4, %eax
jne 0x2334d
testb $0x8, 0x2(%r14)
movl 0xc(%rsp), %eax
je 0x231c9
bswapl %eax
movl %eax, 0xc(%rsp)
cmpl $0x20, %eax
jge 0x231d8
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
jmp 0x23352
movl 0x8(%r14), %edx
movslq 0x10(%r14), %rcx
subl %ecx, %edx
cmpl $0x21, %edx
jl 0x23201
movq %rcx, %r15
addq 0x28(%r14), %r15
addl $0x20, %ecx
movl %ecx, 0x10(%r14)
jmp 0x2322c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x23352
leaq 0x10(%rsp), %r15
movl $0x20, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0xbefc
movq %rax, %rcx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq $0x20, %rcx
jne 0x23352
movl 0xc(%rsp), %eax
movl (%r15), %ecx
movl %ecx, 0x8(%rbx)
movslq 0x4(%r15), %rcx
movq %rcx, (%rbx)
movl 0x8(%r15), %edx
movl %edx, %ecx
shrl $0x10, %ecx
movw %cx, 0xc(%rbx)
movb %dh, 0xe(%rbx)
movzbl %dl, %ecx
movw %cx, 0x12(%rbx)
andl $0x3, %edx
movb $0x4, %sil
subb %dl, %sil
testl %edx, %edx
movzbl %sil, %esi
cmovel %edx, %esi
movb %sil, 0xf(%rbx)
movl 0xc(%r15), %edx
movzwl %dx, %edi
shrl $0x10, %edx
movw %dx, 0x10(%rbx)
movl %edi, 0x14(%rbx)
movl 0x10(%r15), %r8d
movl %r8d, 0x18(%rbx)
movl 0x14(%r15), %edx
movl %edx, 0x1c(%rbx)
movslq 0x18(%r15), %rdx
movq %rdx, 0x20(%rbx)
movslq 0x1c(%r15), %rdx
movq %rdx, 0x28(%rbx)
leal -0x20(%rsi), %edx
movsbl %dl, %ebp
addl %eax, %ebp
js 0x231ce
testl %r8d, %r8d
js 0x231ce
testw %cx, %cx
je 0x231ce
movzwl %cx, %edx
movzbl %sil, %eax
leaq 0x1(%r8), %rcx
shrq %rcx
addq %rdx, %rax
leaq (%rax,%rdi,4), %rax
addq %r8, %rcx
addq %rax, %rcx
movl %ebp, %esi
cmpq %rsi, %rcx
ja 0x231ce
cmpl %ebp, 0x44(%rbx)
jae 0x232f5
movq %rbx, %rdi
callq 0x22a64
testl %eax, %eax
js 0x231ce
movzwl 0x12(%rbx), %edx
movl %ebp, 0x40(%rbx)
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x2350b
movzwl 0x12(%rbx), %ecx
cmpq %rcx, %rax
jne 0x231ce
movq 0x38(%rbx), %rcx
cmpb $0x0, -0x1(%rcx,%rax)
je 0x2332c
movq %rbx, %rdi
callq 0x2355c
testl %eax, %eax
js 0x231ce
cmpb $0x0, 0xf(%rbx)
je 0x2335d
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 0x23334
jmp 0x2335f
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
addw 0x12(%rbx), %ax
movw %ax, 0x12(%rbx)
movl 0x40(%rbx), %ecx
movzwl %ax, %eax
subl %eax, %ecx
jl 0x231ce
movl %eax, %esi
addq 0x38(%rbx), %rsi
movslq %ecx, %rdx
movq %r14, %rdi
callq 0x2350b
movslq 0x40(%rbx), %rdx
movzwl 0x12(%rbx), %ecx
subq %rcx, %rdx
cmpq %rdx, %rax
jne 0x231ce
testb $0x8, 0x2(%r14)
je 0x233c0
cmpl $0x0, 0x14(%rbx)
je 0x233c0
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 0x233ad
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x235d8
testl %eax, %eax
js 0x231ce
movl 0x14(%rbx), %edx
testq %rdx, %rdx
je 0x234ff
movq 0x38(%rbx), %rax
testl %edx, %edx
jle 0x2345e
movzwl 0x12(%rbx), %esi
addq %rax, %rsi
xorl %r8d, %r8d
movl $0x3c1a7, %r9d          # imm = 0x3C1A7
xorl %edi, %edi
xorl %r10d, %r10d
movl (%rsi,%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, %r8
incq %r10
cmpq %r10, %rdx
jne 0x233fd
movb 0x10(%rbx), %r9b
andb $0x4, %r9b
shrb $0x2, %r9b
subq $0x1, %r8
setb %cl
xorl %edx, %edx
testb $0x1, %cl
cmovneq %rdx, %r8
testb %r9b, %r9b
cmovneq %rdx, %r8
jmp 0x2346f
movb 0x10(%rbx), %r9b
andb $0x4, %r9b
shrb $0x2, %r9b
xorl %edi, %edi
xorl %r8d, %r8d
movq (%rbx), %r11
addq %r11, %r8
movl $0x1249, %r10d          # imm = 0x1249
movl $0xe, %edx
movl $0x6, %ebp
movl $0xc, %esi
movq %r11, %r14
movl %edx, %ecx
sarq %cl, %r14
movq %r8, %r15
sarq %cl, %r15
cmpq %r15, %r14
je 0x234be
addq $0x3, %rdx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %r14d
addl %r14d, %r10d
decl %ebp
addl $-0x3, %esi
cmpl $0x1, %ebp
ja 0x2348a
xorl %r10d, %r10d
jmp 0x234c1
addl %r14d, %r10d
movw %r10w, 0xc(%rbx)
movslq 0x18(%rbx), %rcx
testq %rcx, %rcx
setle %dl
orb %r9b, %dl
testb $0x1, %dl
jne 0x234ff
cmpq %rcx, %rdi
je 0x234ff
leaq 0x7430f(%rip), %rsi     # 0x977f3
leaq 0x74312(%rip), %rdx     # 0x977fd
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x13de5
jmp 0x231ce
movl 0xc(%rsp), %eax
addl $0x4, %eax
jmp 0x23352