// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/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 x[8];
    if ((ret = bgzf_read(fp, &block_len, 4)) != 4) {
        if (ret == 0) return -1; // normal end-of-file
        else return -2; // truncated
    }
    if (bgzf_read(fp, x, 32) != 32) return -3;
    if (fp->is_be) {
        ed_swap_4p(&block_len);
        for (i = 0; i < 8; ++i) ed_swap_4p(x + i);
    }
    c->tid = x[0]; c->pos = x[1];
    c->bin = x[2]>>16; c->qual = x[2]>>8&0xff; c->l_qname = x[2]&0xff;
    c->flag = x[3]>>16; c->n_cigar = x[3]&0xffff;
    c->l_qseq = x[4];
    c->mtid = x[5]; c->mpos = x[6]; c->isize = x[7];
    b->l_data = block_len - 32;
    if (b->l_data < 0 || c->l_qseq < 0 || c->l_qname < 1) return -4;
    if ((char *)bam_get_aux(b) - (char *)b->data > b->l_data)
        return -4;
    if (b->m_data < b->l_data) {
        b->m_data = b->l_data;
        kroundup32(b->m_data);
        b->data = (uint8_t*)realloc(b->data, b->m_data);
        if (!b->data)
            return -4;
    }
    if (bgzf_read(fp, b->data, b->l_data) != b->l_data) return -4;
    //b->l_aux = b->l_data - c->n_cigar * 4 - c->l_qname - c->l_qseq - (c->l_qseq+1)/2;
    if (fp->is_be) swap_data(c, b->l_data, b->data, 0);
    return 4 + block_len;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x4489c
testl %eax, %eax
je 0x14af7
cmpl $0x4, %eax
jne 0x14afe
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r14, %rdi
callq 0x4489c
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpq $0x20, %rax
jne 0x14b03
testb $0xc, 0x2(%r14)
je 0x149af
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movl 0x10(%rsp,%rax,4), %ecx
bswapl %ecx
movl %ecx, 0x10(%rsp,%rax,4)
incq %rax
cmpq $0x8, %rax
jne 0x1499c
movl 0x10(%rsp), %eax
movl %eax, (%rbx)
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rbx)
movl 0x18(%rsp), %eax
movl %eax, %ecx
shrl $0x10, %ecx
movl 0xc(%rbx), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movl %eax, %ecx
shll $0x8, %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
orq %rdx, %rcx
shll $0x18, %eax
orq %rax, %rcx
movq %rcx, 0x8(%rbx)
movl 0x1c(%rsp), %edx
movl %edx, %esi
shrl $0x10, %esi
shlq $0x20, %rsi
movl %ecx, %ecx
movq %rdx, %rdi
shlq $0x30, %rdi
orq %rsi, %rdi
orq %rcx, %rdi
movq %rdi, 0x8(%rbx)
movl 0x20(%rsp), %edi
movl %edi, 0x10(%rbx)
movl 0x24(%rsp), %ecx
movl %ecx, 0x14(%rbx)
movl 0x28(%rsp), %ecx
movl %ecx, 0x18(%rbx)
movl 0x2c(%rsp), %ecx
movl %ecx, 0x1c(%rbx)
movl 0xc(%rsp), %ecx
leal -0x20(%rcx), %esi
movl %esi, 0x20(%rbx)
cmpl $0x20, %ecx
setl %r8b
testl %edi, %edi
sets %r9b
orb %r8b, %r9b
testl %eax, %eax
sete %r8b
orb %r9b, %r8b
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
jne 0x14b03
movzwl %dx, %edx
movl %edi, %r8d
shrl $0x18, %eax
movq 0x28(%rbx), %rdi
leaq (%rdi,%rdx,4), %rdx
addq %rax, %rdx
leaq 0x1(%r8), %rax
shrq %rax
addq %rdx, %rax
addq %r8, %rax
subq %rdi, %rax
movl %esi, %edx
cmpq %rdx, %rax
jg 0x14b03
cmpl %esi, 0x24(%rbx)
jge 0x14ac0
addl $-0x21, %ecx
movl %ecx, %eax
sarl %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x10, %eax
orl %ecx, %eax
incl %eax
movl %eax, 0x24(%rbx)
movslq %eax, %rsi
callq 0x48d0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x14b03
movq 0x28(%rbx), %rsi
movslq 0x20(%rbx), %rdx
movq %r14, %rdi
callq 0x4489c
movslq 0x20(%rbx), %rsi
cmpq %rsi, %rax
jne 0x14b03
testb $0xc, 0x2(%r14)
je 0x14aee
movq 0x28(%rbx), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x14b0e
movl 0xc(%rsp), %ebp
addl $0x4, %ebp
jmp 0x14b03
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x14b03
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq