// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam.c
// Function: swap_endian_data
static void swap_endian_data(const bam1_core_t *c, int data_len, uint8_t *data)
{
	uint8_t *s;
	uint32_t i, *cigar = (uint32_t*)(data + c->l_qname);
	s = data + c->n_cigar*4 + c->l_qname + c->l_qseq + (c->l_qseq + 1)/2;
	for (i = 0; i < c->n_cigar; ++i) bam_swap_endian_4p(&cigar[i]);
	while (s < data + data_len) {
		uint8_t type;
		s += 2; // skip key
		type = toupper(*s); ++s; // skip type
		if (type == 'C' || type == 'A') ++s;
		else if (type == 'S') { bam_swap_endian_2p(s); s += 2; }
		else if (type == 'I' || type == 'F') { bam_swap_endian_4p(s); s += 4; }
		else if (type == 'D') { bam_swap_endian_8p(s); s += 8; }
		else if (type == 'Z' || type == 'H') { while (*s) ++s; ++s; }
		else if (type == 'B') {
			int32_t n, Bsize = bam_aux_type2size(*s);
			memcpy(&n, s + 1, 4);
			if (1 == Bsize) {
			} else if (2 == Bsize) {
				for (i = 0; i < n; i += 2)
					bam_swap_endian_2p(s + 5 + i);
			} else if (4 == Bsize) {
				for (i = 0; i < n; i += 4)
					bam_swap_endian_4p(s + 5 + i);
			}
			bam_swap_endian_4p(s+1); 
		}
	}
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq 0x8(%rdi), %rcx
movl %ecx, %eax
shrl $0x18, %eax
addq %rdx, %rax
shrq $0x30, %rcx
leaq (%rax,%rcx,4), %rdx
movslq 0x10(%rdi), %r8
addq %r8, %rdx
leal 0x1(%r8), %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
incl %r8d
sarl %r8d
movslq %r8d, %r14
addq %rdx, %r14
testq %rcx, %rcx
je 0x9d5c
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
bswapl %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
movzwl 0xe(%rdi), %edx
cmpq %rdx, %rcx
jb 0x9d48
movslq %esi, %rax
addq %rax, %rbx
cmpq %rbx, %r14
jae 0x9edc
callq 0x3030
movq (%rax), %rax
leaq 0x10d22(%rip), %rcx     # 0x1aa9c
movabsq $0x900000009, %rdx      # imm = 0x900000009
movabsq $0x400000005, %rsi      # imm = 0x400000005
movzbl 0x2(%r14), %edi
movl (%rax,%rdi,4), %r8d
movl %r8d, %edi
andl $0xfd, %edi
cmpl $0x41, %edi
jne 0x9dae
addq $0x4, %r14
jmp 0x9e67
leaq 0x3(%r14), %rdi
movzbl %r8b, %r9d
leal -0x42(%r9), %r8d
cmpl $0x7, %r8d
ja 0x9ddd
movslq (%rcx,%r8,4), %r8
addq %rcx, %r8
jmpq *%r8
movl 0x3(%r14), %edi
bswapl %edi
movl %edi, 0x3(%r14)
addq $0x7, %r14
jmp 0x9e67
cmpl $0x53, %r9d
je 0x9e5d
movq %rdi, %r8
cmpl $0x5a, %r9d
je 0x9e4e
jmp 0x9e6a
movq 0x3(%r14), %rdi
bswapq %rdi
movq %rdi, 0x3(%r14)
addq $0xb, %r14
jmp 0x9e67
movzbl (%rdi), %r8d
leal -0x41(%r8), %r10d
cmpl $0x22, %r10d
ja 0x9ea3
movl $0x1, %r9d
btq %r10, %rsi
jae 0x9ea3
movl 0x4(%r14), %r8d
cmpl $0x4, %r9d
je 0x9e78
cmpl $0x2, %r9d
jne 0x9e96
testq %r8, %r8
je 0x9e96
xorl %r9d, %r9d
rolw $0x8, 0x8(%r14,%r9)
addq $0x2, %r9
cmpq %r8, %r9
jb 0x9e39
jmp 0x9e96
movq %rdi, %r8
leaq 0x1(%r8), %rdi
cmpb $0x0, (%r8)
movq %rdi, %r8
jne 0x9e4e
jmp 0x9e6a
rolw $0x8, 0x3(%r14)
addq $0x5, %r14
movq %r14, %rdi
movq %rdi, %r14
cmpq %rbx, %rdi
jb 0x9d8e
jmp 0x9edc
testq %r8, %r8
je 0x9e96
xorl %r9d, %r9d
movl 0x8(%r14,%r9), %r10d
bswapl %r10d
movl %r10d, 0x8(%r14,%r9)
addq $0x4, %r9
cmpq %r8, %r9
jb 0x9e80
movl 0x4(%r14), %r8d
bswapl %r8d
movl %r8d, 0x4(%r14)
jmp 0x9e6a
movl %r8d, %r10d
andb $-0x21, %r10b
movl $0x2, %r9d
cmpb $0x53, %r10b
je 0x9e21
addl $-0x46, %r8d
cmpl $0x23, %r8d
ja 0x9ed4
movl $0x4, %r9d
btq %r8, %rdx
jb 0x9e21
xorl %r9d, %r9d
jmp 0x9e21
addq $0x8, %rsp
popq %rbx
popq %r14
retq