// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/sam.c
// Function: bam_write1
int bam_write1(BGZF *fp, const bam1_t *b)
{
    const bam1_core_t *c = &b->core;
    uint32_t x[8], block_len = b->l_data + 32, y;
    int i, ok;
    x[0] = c->tid;
    x[1] = c->pos;
    x[2] = (uint32_t)c->bin<<16 | c->qual<<8 | c->l_qname;
    x[3] = (uint32_t)c->flag<<16 | c->n_cigar;
    x[4] = c->l_qseq;
    x[5] = c->mtid;
    x[6] = c->mpos;
    x[7] = c->isize;
    ok = (bgzf_flush_try(fp, 4 + block_len) >= 0);
    if (fp->is_be) {
        for (i = 0; i < 8; ++i) ed_swap_4p(x + i);
        y = block_len;
        if (ok) ok = (bgzf_write(fp, ed_swap_4p(&y), 4) >= 0);
        swap_data(c, b->l_data, b->data, 1);
    } else {
        if (ok) ok = (bgzf_write(fp, &block_len, 4) >= 0);
    }
    if (ok) ok = (bgzf_write(fp, x, 32) >= 0);
    if (ok) ok = (bgzf_write(fp, b->data, b->l_data) >= 0);
    if (fp->is_be) swap_data(c, b->l_data, b->data, 0);
    return ok? 4 + block_len : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x20(%rsi), %esi
leal 0x20(%rsi), %ebp
movl %ebp, 0x8(%rsp)
movq (%rbx), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rbx), %rax
movl %eax, %ecx
shll $0x10, %ecx
movl %eax, %edx
shrl $0x8, %edx
andl $0xff00, %edx           # imm = 0xFF00
orl %ecx, %edx
movl %eax, %ecx
shrl $0x18, %ecx
orl %edx, %ecx
movl %ecx, 0x18(%rsp)
movq %rax, %rcx
shrq $0x10, %rcx
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
shrq $0x30, %rax
orl %ecx, %eax
movl %eax, 0x1c(%rsp)
movdqu 0x10(%rbx), %xmm0
movdqa %xmm0, 0x20(%rsp)
addl $0x24, %esi
callq 0x44033
testb $0xc, 0x2(%r14)
je 0x14e25
xorl %ecx, %ecx
pxor %xmm0, %xmm0
movdqa 0x10(%rsp,%rcx,4), %xmm1
movdqa %xmm1, %xmm2
punpckhbw %xmm0, %xmm2    # xmm2 = xmm2[8],xmm0[8],xmm2[9],xmm0[9],xmm2[10],xmm0[10],xmm2[11],xmm0[11],xmm2[12],xmm0[12],xmm2[13],xmm0[13],xmm2[14],xmm0[14],xmm2[15],xmm0[15]
pshuflw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm2, %xmm2     # xmm2 = xmm2[0,1,2,3,7,6,5,4]
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
pshuflw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[3,2,1,0,4,5,6,7]
pshufhw $0x1b, %xmm1, %xmm1     # xmm1 = xmm1[0,1,2,3,7,6,5,4]
packuswb %xmm2, %xmm1
movdqa %xmm1, 0x10(%rsp,%rcx,4)
addq $0x4, %rcx
cmpq $0x8, %rcx
jne 0x14dc2
movl %ebp, 0xc(%rsp)
testl %eax, %eax
js 0x14e46
bswapl %ebp
leaq 0xc(%rsp), %rsi
movl %ebp, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
xorl %ebp, %ebp
testq %rax, %rax
setns %bpl
jmp 0x14e48
testl %eax, %eax
js 0x14e93
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x44082
xorl %ebp, %ebp
testq %rax, %rax
setns %bpl
jmp 0x14e5c
xorl %ebp, %ebp
movl 0x20(%rbx), %esi
movq 0x28(%rbx), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0x14b13
movb $0x1, %r15b
testl %ebp, %ebp
je 0x14e96
leaq 0x10(%rsp), %rsi
movl $0x20, %edx
movq %r14, %rdi
callq 0x44082
testq %rax, %rax
js 0x14e96
movq 0x28(%rbx), %rsi
movslq 0x20(%rbx), %rdx
movq %r14, %rdi
callq 0x44082
movq %rax, %r15
shrq $0x3f, %r15
jmp 0x14e96
movb $0x1, %r15b
testb $0xc, 0x2(%r14)
je 0x14eae
movl 0x20(%rbx), %esi
movq 0x28(%rbx), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x14b13
movl 0x8(%rsp), %ecx
addl $0x4, %ecx
testb %r15b, %r15b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %ecx, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq