// File: /workspace/github_c_makefile_star2_O1/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 0x5262
testl %eax, %eax
je 0x5511
cmpl $0x4, %eax
jne 0x5518
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movl $0x20, %edx
callq 0x5262
movl %eax, %ecx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpl $0x20, %ecx
jne 0x551d
cmpl $0x0, 0x26336(%rip)     # 0x2b614
je 0x52ff
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 0x52ec
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
shll $0x18, %eax
orq %rdx, %rax
orq %rcx, %rax
movq %rax, 0x8(%rbx)
movl 0x1c(%rsp), %ecx
movl %ecx, %edx
shrl $0x10, %edx
shlq $0x20, %rdx
movl %eax, %eax
orq %rdx, %rax
shlq $0x30, %rcx
orq %rax, %rcx
movq %rcx, 0x8(%rbx)
movl 0x20(%rsp), %eax
movl %eax, 0x10(%rbx)
movl 0x24(%rsp), %eax
movl %eax, 0x14(%rbx)
movl 0x28(%rsp), %eax
movl %eax, 0x18(%rbx)
movl 0x2c(%rsp), %eax
movl %eax, 0x1c(%rbx)
movl 0xc(%rsp), %eax
leal -0x20(%rax), %ecx
movl %ecx, 0x24(%rbx)
cmpl %ecx, 0x28(%rbx)
jge 0x53b9
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, 0x30(%rbx)
movq 0x30(%rbx), %rsi
movl 0x24(%rbx), %edx
movq %r14, %rdi
callq 0x5262
movl %eax, %ecx
movslq 0x24(%rbx), %rdx
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpl %edx, %ecx
jne 0x551d
movq 0x8(%rbx), %rax
movq %rax, %rcx
shrq $0x2e, %rcx
movl %ecx, %esi
andl $-0x4, %esi
movl %eax, %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 %edx, %esi
subl %r10d, %esi
subl %r11d, %esi
movl %esi, 0x20(%rbx)
cmpl $0x0, 0x261f1(%rip)     # 0x2b614
je 0x5508
movq 0x30(%rbx), %r14
movl %eax, %esi
shrl $0x18, %esi
addq %r14, %rsi
andl $-0x4, %ecx
addq %rsi, %rcx
addq %r8, %rcx
addl %r9d, %edi
sarl %edi
movslq %edi, %r15
addq %rcx, %r15
shrq $0x30, %rax
je 0x5465
xorl %eax, %eax
movl (%rsi,%rax,4), %ecx
bswapl %ecx
movl %ecx, (%rsi,%rax,4)
incq %rax
movzwl 0xe(%rbx), %ecx
cmpq %rcx, %rax
jb 0x5451
addq %rdx, %r14
cmpq %r14, %r15
jae 0x5508
callq 0x2030
movq (%rax), %rax
leaq 0x1bc3c(%rip), %rcx     # 0x210bc
movzbl 0x2(%r15), %edx
movl (%rax,%rdx,4), %esi
movl %esi, %edx
andl $0xfd, %edx
cmpl $0x41, %edx
jne 0x549b
addq $0x4, %r15
jmp 0x54ff
leaq 0x3(%r15), %rdx
movzbl %sil, %esi
leal -0x44(%rsi), %edi
cmpl $0x5, %edi
ja 0x54c4
movslq (%rcx,%rdi,4), %rsi
addq %rcx, %rsi
jmpq *%rsi
movl 0x3(%r15), %edx
bswapl %edx
movl %edx, 0x3(%r15)
addq $0x7, %r15
jmp 0x54ff
cmpl $0x53, %esi
je 0x54f0
movq %rdx, %r15
cmpl $0x5a, %esi
jne 0x54ff
leaq 0x1(%rdx), %r15
cmpb $0x0, (%rdx)
movq %r15, %rdx
jne 0x54d1
jmp 0x54ff
movq 0x3(%r15), %rdx
bswapq %rdx
movq %rdx, 0x3(%r15)
addq $0xb, %r15
jmp 0x54ff
rolw $0x8, 0x3(%r15)
addq $0x5, %r15
jmp 0x54ff
movq %rdx, %r15
cmpq %r14, %r15
jb 0x5480
movl 0xc(%rsp), %eax
addl $0x4, %eax
jmp 0x551d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x551d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq