// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]yahs/bamlite.c
// Function: bam_read1
int bam_read1(bamFile fp, bam1_t *b)
{
    bam1_core_t *c = &b->core;
    int32_t block_len, ret, i;
    uint32_t x[8];

    if ((ret = bam_read(fp, &block_len, 4)) != 4) {
        if (ret == 0) return -1; // normal end-of-file
        else return -2; // truncated
    }
    if (bam_read(fp, x, sizeof(bam1_core_t)) != sizeof(bam1_core_t)) return -3;
    if (bam_is_be) {
        bam_swap_endian_4p(&block_len);
        for (i = 0; i < 8; ++i) bam_swap_endian_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->data_len = block_len - sizeof(bam1_core_t);
    if (b->m_data < b->data_len) {
        b->m_data = b->data_len;
        kroundup32(b->m_data);
        b->data = (uint8_t*)realloc(b->data, b->m_data);
    }
    if (bam_read(fp, b->data, b->data_len) != b->data_len) return -4;
    b->l_aux = b->data_len - c->n_cigar * 4 - c->l_qname - c->l_qseq - (c->l_qseq+1)/2;
    if (bam_is_be) swap_endian_data(c, b->data_len, b->data);
    return 4 + block_len;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x5171
testl %eax, %eax
je 0x52cb
cmpl $0x4, %eax
jne 0x52d5
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movl $0x20, %edx
callq 0x5171
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
cmpl $0x20, %eax
jne 0x542f
cmpl $0x0, 0x27429(%rip)     # 0x2c614
movl 0xc(%rsp), %eax
je 0x5237
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 0x51fd
movq 0x10(%rsp), %rcx
movq %rcx, (%rbx)
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %edx
movl %ecx, %esi
shrl $0x10, %esi
movl %ecx, %edi
shll $0x8, %edi
andl $0xff0000, %edi         # imm = 0xFF0000
shll $0x18, %ecx
orl %esi, %ecx
orl %edi, %ecx
movl %edx, %esi
shrl $0x10, %esi
shlq $0x20, %rsi
orq %rcx, %rsi
shlq $0x30, %rdx
orq %rsi, %rdx
movq %rdx, 0x8(%rbx)
movaps 0x20(%rsp), %xmm0
movups %xmm0, 0x10(%rbx)
leal -0x20(%rax), %edx
movl %edx, 0x24(%rbx)
cmpl %edx, 0x28(%rbx)
jge 0x52df
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, 0x28(%rbx)
movq 0x30(%rbx), %rdi
movslq %ecx, %rsi
callq 0x2390
movq %rax, %rsi
movq %rax, 0x30(%rbx)
movl 0x24(%rbx), %edx
jmp 0x52e3
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x542f
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
jmp 0x542f
movq 0x30(%rbx), %rsi
movq %r14, %rdi
callq 0x5171
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
cmpl 0x24(%rbx), %eax
jne 0x542f
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
shrq $0x2e, %rdx
movl %edx, %esi
andl $-0x4, %esi
movl %ecx, %r10d
shrl $0x18, %r10d
movslq 0x10(%rbx), %r8
leal 0x1(%r8), %edi
movl %edi, %r9d
shrl $0x1f, %r9d
leal (%r8,%r9), %r11d
incl %r11d
sarl %r11d
addl %r8d, %r10d
addl %esi, %r10d
movl %eax, %esi
subl %r10d, %esi
subl %r11d, %esi
movl %esi, 0x20(%rbx)
cmpl $0x0, 0x272d3(%rip)     # 0x2c614
je 0x5428
movq 0x30(%rbx), %r14
movl %ecx, %esi
shrl $0x18, %esi
addq %r14, %rsi
andl $-0x4, %edx
addq %rsi, %rdx
addq %r8, %rdx
addl %r9d, %edi
sarl %edi
movslq %edi, %r15
addq %rdx, %r15
shrq $0x30, %rcx
je 0x5383
xorl %ecx, %ecx
movl (%rsi,%rcx,4), %edx
bswapl %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
movzwl 0xe(%rbx), %edx
cmpq %rdx, %rcx
jb 0x536f
cltq
addq %rax, %r14
cmpq %r14, %r15
jae 0x5428
callq 0x2030
movq (%rax), %rax
leaq 0x1cd1c(%rip), %rcx     # 0x220bc
movzbl 0x2(%r15), %edx
movl (%rax,%rdx,4), %esi
movl %esi, %edx
andl $0xfd, %edx
cmpl $0x41, %edx
jne 0x53bb
addq $0x4, %r15
jmp 0x541f
leaq 0x3(%r15), %rdx
movzbl %sil, %esi
leal -0x44(%rsi), %edi
cmpl $0x5, %edi
ja 0x53e4
movslq (%rcx,%rdi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
movl 0x3(%r15), %edx
bswapl %edx
movl %edx, 0x3(%r15)
addq $0x7, %r15
jmp 0x541f
cmpl $0x53, %esi
je 0x5410
movq %rdx, %r15
cmpl $0x5a, %esi
jne 0x541f
leaq 0x1(%rdx), %r15
cmpb $0x0, (%rdx)
movq %r15, %rdx
jne 0x53f1
jmp 0x541f
movq 0x3(%r15), %rdx
bswapq %rdx
movq %rdx, 0x3(%r15)
addq $0xb, %r15
jmp 0x541f
rolw $0x8, 0x3(%r15)
addq $0x5, %r15
jmp 0x541f
movq %rdx, %r15
cmpq %r14, %r15
jb 0x53a0
movl 0xc(%rsp), %ecx
addl $0x4, %ecx
movl %ecx, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq