// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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 %r15
pushq %r14
pushq %rbx
subq $0x30, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xc(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2d694b
testl %eax, %eax
je 0x1f4e73
cmpl $0x4, %eax
jne 0x1f4e7a
leaq 0x10(%rsp), %rsi
pushq $0x20
popq %rdx
movq %r14, %rdi
callq 0x2d694b
cmpl $0x20, %eax
jne 0x1f4e81
leaq 0x248b4c(%rip), %r15    # 0x43d998
cmpl $0x0, (%r15)
movl 0xc(%rsp), %eax
je 0x1f4e88
bswapl %eax
movl %eax, 0xc(%rsp)
xorl %ecx, %ecx
cmpq $0x8, %rcx
je 0x1f4e88
movl 0x10(%rsp,%rcx,4), %edx
bswapl %edx
movl %edx, 0x10(%rsp,%rcx,4)
incq %rcx
jmp 0x1f4e5e
pushq $-0x1
jmp 0x1f4f7b
pushq $-0x2
jmp 0x1f4f7b
pushq $-0x3
jmp 0x1f4f7b
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 0x1f4f1c
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 0x17f58
movq %rax, %rsi
movq %rax, 0x30(%rbx)
movl 0x24(%rbx), %edx
jmp 0x1f4f20
movq 0x30(%rbx), %rsi
movq %r14, %rdi
callq 0x2d694b
cmpl 0x24(%rbx), %eax
jne 0x1f4f79
movl %eax, %esi
movq 0x8(%rbx), %rcx
movq %rcx, %rdi
shrq $0x2e, %rdi
andl $-0x4, %edi
shrl $0x18, %ecx
movl 0x10(%rbx), %r8d
leal 0x1(%r8), %eax
pushq $-0x2
popq %r9
cltd
idivl %r9d
addl %r8d, %ecx
addl %edi, %ecx
movl %esi, %edx
subl %ecx, %edx
addl %eax, %edx
movl %edx, 0x20(%rbx)
cmpl $0x0, (%r15)
je 0x1f4f70
movq 0x30(%rbx), %rdx
movq %rbx, %rdi
callq 0x1f4f86
movl 0xc(%rsp), %eax
addl $0x4, %eax
jmp 0x1f4f7c
pushq $-0x4
popq %rax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %r15
retq