// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2f4b
testl %eax, %eax
je 0x3019
cmpl $0x4, %eax
jne 0x3020
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
movq %r14, %rdi
callq 0x2f4b
cmpl $0x20, %eax
jne 0x3027
cmpl $0x0, 0x2561e(%rip)     # 0x28614
movl 0xc(%rsp), %eax
je 0x302e
bswapl %eax
movl %eax, 0xc(%rsp)
xorl %ecx, %ecx
cmpq $0x8, %rcx
je 0x302e
movl 0x10(%rsp,%rcx,4), %edx
bswapl %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
jmp 0x3004
pushq $-0x1
jmp 0x315c
pushq $-0x2
jmp 0x315c
pushq $-0x3
jmp 0x315c
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 0x30c2
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 0x30c6
movq 0x30(%rbx), %rsi
movq %r14, %rdi
callq 0x2f4b
cmpl 0x24(%rbx), %eax
jne 0x315a
movl %eax, %ecx
movq 0x8(%rbx), %r9
movq %r9, %rdi
shrq $0x2e, %rdi
movl %edi, %r10d
andl $-0x4, %r10d
movl %r9d, %r11d
shrl $0x18, %r11d
movslq 0x10(%rbx), %r8
leal 0x1(%r8), %esi
pushq $-0x2
popq %rbp
movl %esi, %eax
cltd
idivl %ebp
addl %r8d, %r11d
addl %r10d, %r11d
movl %ecx, %edx
subl %r11d, %edx
addl %eax, %edx
movl %edx, 0x20(%rbx)
cmpl $0x0, 0x254fb(%rip)     # 0x28614
je 0x3226
movq 0x30(%rbx), %r14
movl %r9d, %r10d
shrl $0x18, %r10d
leaq (%r14,%r10), %r11
andl $-0x4, %edi
addq %r14, %rdi
pushq $0x2
popq %rbp
movl %esi, %eax
cltd
idivl %ebp
xorl %edx, %edx
shrq $0x30, %r9
cmpq %r9, %rdx
jae 0x3168
movl (%r11,%rdx,4), %esi
bswapl %esi
movl %esi, (%r11,%rdx,4)
incq %rdx
movq 0x8(%rbx), %r9
jmp 0x313e
pushq $-0x4
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cltq
addq %r10, %rdi
addq %r8, %rdi
addq %rax, %rdi
movslq %ecx, %rax
addq %rax, %r14
leaq 0x1af3c(%rip), %rbx     # 0x1e0bc
cmpq %r14, %rdi
jae 0x3226
movq %rdi, %r15
callq 0x2030
movq (%rax), %rax
movzbl 0x2(%r15), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
andl $0xfd, %ecx
cmpl $0x41, %ecx
jne 0x31b2
addq $0x4, %r15
movq %r15, %rdi
jmp 0x3180
leaq 0x3(%r15), %rdi
movzbl %al, %eax
leal -0x44(%rax), %ecx
cmpl $0x5, %ecx
ja 0x31dd
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movl 0x3(%r15), %eax
bswapl %eax
movl %eax, 0x3(%r15)
addq $0x7, %r15
movq %r15, %rdi
jmp 0x3180
cmpl $0x53, %eax
je 0x3214
movq %rdi, %rcx
cmpl $0x5a, %eax
jne 0x3180
jmp 0x3203
movq 0x3(%r15), %rax
bswapq %rax
movq %rax, 0x3(%r15)
addq $0xb, %r15
movq %r15, %rdi
jmp 0x3180
movq %rdi, %rcx
leaq 0x1(%rcx), %rdi
cmpb $0x0, (%rcx)
movq %rdi, %rcx
jne 0x3203
jmp 0x3180
rolw $0x8, 0x3(%r15)
addq $0x5, %r15
movq %r15, %rdi
jmp 0x3180
movl 0xc(%rsp), %eax
addl $0x4, %eax
jmp 0x315d