// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: sam_read1_sam
static inline int sam_read1_sam(htsFile *fp, sam_hdr_t *h, bam1_t *b) {
    int ret;

    // Consume 1st line after header parsing as it wasn't using peek
    if (fp->line.l != 0) {
        ret = sam_parse1(&fp->line, h, b);
        fp->line.l = 0;
        return ret;
    }

    if (fp->state) {
        SAM_state *fd = (SAM_state *)fp->state;

        if (fp->format.compression == bgzf && fp->fp.bgzf->seeked) {
            // We don't support multi-threaded SAM parsing with seeks yet.
            int ret;
            if ((ret = sam_state_destroy(fp)) < 0) {
                errno = -ret;
                return -2;
            }
            if (bgzf_seek(fp->fp.bgzf, fp->fp.bgzf->seeked, SEEK_SET) < 0)
                return -2;
            fp->fp.bgzf->seeked = 0;
            goto err_recover;
        }

        if (!fd->h) {
            fd->h = h;
            fd->h->ref_count++;
            // Ensure hrecs is initialised now as we don't want multiple
            // threads trying to do this simultaneously.
            if (!fd->h->hrecs && sam_hdr_fill_hrecs(fd->h) < 0)
                return -2;

            // We can only do this once we've got a header
            if (pthread_create(&fd->dispatcher, NULL, sam_dispatcher_read,
                               fp) != 0)
                return -2;
            fd->dispatcher_set = 1;
        }

        if (fd->h != h) {
            hts_log_error("SAM multi-threaded decoding does not support changing header");
            return -2;
        }

        sp_bams *gb = fd->curr_bam;
        if (!gb) {
            if (fd->errcode) {
                // In case reader failed
                errno = fd->errcode;
                return -2;
            }

            pthread_mutex_lock(&fd->command_m);
            int cmd = fd->command;
            pthread_mutex_unlock(&fd->command_m);
            if (cmd == SAM_AT_EOF)
                return -1;

            hts_tpool_result *r = hts_tpool_next_result_wait(fd->q);
            if (!r)
                return -2;
            fd->curr_bam = gb = (sp_bams *)hts_tpool_result_data(r);
            hts_tpool_delete_result(r, 0);
        }
        if (!gb) {
            pthread_mutex_lock(&fd->command_m);
            fd->command = SAM_AT_EOF;
            pthread_mutex_unlock(&fd->command_m);
            return fd->errcode ? -2 : -1;
        }
        bam1_t *b_array = (bam1_t *)gb->bams;
        if (fd->curr_idx < gb->nbams)
            if (!bam_copy1(b, &b_array[fd->curr_idx++]))
                return -2;
        if (fd->curr_idx == gb->nbams) {
            pthread_mutex_lock(&fd->lines_m);
            gb->next = fd->bams;
            fd->bams = gb;
            pthread_mutex_unlock(&fd->lines_m);

            fd->curr_bam = NULL;
            fd->curr_idx = 0;
        // Consider prefetching next record?  I.e.
        // } else {
        //     __builtin_prefetch(&b_array[fd->curr_idx], 0, 3);
        }

        ret = 0;

    } else  {
    err_recover:
        ret = hts_getline(fp, KS_SEP_LINE, &fp->line);
        if (ret < 0) return ret;

        ret = sam_parse1(&fp->line, h, b);
        fp->line.l = 0;
        if (ret < 0) {
            hts_log_warning("Parse error at line %lld", (long long)fp->lineno);
            if (h && h->ignore_sam_err) goto err_recover;
        }
    }

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x3cd0e
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39630
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3d0dc
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x3d047
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x54(%rax)
jne 0x3cdb7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x68(%rax)
je 0x3cdb7
movq -0x10(%rbp), %rdi
callq 0x35580
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jge 0x3cd75
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x5c(%rbp)
callq 0x4050
movl -0x5c(%rbp), %ecx
movl %ecx, (%rax)
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x68(%rax), %rsi
xorl %edx, %edx
callq 0x10a80
cmpq $0x0, %rax
jge 0x3cda2
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq $0x0, 0x68(%rax)
jmp 0x3d049
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3ce3f
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movl 0x40(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x40(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x3ce07
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0xd7490
cmpl $0x0, %eax
jge 0x3ce07
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x30(%rbp), %rdi
addq $0x48, %rdi
movq -0x10(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0xa0b2(%rip), %rdx      # 0x46ed0
callq 0x4910
cmpl $0x0, %eax
je 0x3ce34
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x30(%rbp), %rax
movl $0x1, 0x50(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x3ce72
movl $0x1, %edi
leaq 0xb5dc7(%rip), %rsi     # 0xf2c1f
leaq 0xb5347(%rip), %rdx     # 0xf21a6
movb $0x0, %al
callq 0x1b030
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x30(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x3cf39
movq -0x30(%rbp), %rax
cmpl $0x0, 0xd4(%rax)
je 0x3ceb9
movq -0x30(%rbp), %rax
movl 0xd4(%rax), %eax
movl %eax, -0x60(%rbp)
callq 0x4050
movl -0x60(%rbp), %ecx
movl %ecx, (%rax)
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x30(%rbp), %rdi
addq $0x78, %rdi
callq 0x4730
movq -0x30(%rbp), %rax
movl 0xd0(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rdi
addq $0x78, %rdi
callq 0x4330
cmpl $0x3, -0x44(%rbp)
jne 0x3cef2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3d0dc
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x4cf90
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x3cf16
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
movq -0x50(%rbp), %rdi
callq 0x4d460
movq %rax, %rcx
movq %rcx, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x4d410
cmpq $0x0, -0x40(%rbp)
jne 0x3cf8a
movq -0x30(%rbp), %rdi
addq $0x78, %rdi
callq 0x4730
movq -0x30(%rbp), %rax
movl $0x3, 0xd0(%rax)
movq -0x30(%rbp), %rdi
addq $0x78, %rdi
callq 0x4330
movq -0x30(%rbp), %rax
movl 0xd4(%rax), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x3d0dc
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl 0x70(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x3cfdf
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rcx
movl 0x70(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x70(%rcx)
cltq
imulq $0x50, %rax, %rax
addq %rax, %rsi
callq 0x33080
cmpq $0x0, %rax
jne 0x3cfdd
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d0dc
jmp 0x3cfdf
movq -0x30(%rbp), %rax
movl 0x70(%rax), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x3d03b
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x4730
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x4330
movq -0x30(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x70(%rax)
movl $0x0, -0x24(%rbp)
jmp 0x3d0d6
jmp 0x3d049
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x10, %rdx
movl $0x2, %esi
callq 0x1dfd0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x3d070
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3d0dc
movq -0x10(%rbp), %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x39630
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x10(%rax)
cmpl $0x0, -0x24(%rbp)
jge 0x3d0d4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0xb5b71(%rip), %rsi     # 0xf2c1f
leaq 0xb5b78(%rip), %rdx     # 0xf2c2d
movb $0x0, %al
callq 0x1b030
cmpq $0x0, -0x18(%rbp)
je 0x3d0d2
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x3d0d2
jmp 0x3d049
jmp 0x3d0d4
jmp 0x3d0d6
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)