// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq 0x8(%rdi), %r11
movl %r11d, %r8d
shrl $0x18, %r8d
leaq (%rdx,%r8), %r10
movq %r11, %rax
shrq $0x30, %rax
leaq (%rdx,%rax,4), %rcx
movslq 0x10(%rdi), %r9
leal 0x1(%r9), %eax
pushq $0x2
popq %rbp
cltd
idivl %ebp
cltq
xorl %edx, %edx
shrq $0x30, %r11
cmpq %r11, %rdx
jae 0x1f4fdd
movl (%r10,%rdx,4), %r11d
bswapl %r11d
movl %r11d, (%r10,%rdx,4)
incq %rdx
movq 0x8(%rdi), %r11
jmp 0x1f4fc0
addq %r8, %rcx
addq %r9, %rcx
addq %rax, %rcx
movslq %esi, %rax
addq %rax, %rbx
leaq 0x17549d(%rip), %r14    # 0x36a490
movabsq $0x120000001, %r15      # imm = 0x120000001
movabsq $0x400000005, %r12      # imm = 0x400000005
cmpq %rbx, %rcx
jae 0x1f5132
movq %rcx, %r13
callq 0x170c0
movq (%rax), %rax
movzbl 0x2(%r13), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
andl $0xfd, %ecx
cmpl $0x41, %ecx
jne 0x1f5039
addq $0x4, %r13
movq %r13, %rcx
jmp 0x1f5007
leaq 0x3(%r13), %rcx
movzbl %al, %eax
leal -0x42(%rax), %edx
cmpl $0x7, %edx
ja 0x1f5064
movslq (%r14,%rdx,4), %rax
addq %r14, %rax
jmpq *%rax
movl 0x3(%r13), %eax
bswapl %eax
movl %eax, 0x3(%r13)
addq $0x7, %r13
movq %r13, %rcx
jmp 0x1f5007
cmpl $0x53, %eax
je 0x1f50c3
movq %rcx, %rdx
cmpl $0x5a, %eax
jne 0x1f5007
jmp 0x1f50b2
movzbl (%rcx), %eax
leal -0x41(%rax), %edx
cmpl $0x22, %edx
ja 0x1f50d5
btq %rdx, %r12
jae 0x1f50d5
movl 0x4(%r13), %eax
addq $0x4, %r13
movq %r13, %rdx
bswapl %eax
movl %eax, (%rdx)
jmp 0x1f5007
movq 0x3(%r13), %rax
bswapq %rax
movq %rax, 0x3(%r13)
addq $0xb, %r13
movq %r13, %rcx
jmp 0x1f5007
movq %rcx, %rdx
leaq 0x1(%rdx), %rcx
cmpb $0x0, (%rdx)
movq %rcx, %rdx
jne 0x1f50b2
jmp 0x1f5007
rolw $0x8, 0x3(%r13)
addq $0x5, %r13
movq %r13, %rcx
jmp 0x1f5007
movl %eax, %edx
andb $-0x21, %dl
cmpb $0x53, %dl
jne 0x1f50fb
leaq 0x4(%r13), %rdx
movl 0x4(%r13), %eax
xorl %esi, %esi
cmpq %rax, %rsi
jae 0x1f508f
rolw $0x8, 0x8(%r13,%rsi)
addq $0x2, %rsi
jmp 0x1f50e9
addl $-0x49, %eax
cmpl $0x20, %eax
ja 0x1f5084
btq %rax, %r15
jae 0x1f5084
leaq 0x4(%r13), %rdx
movl 0x4(%r13), %eax
xorl %esi, %esi
cmpq %rax, %rsi
jae 0x1f508f
movl 0x8(%r13,%rsi), %edi
bswapl %edi
movl %edi, 0x8(%r13,%rsi)
addq $0x4, %rsi
jmp 0x1f5117
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq