// File: /workspace/github_cpp_makefile_star2_O3/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 0x43873
testl %eax, %eax
je 0x14afc
cmpl $0x4, %eax
jne 0x14b03
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r14, %rdi
callq 0x43873
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmpq $0x20, %rax
jne 0x14b08
testb $0xc, 0x2(%r14)
movl 0xc(%rsp), %eax
je 0x149cd
bswapl %eax
movl %eax, 0xc(%rsp)
xorl %ecx, %ecx
pxor %xmm0, %xmm0
movdqa 0x10(%rsp,%rcx,4), %xmm1
movdqa %xmm1, %xmm2
punpckhbw %xmm0, %xmm2    # xmm2 = xmm2[8],xmm0[8],xmm2[9],xmm0[9],xmm2[10],xmm0[10],xmm2[11],xmm0[11],xmm2[12],xmm0[12],xmm2[13],xmm0[13],xmm2[14],xmm0[14],xmm2[15],xmm0[15]
pshuflw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[0,1,2,3,7,6,5,4]
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
pshuflw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[0,1,2,3,7,6,5,4]
packuswb %xmm2, %xmm1
movdqa %xmm1, 0x10(%rsp,%rcx,4)
addq $0x4, %rcx
cmpq $0x8, %rcx
jne 0x14993
movq 0x10(%rsp), %rcx
movq %rcx, (%rbx)
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %edx
movl %esi, %ecx
shrl $0x10, %ecx
movl %esi, %edi
shll $0x8, %edi
andl $0xff0000, %edi         # imm = 0xFF0000
orl %ecx, %edi
movl %esi, %r8d
shll $0x18, %r8d
orl %r8d, %edi
movl %edx, %ecx
shrl $0x10, %ecx
shlq $0x20, %rcx
movq %rdx, %r9
shlq $0x30, %r9
orq %rcx, %r9
orq %rdi, %r9
movq %r9, 0x8(%rbx)
movdqa 0x20(%rsp), %xmm0
movdqu %xmm0, 0x10(%rbx)
leal -0x20(%rax), %ecx
movl %ecx, 0x20(%rbx)
cmpl $0x20, %eax
setl %r9b
movd %xmm0, %edi
testl %edi, %edi
sets %r10b
testl %r8d, %r8d
sete %r8b
orb %r9b, %r8b
orb %r10b, %r8b
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
jne 0x14b08
movl %esi, %esi
movzwl %dx, %edx
movzbl %sil, %r8d
movq 0x28(%rbx), %rsi
leaq (%rsi,%rdx,4), %rdx
addq %r8, %rdx
leal 0x1(%rdi), %r8d
shrl %r8d
movl %edi, %edi
addq %rdx, %rdi
addq %r8, %rdi
subq %rsi, %rdi
movl %ecx, %edx
cmpq %rdx, %rdi
jg 0x14b08
cmpl %ecx, 0x24(%rbx)
jge 0x14aca
addl $-0x21, %eax
movl %eax, %ecx
sarl %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
sarl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
sarl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, 0x24(%rbx)
movslq %ecx, %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0x48d0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x14b08
movq %rax, %rsi
movl 0x20(%rbx), %ecx
movslq %ecx, %rdx
movq %r14, %rdi
callq 0x43873
movslq 0x20(%rbx), %rsi
cmpq %rsi, %rax
jne 0x14b08
testb $0xc, 0x2(%r14)
je 0x14af3
movq 0x28(%rbx), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x14b13
movl 0xc(%rsp), %ebp
addl $0x4, %ebp
jmp 0x14b08
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x14b08
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movl %ebp, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq