// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/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);
	if (bam_no_B) bam_remove_B(b);
	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 0x180ad
testl %eax, %eax
je 0xa073
cmpl $0x4, %eax
jne 0xa07d
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r14, %rdi
callq 0x180ad
movq %rax, %rcx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpq $0x20, %rcx
jne 0xa0fe
cmpl $0x0, 0x19abd(%rip)     # 0x23a50
movl 0xc(%rsp), %eax
je 0x9fdf
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 0x9fa5
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), %ecx
movl %ecx, 0x24(%rbx)
cmpl %ecx, 0x28(%rbx)
jge 0xa084
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 0x3430
movq %rax, %rsi
movq %rax, 0x30(%rbx)
movl 0x24(%rbx), %ecx
jmp 0xa088
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xa0fe
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0xa0fe
movq 0x30(%rbx), %rsi
movslq %ecx, %rdx
movq %r14, %rdi
callq 0x180ad
movq %rax, %rcx
movslq 0x24(%rbx), %rsi
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpq %rsi, %rcx
jne 0xa0fe
movq 0x8(%rbx), %rax
movq %rax, %rcx
shrq $0x2e, %rcx
andl $-0x4, %ecx
shrl $0x18, %eax
movl 0x10(%rbx), %edx
leal 0x1(%rdx), %edi
shrl $0x1f, %edi
addl %edx, %edi
incl %edi
sarl %edi
addl %edx, %eax
addl %ecx, %eax
movl %esi, %ecx
subl %eax, %ecx
subl %edi, %ecx
movl %ecx, 0x20(%rbx)
cmpl $0x0, 0x19978(%rip)     # 0x23a50
je 0xa0e6
movq 0x30(%rbx), %rdx
movq %rbx, %rdi
callq 0xa106
cmpl $0x0, 0x19967(%rip)     # 0x23a54
je 0xa0f7
movq %rbx, %rdi
callq 0xa2c8
movl 0xc(%rsp), %eax
addl $0x4, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
retq