// File: /workspace/github_c_makefile_star2_O3/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 0xa15a
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 0xa146
movslq %esi, %rax
addq %rax, %rbx
cmpq %rbx, %r14
jae 0xa2c0
callq 0x3030
movq (%rax), %rax
leaq 0x119d4(%rip), %rcx     # 0x1bb4c
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 0xa1ac
addq $0x4, %r14
jmp 0xa23d
leaq 0x3(%r14), %rdi
movzbl %r8b, %r9d
leal -0x42(%r9), %r8d
cmpl $0x7, %r8d
ja 0xa1d8
movslq (%rcx,%r8,4), %r8
addq %rcx, %r8
jmpq *%r8
movl 0x3(%r14), %edi
bswapl %edi
movl %edi, 0x3(%r14)
addq $0x7, %r14
jmp 0xa23d
cmpl $0x53, %r9d
je 0xa233
movq %rdi, %r8
cmpl $0x5a, %r9d
je 0xa224
jmp 0xa240
movq 0x3(%r14), %rdi
bswapq %rdi
movq %rdi, 0x3(%r14)
addq $0xb, %r14
jmp 0xa23d
movzbl (%rdi), %r8d
leal -0x41(%r8), %r9d
cmpl $0x22, %r9d
ja 0xa24e
btq %r9, %rsi
jae 0xa24e
movl 0x4(%r14), %r9d
addq $0x4, %r14
movq %r14, %r8
bswapl %r9d
movl %r9d, (%r8)
jmp 0xa240
movq %rdi, %r8
leaq 0x1(%r8), %rdi
cmpb $0x0, (%r8)
movq %rdi, %r8
jne 0xa224
jmp 0xa240
rolw $0x8, 0x3(%r14)
addq $0x5, %r14
movq %r14, %rdi
movq %rdi, %r14
cmpq %rbx, %rdi
jb 0xa18c
jmp 0xa2c0
movl %r8d, %r9d
andb $-0x21, %r9b
cmpb $0x53, %r9b
jne 0xa27d
leaq 0x4(%r14), %r8
movl 0x4(%r14), %r9d
testq %r9, %r9
je 0xa2b8
xorl %r10d, %r10d
rolw $0x8, 0x8(%r14,%r10)
addq $0x2, %r10
cmpq %r9, %r10
jb 0xa26b
jmp 0xa219
addl $-0x46, %r8d
cmpl $0x23, %r8d
ja 0xa20e
btq %r8, %rdx
jae 0xa20e
leaq 0x4(%r14), %r8
movl 0x4(%r14), %r9d
testq %r9, %r9
je 0xa2b8
xorl %r10d, %r10d
movl 0x8(%r14,%r10), %r11d
bswapl %r11d
movl %r11d, 0x8(%r14,%r10)
addq $0x4, %r10
cmpq %r9, %r10
jb 0xa29d
jmp 0xa219
xorl %r9d, %r9d
jmp 0xa219
addq $0x8, %rsp
popq %rbx
popq %r14
retq