// File: /workspace/github_c_makefile_star2_O1/DReichLab[P]adna/sam.c
// Function: swap_data
static void swap_data(const bam1_core_t *c, int l_data, uint8_t *data)
{
	uint8_t *s;
	uint32_t *cigar = (uint32_t*)(data + c->l_qname);
	int i;
	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) ed_swap_4p(&cigar[i]);
	while (s < data + l_data) {
		uint8_t type;
		s += 2; // skip key
		type = toupper(*s); ++s; // skip type
		if (type == 'C' || type == 'A') ++s;
		else if (type == 'S') { ed_swap_2p(s); s += 2; }
		else if (type == 'I' || type == 'F') { ed_swap_4p(s); s += 4; }
		else if (type == 'D') { ed_swap_8p(s); s += 8; }
		else if (type == 'Z' || type == 'H') { while (*s) ++s; ++s; }
		else if (type == 'B') {
			int32_t n, Bsize = aux_type2size(*s);
			memcpy(&n, s + 1, 4);
			if (Bsize == 2) {
				for (i = 0; i < n; i += 2)
					ed_swap_2p(s + 5 + i);
			} else if (Bsize == 4) {
				for (i = 0; i < n; i += 4)
					ed_swap_4p(s + 5 + i);
			}
			ed_swap_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 0x9075
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 0x9061
movslq %esi, %rax
addq %rax, %rbx
cmpq %rbx, %r14
jae 0x91fc
callq 0x2030
movq (%rax), %rax
leaq 0x5349(%rip), %rcx      # 0xe3dc
movabsq $0x120000001, %rdx      # imm = 0x120000001
movabsq $0x400000005, %rsi      # imm = 0x400000005
movzbl 0x2(%r14), %edi
movl (%rax,%rdi,4), %r8d
movl %r8d, %edi
andl $0xfd, %edi
cmpl $0x41, %edi
jne 0x90c7
addq $0x4, %r14
jmp 0x918d
leaq 0x3(%r14), %rdi
movzbl %r8b, %r9d
leal -0x42(%r9), %r8d
cmpl $0x7, %r8d
ja 0x90f6
movslq (%rcx,%r8,4), %r8
addq %rcx, %r8
jmpq *%r8
movl 0x3(%r14), %edi
bswapl %edi
movl %edi, 0x3(%r14)
addq $0x7, %r14
jmp 0x918d
cmpl $0x53, %r9d
je 0x9183
movq %rdi, %r8
cmpl $0x5a, %r9d
je 0x9174
jmp 0x9190
movq 0x3(%r14), %rdi
bswapq %rdi
movq %rdi, 0x3(%r14)
addq $0xb, %r14
jmp 0x918d
movzbl (%rdi), %r8d
leal -0x41(%r8), %r10d
cmpl $0x22, %r10d
ja 0x91c3
movl $0x1, %r9d
btq %r10, %rsi
jae 0x91c3
movl 0x4(%r14), %r8d
cmpl $0x2, %r9d
je 0x919e
cmpl $0x4, %r9d
jne 0x91b6
testl %r8d, %r8d
jle 0x91b6
xorl %r9d, %r9d
movl 0x8(%r14,%r9), %r10d
bswapl %r10d
movl %r10d, 0x8(%r14,%r9)
addq $0x4, %r9
cmpq %r8, %r9
jb 0x9159
jmp 0x91b6
movq %rdi, %r8
leaq 0x1(%r8), %rdi
cmpb $0x0, (%r8)
movq %rdi, %r8
jne 0x9174
jmp 0x9190
rolw $0x8, 0x3(%r14)
addq $0x5, %r14
movq %r14, %rdi
movq %rdi, %r14
cmpq %rbx, %rdi
jb 0x90a7
jmp 0x91fc
testl %r8d, %r8d
jle 0x91b6
xorl %r9d, %r9d
rolw $0x8, 0x8(%r14,%r9)
addq $0x2, %r9
cmpq %r8, %r9
jb 0x91a6
movl 0x4(%r14), %r8d
bswapl %r8d
movl %r8d, 0x4(%r14)
jmp 0x9190
movl %r8d, %r10d
andb $-0x21, %r10b
movl $0x2, %r9d
cmpb $0x53, %r10b
je 0x9141
addl $-0x49, %r8d
cmpl $0x20, %r8d
ja 0x91f4
movl $0x4, %r9d
btq %r8, %rdx
jb 0x9141
xorl %r9d, %r9d
jmp 0x9141
addq $0x8, %rsp
popq %rbx
popq %r14
retq