// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/sam.c
// Function: swap_data
static void swap_data(const bam1_core_t *c, int l_data, uint8_t *data, int is_host)
{
    uint8_t *s;
    uint32_t *cigar = (uint32_t*)(data + c->l_qname);
    uint32_t i, n;
    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) {
        int size;
        s += 2; // skip key
        size = aux_type2size(*s); ++s; // skip type
        switch (size) {
        case 1: ++s; break;
        case 2: ed_swap_2p(s); s += 2; break;
        case 4: ed_swap_4p(s); s += 4; break;
        case 8: ed_swap_8p(s); s += 8; break;
        case 'Z':
        case 'H':
            while (*s) ++s;
            ++s;
            break;
        case 'B':
            size = aux_type2size(*s); ++s;
            if (is_host) memcpy(&n, s, 4), ed_swap_4p(s);
            else ed_swap_4p(s), memcpy(&n, s, 4);
            s += 4;
            switch (size) {
            case 1: s += n; break;
            case 2: for (i = 0; i < n; ++i, s += 2) ed_swap_2p(s); break;
            case 4: for (i = 0; i < n; ++i, s += 4) ed_swap_4p(s); break;
            case 8: for (i = 0; i < n; ++i, s += 8) ed_swap_8p(s); break;
            }
            break;
        }
    }
}

// Assembly:
movq 0x8(%rdi), %r9
movl %r9d, %r8d
shrl $0x18, %r8d
addq %rdx, %r8
shrq $0x30, %r9
leaq (%r8,%r9,4), %r10
movslq 0x10(%rdi), %rax
addq %rax, %r10
leal 0x1(%rax), %r11d
shrl $0x1f, %r11d
addl %r11d, %eax
incl %eax
sarl %eax
cltq
addq %r10, %rax
testq %r9, %r9
je 0x14b64
xorl %r9d, %r9d
movl (%r8,%r9,4), %r10d
bswapl %r10d
movl %r10d, (%r8,%r9,4)
incq %r9
movzwl 0xe(%rdi), %r10d
cmpq %r10, %r9
jb 0x14b4c
movslq %esi, %rsi
addq %rsi, %rdx
cmpq %rdx, %rax
jae 0x14d47
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
leaq 0x3c554(%rip), %rsi     # 0x510d4
leaq 0x3c58d(%rip), %rdi     # 0x51114
leaq 0x3c5c6(%rip), %r8      # 0x51154
leaq 0x3c5a3(%rip), %r9      # 0x51138
leaq 0x3c55c(%rip), %r10     # 0x510f8
movzbl 0x2(%rax), %r11d
cmpl $0x59, %r11d
jg 0x14bb9
leal -0x41(%r11), %ebx
cmpl $0x8, %ebx
ja 0x14c21
movslq (%rsi,%rbx,4), %rbx
addq %rsi, %rbx
jmpq *%rbx
leal -0x63(%r11), %ebx
cmpl $0x6, %ebx
ja 0x14be3
movslq (%r10,%rbx,4), %r11
addq %r10, %r11
jmpq *%r11
movl 0x3(%rax), %r11d
bswapl %r11d
movl %r11d, 0x3(%rax)
addq $0x7, %rax
jmp 0x14c3c
addq $0x4, %rax
jmp 0x14c3c
cmpl $0x5a, %r11d
je 0x14bfa
cmpl $0x73, %r11d
jne 0x14c27
rolw $0x8, 0x3(%rax)
addq $0x5, %rax
jmp 0x14c3c
leaq 0x3(%rax), %rbx
cmpl $0x42, %r11d
je 0x14c4a
cmpl $0x5a, %r11d
je 0x14c13
movq %rbx, %rax
cmpl $0x48, %r11d
jne 0x14c3c
leaq 0x1(%rbx), %rax
cmpb $0x0, (%rbx)
movq %rax, %rbx
jne 0x14c13
jmp 0x14c3c
cmpl $0x53, %r11d
je 0x14bef
addq $0x3, %rax
jmp 0x14c3c
movq 0x3(%rax), %r11
bswapq %r11
movq %r11, 0x3(%rax)
addq $0xb, %rax
cmpq %rdx, %rax
jb 0x14b9c
jmp 0x14d41
movb (%rbx), %r11b
movzbl %r11b, %r14d
movb $0x1, %bl
cmpl $0x59, %r14d
jg 0x14c72
leal -0x41(%r14), %r15d
cmpl $0x8, %r15d
ja 0x14c9d
movslq (%rdi,%r15,4), %r14
addq %rdi, %r14
jmpq *%r14
movl %r11d, %ebx
jmp 0x14ca9
leal -0x63(%r14), %r15d
cmpl $0x6, %r15d
ja 0x14c8a
movslq (%r9,%r15,4), %r11
addq %r9, %r11
jmpq *%r11
movb $0x4, %bl
jmp 0x14ca9
movl %r11d, %ebx
cmpl $0x5a, %r14d
je 0x14ca9
cmpl $0x73, %r14d
jne 0x14ca3
movb $0x2, %bl
jmp 0x14ca9
cmpl $0x53, %r14d
je 0x14c99
xorl %ebx, %ebx
jmp 0x14ca9
movb $0x8, %bl
testl %ecx, %ecx
je 0x14cb8
movl 0x4(%rax), %r11d
movl %r11d, %ebp
bswapl %ebp
jmp 0x14cc0
movl 0x4(%rax), %ebp
bswapl %ebp
movl %ebp, %r11d
movl %ebp, 0x4(%rax)
addq $0x8, %rax
movzbl %bl, %ebx
decl %ebx
cmpl $0x7, %ebx
ja 0x14c3c
movslq (%r8,%rbx,4), %rbx
addq %r8, %rbx
jmpq *%rbx
movl %r11d, %r11d
addq %r11, %rax
jmp 0x14c3c
testl %r11d, %r11d
je 0x14c3c
movl (%rax), %ebx
bswapl %ebx
movl %ebx, (%rax)
addq $0x4, %rax
decl %r11d
jne 0x14cf2
jmp 0x14c3c
testl %r11d, %r11d
je 0x14c3c
rolw $0x8, (%rax)
addq $0x2, %rax
decl %r11d
jne 0x14d0f
jmp 0x14c3c
testl %r11d, %r11d
je 0x14c3c
movq (%rax), %rbx
bswapq %rbx
movq %rbx, (%rax)
addq $0x8, %rax
decl %r11d
jne 0x14d2a
jmp 0x14c3c
popq %rbx
popq %r14
popq %r15
popq %rbp
retq