// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
addl $0x20, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
andq $0xffff, %rax           # imm = 0xFFFF
shll $0x10, %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x10, %rcx
andq $0xff, %rcx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0xffff, %rax           # imm = 0xFFFF
shll $0x10, %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %eax
addl $0x4, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x65630
cmpl $0x0, %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x12, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x1c1b5
movl $0x0, -0x4c(%rbp)
cmpl $0x8, -0x4c(%rbp)
jge 0x1c159
leaq -0x40(%rbp), %rdi
movslq -0x4c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x1b1a0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1c134
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x1c196
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1b1a0
movq -0x58(%rbp), %rdi
movq %rax, %rsi
movl $0x4, %edx
callq 0x65700
cmpq $0x0, %rax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
movl $0x1, %ecx
callq 0x1bd10
jmp 0x1c1de
cmpl $0x0, -0x50(%rbp)
je 0x1c1dc
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
movl $0x4, %edx
callq 0x65700
cmpq $0x0, %rax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
jmp 0x1c1de
cmpl $0x0, -0x50(%rbp)
je 0x1c205
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x20, %edx
callq 0x65700
cmpq $0x0, %rax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x1c233
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x20(%rax), %rdx
callq 0x65700
cmpq $0x0, %rax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x12, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x1c25e
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
xorl %ecx, %ecx
callq 0x1bd10
cmpl $0x0, -0x50(%rbp)
je 0x1c26f
movl -0x44(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1c279
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x5c(%rbp)
jmp 0x1c279
movl -0x5c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)