// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
callq 0x33ff0
movl %eax, -0x28(%rbp)
cmpl $0x4, %eax
je 0x33afe
cmpl $0x0, -0x28(%rbp)
jne 0x33af2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x33fe3
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x33fe3
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x13, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x33b18
leaq -0x24(%rbp), %rdi
callq 0x32830
cmpl $0x20, -0x24(%rbp)
jge 0x33b2a
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
cmpl $0x20, %eax
jle 0x33b63
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x20, %ecx
movl %ecx, 0x10(%rax)
jmp 0x33b91
leaq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl $0x20, %edx
callq 0xe620
cmpq $0x20, %rax
je 0x33b8f
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x33fe3
jmp 0x33b91
movq -0x58(%rbp), %rdi
callq 0x32820
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rdi
addq $0x4, %rdi
callq 0x34090
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x32820
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x10, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0xc(%rax)
movl -0x5c(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xe(%rax)
movl -0x5c(%rbp), %eax
andl $0xff, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x33c33
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl $0x4, %eax
subl %edx, %eax
movl %eax, -0x74(%rbp)
jmp 0x33c3a
xorl %eax, %eax
movl %eax, -0x74(%rbp)
jmp 0x33c3a
movl -0x74(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0xf(%rax)
movq -0x58(%rbp), %rdi
addq $0xc, %rdi
callq 0x32820
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
shrl $0x10, %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x10(%rax)
movl -0x60(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x58(%rbp), %rdi
addq $0x10, %rdi
callq 0x32820
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rdi
addq $0x14, %rdi
callq 0x32820
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x58(%rbp), %rdi
addq $0x18, %rdi
callq 0x34090
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x58(%rbp), %rdi
addq $0x1c, %rdi
callq 0x34090
movslq %eax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x24(%rbp), %eax
subl $0x20, %eax
movq -0x20(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
cmpl $0x7fffffff, -0x30(%rbp) # imm = 0x7FFFFFFF
ja 0x33d06
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jl 0x33d06
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
cmpl $0x1, %eax
jge 0x33d12
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
shlq $0x2, %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq 0x18(%rcx), %rcx
addq $0x1, %rcx
shrq %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq 0x18(%rcx), %rcx
addq %rcx, %rax
movl -0x30(%rbp), %ecx
cmpq %rcx, %rax
jbe 0x33d64
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x18(%rbp), %rdi
movl -0x30(%rbp), %eax
movl %eax, %esi
callq 0x33110
cmpl $0x0, %eax
jge 0x33d83
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movl -0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
movl %eax, %edx
callq 0x33ff0
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpq %rcx, %rax
je 0x33dc1
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x33dfc
movq -0x18(%rbp), %rdi
callq 0x340e0
cmpl $0x0, %eax
jge 0x33dfa
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
jmp 0x33dfc
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
cmpl %ecx, %eax
jge 0x33e37
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x33e03
movq -0x20(%rbp), %rax
movzbl 0xf(%rax), %edx
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x12(%rax)
movq -0x18(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
cmpl %ecx, %eax
jl 0x33eab
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x20(%rbp), %rax
movzwl 0x12(%rax), %eax
cltq
addq %rax, %rsi
movq -0x18(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
subl %ecx, %eax
movslq %eax, %rdx
callq 0x33ff0
movq -0x18(%rbp), %rcx
movl 0x40(%rcx), %ecx
movq -0x20(%rbp), %rdx
movzwl 0x12(%rdx), %edx
subl %edx, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
je 0x33eb7
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x13, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x33ee2
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x40(%rax), %esi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdx
xorl %ecx, %ecx
callq 0x341c0
movq -0x18(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x34230
cmpl $0x0, %eax
jge 0x33f00
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
movq -0x20(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jbe 0x33fda
movq -0x20(%rbp), %rax
movl 0x14(%rax), %edi
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
cltq
addq %rax, %rsi
leaq -0x68(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x33790
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x33f4e
cmpq $0x0, -0x68(%rbp)
jne 0x33f56
movq $0x1, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
addq -0x68(%rbp), %rsi
movl $0xe, %edx
movl $0x5, %ecx
callq 0x33880
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xc(%rax)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x33fd8
movq -0x20(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x33fd8
movq -0x70(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq 0x18(%rcx), %rcx
cmpq %rcx, %rax
je 0x33fd8
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
movl $0x1, %edi
leaq 0xbdd4d(%rip), %rsi     # 0xf1d0e
leaq 0xbdd50(%rip), %rdx     # 0xf1d18
movb $0x0, %al
callq 0x1b030
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x33fe3
jmp 0x33fda
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop