// File: karel-brinda[P]ococo/ext/htslib/sam.c
// Function: bam_read1
int bam_read1(BGZF *fp, bam1_t *b)
{
    bam1_core_t *c = &b->core;
    int32_t block_len, ret, i;
    uint32_t x[8];
    if ((ret = bgzf_read(fp, &block_len, 4)) != 4) {
        if (ret == 0) return -1; // normal end-of-file
        else return -2; // truncated
    }
    if (bgzf_read(fp, x, 32) != 32) return -3;
    if (fp->is_be) {
        ed_swap_4p(&block_len);
        for (i = 0; i < 8; ++i) ed_swap_4p(x + i);
    }
    c->tid = x[0]; c->pos = x[1];
    c->bin = x[2]>>16; c->qual = x[2]>>8&0xff; c->l_qname = x[2]&0xff;
    c->flag = x[3]>>16; c->n_cigar = x[3]&0xffff;
    c->l_qseq = x[4];
    c->mtid = x[5]; c->mpos = x[6]; c->isize = x[7];
    b->l_data = block_len - 32;
    if (b->l_data < 0 || c->l_qseq < 0 || c->l_qname < 1) return -4;
    if ((char *)bam_get_aux(b) - (char *)b->data > b->l_data)
        return -4;
    if (b->m_data < b->l_data) {
        b->m_data = b->l_data;
        kroundup32(b->m_data);
        b->data = (uint8_t*)realloc(b->data, b->m_data);
        if (!b->data)
            return -4;
    }
    if (bgzf_read(fp, b->data, b->l_data) != b->l_data) return -4;
    //b->l_aux = b->l_data - c->n_cigar * 4 - c->l_qname - c->l_qseq - (c->l_qseq+1)/2;
    if (fp->is_be) swap_data(c, b->l_data, b->data, 0);
    return 4 + block_len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0x4, %edx
callq 0x64bb0
movl %eax, -0x28(%rbp)
cmpl $0x4, %eax
je 0x1b970
cmpl $0x0, -0x28(%rbp)
jne 0x1b964
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1bcfb
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x1bcfb
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
callq 0x64bb0
cmpq $0x20, %rax
je 0x1b994
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x1bcfb
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x12, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x1b9dc
leaq -0x24(%rbp), %rdi
callq 0x1b1a0
movl $0x0, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jge 0x1b9da
leaq -0x50(%rbp), %rdi
movslq -0x2c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x1b1a0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1b9b5
jmp 0x1b9dc
movl -0x50(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x48(%rbp), %ecx
shrl $0x10, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
andq $-0x10000, %rcx         # imm = 0xFFFF0000
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x48(%rbp), %ecx
shrl $0x8, %ecx
andl $0xff, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xff, %rdx
shlq $0x10, %rdx
andq $-0xff0001, %rcx        # imm = 0xFF00FFFF
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x48(%rbp), %ecx
andl $0xff, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xff, %rdx
shlq $0x18, %rdx
movabsq $-0xff000001, %rsi      # imm = 0xFFFFFFFF00FFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x44(%rbp), %ecx
shrl $0x10, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x20, %rdx
movabsq $-0xffff00000001, %rsi  # imm = 0xFFFF0000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x44(%rbp), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movq -0x20(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x8(%rax), %rcx
andq $0xffff, %rdx           # imm = 0xFFFF
shlq $0x30, %rdx
movabsq $0xffffffffffff, %rsi   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl -0x24(%rbp), %ecx
subl $0x20, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jl 0x1bb40
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x1bb40
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x18, %rax
andq $0xff, %rax
cmpl $0x1, %eax
jge 0x1bb4c
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x1bcfb
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
jle 0x1bbc3
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x1bcfb
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x1bc98
movq -0x18(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
sarl %ecx
movq -0x18(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x2, %ecx
movq -0x18(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x4, %ecx
movq -0x18(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x8, %ecx
movq -0x18(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x10, %ecx
movq -0x18(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x24(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x1bc96
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x1bcfb
jmp 0x1bc98
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x18(%rbp), %rax
movslq 0x20(%rax), %rdx
callq 0x64bb0
movq -0x18(%rbp), %rcx
movslq 0x20(%rcx), %rcx
cmpq %rcx, %rax
je 0x1bcc7
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x1bcfb
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x12, %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x1bcf2
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
xorl %ecx, %ecx
callq 0x1bd10
movl -0x24(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)