// File: karel-brinda[P]ococo/ext/htslib/sam.c
// Function: sam_read1
int sam_read1(htsFile *fp, bam_hdr_t *h, bam1_t *b)
{
    switch (fp->format.format) {
    case bam: {
        int r = bam_read1(fp->fp.bgzf, b);
        if (r >= 0) {
            if (b->core.tid  >= h->n_targets || b->core.tid  < -1 ||
                b->core.mtid >= h->n_targets || b->core.mtid < -1)
                return -3;
        }
        return r;
        }

    case cram: {
        int ret = cram_get_bam_seq(fp->fp.cram, &b);
        return ret >= 0
            ? ret
            : (cram_eof(fp->fp.cram) ? -1 : -2);
    }

    case sam: {
        int ret;
err_recover:
        if (fp->line.l == 0) {
            ret = hts_getline(fp, KS_SEP_LINE, &fp->line);
            if (ret < 0) return -1;
        }
        ret = sam_parse1(&fp->line, h, b);
        fp->line.l = 0;
        if (ret < 0) {
            if (hts_verbose >= 1)
                fprintf(stderr, "[W::%s] parse error at line %lld\n", __func__, (long long)fp->lineno);
            if (h->ignore_sam_err) goto err_recover;
        }
        return ret;
        }

    default:
        abort();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x30(%rbp)
subl $0x3, %eax
je 0x1f152
jmp 0x1f089
movl -0x30(%rbp), %eax
subl $0x4, %eax
je 0x1f0a0
jmp 0x1f093
movl -0x30(%rbp), %eax
subl $0x6, %eax
je 0x1f103
jmp 0x1f1ff
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1b920
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1f0f8
movq -0x20(%rbp), %rax
movl (%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1f0ea
movq -0x20(%rbp), %rax
cmpl $-0x1, (%rax)
jl 0x1f0ea
movq -0x20(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x1f0ea
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x14(%rax)
jge 0x1f0f6
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x1f204
jmp 0x1f0f8
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f204
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2e9f0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x1f125
movl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x1f147
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x52a00
movl %eax, %edx
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f204
jmp 0x1f154
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1f189
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x10, %rdx
movl $0x2, %esi
callq 0x145e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x1f187
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1f204
jmp 0x1f189
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x1d840
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
cmpl $0x0, -0x2c(%rbp)
jge 0x1f1f7
leaq 0x6b426(%rip), %rax     # 0x8a5e0
cmpl $0x1, (%rax)
jl 0x1f1e6
movq 0x6ae0a(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x5c579(%rip), %rsi     # 0x7b751
leaq 0x5c594(%rip), %rdx     # 0x7b773
movb $0x0, %al
callq 0x4830
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x1f1f5
jmp 0x1f154
jmp 0x1f1f7
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x1f204
callq 0x42e0
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)