// File: /workspace/github_cpp_makefile_star2_O1/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), %r8
movl %r8d, %eax
shrl $0x18, %eax
addq %rdx, %rax
shrq $0x30, %r8
leaq (%rax,%r8,4), %r9
movslq 0x10(%rdi), %r10
addq %r10, %r9
leal 0x1(%r10), %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
incl %r10d
sarl %r10d
movslq %r10d, %r11
addq %r9, %r11
testq %r8, %r8
je 0x14b61
xorl %r8d, %r8d
movl (%rax,%r8,4), %r9d
bswapl %r9d
movl %r9d, (%rax,%r8,4)
incq %r8
movzwl 0xe(%rdi), %r9d
cmpq %r9, %r8
jb 0x14b49
movslq %esi, %rax
addq %rax, %rdx
cmpq %rdx, %r11
jae 0x14d98
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
leaq 0x3e527(%rip), %rax     # 0x530a4
leaq 0x3e560(%rip), %rsi     # 0x530e4
leaq 0x3e579(%rip), %rdi     # 0x53104
leaq 0x3e5b2(%rip), %r8      # 0x53144
leaq 0x3e58f(%rip), %r9      # 0x53128
leaq 0x3e528(%rip), %r10     # 0x530c8
movb 0x2(%r11), %bl
movzbl %bl, %r14d
movb $0x1, %bpl
cmpl $0x59, %r14d
jg 0x14bc9
leal -0x41(%r14), %r15d
cmpl $0x8, %r15d
ja 0x14bf4
movslq (%rax,%r15,4), %r14
addq %rax, %r14
jmpq *%r14
movl %ebx, %ebp
jmp 0x14c01
leal -0x63(%r14), %r15d
cmpl $0x6, %r15d
ja 0x14be1
movslq (%r10,%r15,4), %rbx
addq %r10, %rbx
jmpq *%rbx
movb $0x4, %bpl
jmp 0x14c01
movl %ebx, %ebp
cmpl $0x5a, %r14d
je 0x14c01
cmpl $0x73, %r14d
jne 0x14bfa
movb $0x2, %bpl
jmp 0x14c01
cmpl $0x53, %r14d
je 0x14bef
xorl %ebp, %ebp
jmp 0x14c01
movb $0x8, %bpl
leaq 0x3(%r11), %rbx
movzbl %bpl, %r14d
cmpl $0x41, %r14d
jg 0x14c2c
decl %r14d
cmpl $0x7, %r14d
ja 0x14caa
movslq (%rsi,%r14,4), %r14
addq %rsi, %r14
jmpq *%r14
addq $0x4, %r11
jmp 0x14c6e
cmpl $0x42, %r14d
je 0x14c73
cmpl $0x5a, %r14d
je 0x14c9a
movq %rbx, %r11
cmpl $0x48, %r14d
je 0x14c9d
jmp 0x14caa
movl 0x3(%r11), %ebx
bswapl %ebx
movl %ebx, 0x3(%r11)
addq $0x7, %r11
jmp 0x14c6e
movq 0x3(%r11), %rbx
bswapq %rbx
movq %rbx, 0x3(%r11)
addq $0xb, %r11
jmp 0x14c6e
rolw $0x8, 0x3(%r11)
addq $0x5, %r11
movq %r11, %rbx
jmp 0x14caa
movb (%rbx), %bpl
movzbl %bpl, %r14d
movb $0x1, %bl
cmpl $0x59, %r14d
jg 0x14cbb
leal -0x41(%r14), %r15d
cmpl $0x8, %r15d
ja 0x14ce5
movslq (%rdi,%r15,4), %r14
addq %rdi, %r14
jmpq *%r14
movl %ebp, %ebx
jmp 0x14cf1
movq %rbx, %r11
leaq 0x1(%r11), %rbx
cmpb $0x0, (%r11)
movq %rbx, %r11
jne 0x14c9d
movq %rbx, %r11
cmpq %rdx, %rbx
jb 0x14ba0
jmp 0x14d92
leal -0x63(%r14), %r15d
cmpl $0x6, %r15d
ja 0x14cd3
movslq (%r9,%r15,4), %r14
addq %r9, %r14
jmpq *%r14
movb $0x4, %bl
jmp 0x14cf1
movl %ebp, %ebx
cmpl $0x5a, %r14d
je 0x14cf1
cmpl $0x73, %r14d
jne 0x14ceb
movb $0x2, %bl
jmp 0x14cf1
cmpl $0x53, %r14d
je 0x14ce1
xorl %ebx, %ebx
jmp 0x14cf1
movb $0x8, %bl
testl %ecx, %ecx
je 0x14d01
movl 0x4(%r11), %ebp
movl %ebp, %r14d
bswapl %r14d
jmp 0x14d0b
movl 0x4(%r11), %r14d
bswapl %r14d
movl %r14d, %ebp
movl %r14d, 0x4(%r11)
addq $0x8, %r11
movzbl %bl, %ebx
decl %ebx
cmpl $0x7, %ebx
ja 0x14c6e
movslq (%r8,%rbx,4), %rbx
addq %r8, %rbx
jmpq *%rbx
movl %ebp, %ebx
addq %rbx, %r11
jmp 0x14c6e
movq %r11, %rbx
testl %ebp, %ebp
je 0x14caa
movl (%rbx), %r11d
bswapl %r11d
movl %r11d, (%rbx)
addq $0x4, %rbx
decl %ebp
jne 0x14d3f
jmp 0x14caa
movq %r11, %rbx
testl %ebp, %ebp
je 0x14caa
rolw $0x8, (%rbx)
addq $0x2, %rbx
decl %ebp
jne 0x14d60
jmp 0x14caa
movq %r11, %rbx
testl %ebp, %ebp
je 0x14caa
movq (%rbx), %r11
bswapq %r11
movq %r11, (%rbx)
addq $0x8, %rbx
decl %ebp
jne 0x14d7c
jmp 0x14caa
popq %rbx
popq %r14
popq %r15
popq %rbp
retq