// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jge 0xd480
movq -0x28(%rbp), %rdi
movslq -0x2c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0xcb00
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd44e
jmp 0xd482
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0xc(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0xd642
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzbl (%rax), %edi
callq 0x20d0
movb %al, -0x2d(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movzbl -0x2d(%rbp), %eax
cmpl $0x43, %eax
je 0xd4d3
movzbl -0x2d(%rbp), %eax
cmpl $0x41, %eax
jne 0xd4e4
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xd63d
movzbl -0x2d(%rbp), %eax
cmpl $0x53, %eax
jne 0xd507
movq -0x20(%rbp), %rdi
callq 0x12920
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
jmp 0xd63b
movzbl -0x2d(%rbp), %eax
cmpl $0x49, %eax
je 0xd519
movzbl -0x2d(%rbp), %eax
cmpl $0x46, %eax
jne 0xd533
movq -0x20(%rbp), %rdi
callq 0xcb00
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
jmp 0xd639
movzbl -0x2d(%rbp), %eax
cmpl $0x44, %eax
jne 0xd556
movq -0x20(%rbp), %rdi
callq 0x12950
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
jmp 0xd637
movzbl -0x2d(%rbp), %eax
cmpl $0x5a, %eax
je 0xd568
movzbl -0x2d(%rbp), %eax
cmpl $0x48, %eax
jne 0xd592
jmp 0xd56a
movq -0x20(%rbp), %rax
cmpb $0x0, (%rax)
je 0xd581
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xd56a
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xd635
movzbl -0x2d(%rbp), %eax
cmpl $0x42, %eax
jne 0xd633
movq -0x20(%rbp), %rax
movzbl (%rax), %edi
callq 0x12980
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl 0x1(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x2, -0x38(%rbp)
jne 0xd5ee
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xd5ec
movq -0x20(%rbp), %rdi
addq $0x5, %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
callq 0x12920
movl -0x2c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd5c5
jmp 0xd626
cmpl $0x4, -0x38(%rbp)
jne 0xd624
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xd622
movq -0x20(%rbp), %rdi
addq $0x5, %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
callq 0xcb00
movl -0x2c(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd5fb
jmp 0xd624
jmp 0xd626
movq -0x20(%rbp), %rdi
addq $0x1, %rdi
callq 0xcb00
jmp 0xd635
jmp 0xd637
jmp 0xd639
jmp 0xd63b
jmp 0xd63d
jmp 0xd482
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)