// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x48(%rsp), %rdi
leaq 0x34(%rsp), %rsi
movl $0x4, %edx
callq 0x4f76c0
movl %eax, 0x30(%rsp)
cmpl $0x4, %eax
je 0x365d86
cmpl $0x0, 0x30(%rsp)
jne 0x365d79
movl $0xffffffff, 0x54(%rsp) # imm = 0xFFFFFFFF
jmp 0x3660d3
movl $0xfffffffe, 0x54(%rsp) # imm = 0xFFFFFFFE
jmp 0x3660d3
movq 0x48(%rsp), %rdi
movq %rsp, %rsi
movl $0x20, %edx
callq 0x4f76c0
cltq
cmpq $0x20, %rax
je 0x365dad
movl $0xfffffffd, 0x54(%rsp) # imm = 0xFFFFFFFD
jmp 0x3660d3
leaq 0x2dd294(%rip), %rax    # 0x643048
cmpl $0x0, (%rax)
je 0x365df5
leaq 0x34(%rsp), %rdi
callq 0x365aa0
movl $0x0, 0x2c(%rsp)
cmpl $0x8, 0x2c(%rsp)
jge 0x365df3
movq %rsp, %rdi
movslq 0x2c(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x365aa0
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x365dcb
jmp 0x365df5
movl (%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movl 0x4(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x8(%rsp), %ecx
shrl $0x10, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
andq $-0x10000, %rcx         # imm = 0xFFFF0000
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0x8(%rsp), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xff, %rdx
shlq $0x10, %rdx
andq $-0xff0001, %rcx        # imm = 0xFF00FFFF
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0x8(%rsp), %ecx
andl $0xff, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xff, %rdx
shlq $0x18, %rdx
movabsq $-0xff000001, %rsi      # imm = 0xFFFFFFFF00FFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0xc(%rsp), %ecx
shrl $0x10, %ecx
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x20, %rdx
movabsq $-0xffff00000001, %rsi  # imm = 0xFFFF0000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0xc(%rsp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movq 0x38(%rsp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x30, %rdx
movabsq $0xffffffffffff, %rsi   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl 0x10(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movl 0x14(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x14(%rax)
movl 0x18(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x18(%rax)
movl 0x1c(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x1c(%rax)
movslq 0x34(%rsp), %rax
subq $0x20, %rax
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x24(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %eax
movq 0x40(%rsp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x36601b
movq 0x40(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
sarl %ecx
movq 0x40(%rsp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
sarl $0x2, %ecx
movq 0x40(%rsp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
sarl $0x4, %ecx
movq 0x40(%rsp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
sarl $0x8, %ecx
movq 0x40(%rsp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
sarl $0x10, %ecx
movq 0x40(%rsp), %rax
orl 0x28(%rax), %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x40(%rsp), %rax
movslq 0x28(%rax), %rsi
callq 0x19f00
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rsi
movq 0x40(%rsp), %rax
movl 0x24(%rax), %edx
callq 0x4f76c0
movq 0x40(%rsp), %rcx
cmpl 0x24(%rcx), %eax
je 0x36604d
movl $0xfffffffc, 0x54(%rsp) # imm = 0xFFFFFFFC
jmp 0x3660d3
movq 0x40(%rsp), %rax
movl 0x24(%rax), %ecx
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
shrq $0x30, %rax
shll $0x2, %eax
subl %eax, %ecx
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
subl %eax, %ecx
movq 0x38(%rsp), %rax
subl 0x10(%rax), %ecx
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl $0x2, %esi
cltd
idivl %esi
subl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x20(%rax)
leaq 0x2dcfa0(%rip), %rax    # 0x643048
cmpl $0x0, (%rax)
je 0x3660c8
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rax
movl 0x24(%rax), %esi
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rdx
callq 0x3660e0
movl 0x34(%rsp), %eax
addl $0x4, %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax)