// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam.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];

	assert(BAM_CORE_SIZE == 32);
	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, BAM_CORE_SIZE) != BAM_CORE_SIZE) 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 - BAM_CORE_SIZE;
	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 %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x1096a
testl %eax, %eax
je 0x127e9
cmpl $0x4, %eax
jne 0x127f0
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movl $0x20, %edx
callq 0x1096a
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
cmpl $0x20, %eax
jne 0x12858
cmpl $0x0, 0x1cc17(%rip)     # 0x2f320
movl 0xc(%rsp), %eax
je 0x12755
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 0x1271b
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 0x127f7
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 0x3610
movq %rax, %rsi
movq %rax, 0x30(%rbx)
movl 0x24(%rbx), %edx
jmp 0x127fb
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x12858
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
jmp 0x12858
movq 0x30(%rbx), %rsi
movq %r14, %rdi
callq 0x1096a
movl $0xfffffffc, %ecx       # imm = 0xFFFFFFFC
cmpl 0x24(%rbx), %eax
jne 0x12858
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
shrq $0x2e, %rdx
andl $-0x4, %edx
shrl $0x18, %ecx
movl 0x10(%rbx), %esi
leal 0x1(%rsi), %edi
shrl $0x1f, %edi
addl %esi, %edi
incl %edi
sarl %edi
addl %esi, %ecx
addl %edx, %ecx
movl %eax, %edx
subl %ecx, %edx
subl %edi, %edx
movl %edx, 0x20(%rbx)
cmpl $0x0, 0x1cadf(%rip)     # 0x2f320
je 0x12851
movq 0x30(%rbx), %rdx
movq %rbx, %rdi
movl %eax, %esi
callq 0x12862
movl 0xc(%rsp), %ecx
addl $0x4, %ecx
movl %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
retq