// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%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, -0x30(%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, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
cmpl %ecx, %eax
jae 0x1bde2
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x1b1a0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1bdb1
jmp 0x1bde4
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0xc(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x1c025
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movzbl (%rax), %edi
callq 0x1fe60
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
incq %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x4c(%rbp)
subl $0x1, %eax
je 0x1be72
jmp 0x1be2f
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x1be83
jmp 0x1be39
movl -0x4c(%rbp), %eax
subl $0x4, %eax
je 0x1be9d
jmp 0x1be43
movl -0x4c(%rbp), %eax
subl $0x8, %eax
je 0x1beb7
jmp 0x1be4d
movl -0x4c(%rbp), %eax
subl $0x42, %eax
je 0x1befb
jmp 0x1be5b
movl -0x4c(%rbp), %eax
subl $0x48, %eax
je 0x1bed1
jmp 0x1be65
movl -0x4c(%rbp), %eax
subl $0x5a, %eax
je 0x1bed1
jmp 0x1c020
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c020
movq -0x28(%rbp), %rdi
callq 0x22d90
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c020
movq -0x28(%rbp), %rdi
callq 0x1b1a0
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c020
movq -0x28(%rbp), %rdi
callq 0x22dc0
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c020
jmp 0x1bed3
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1beea
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1bed3
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c020
movq -0x28(%rbp), %rax
movzbl (%rax), %edi
callq 0x1fe60
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1bf30
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1b1a0
jmp 0x1bf42
movq -0x28(%rbp), %rdi
callq 0x1b1a0
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x7, %eax
ja 0x1c01e
movq -0x58(%rbp), %rax
leaq 0x5f2eb(%rip), %rcx     # 0x7b258
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x1c01e
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x1bfba
movq -0x28(%rbp), %rdi
callq 0x22d90
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
jmp 0x1bf92
jmp 0x1c01e
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x1bfeb
movq -0x28(%rbp), %rdi
callq 0x1b1a0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
jmp 0x1bfc3
jmp 0x1c01e
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x1c01c
movq -0x28(%rbp), %rdi
callq 0x22dc0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x1bff4
jmp 0x1c01e
jmp 0x1c020
jmp 0x1bde4
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)