// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bcf_sr_sort.c
// Function: bcf_sr_sort_next
int bcf_sr_sort_next(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, hts_pos_t min_pos)
{
    int i,j;
    assert( srt->nactive>0 );

    if ( srt->nsr != readers->nreaders )
    {
        srt->sr = readers;
        if ( srt->nsr < readers->nreaders )
        {
            srt->vcf_buf = (vcf_buf_t*) realloc(srt->vcf_buf,readers->nreaders*sizeof(vcf_buf_t));
            memset(srt->vcf_buf + srt->nsr, 0, sizeof(vcf_buf_t)*(readers->nreaders - srt->nsr));
            if ( srt->msr < srt->nsr ) srt->msr = srt->nsr;
        }
        srt->nsr = readers->nreaders;
        srt->chr = NULL;
    }
    if ( srt->nactive == 1 )
    {
        if ( readers->nreaders>1 )
            memset(readers->has_line, 0, readers->nreaders*sizeof(*readers->has_line));
        bcf_sr_t *reader = &readers->readers[srt->active[0]];
        assert( reader->buffer[1]->pos==min_pos );
        bcf1_t *tmp = reader->buffer[0];
        for (j=1; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j];
        reader->buffer[ reader->nbuffer ] = tmp;
        reader->nbuffer--;
        readers->has_line[srt->active[0]] = 1;
        return 1;
    }
    if ( !srt->chr || srt->pos!=min_pos || strcmp(srt->chr,chr) ) bcf_sr_sort_set(readers, srt, chr, min_pos);

    if ( !srt->vcf_buf[0].nrec ) return 0;

#if DEBUG_VBUF
    debug_vbuf(srt);
#endif

    int nret = 0;
    for (i=0; i<srt->sr->nreaders; i++)
    {
        vcf_buf_t *buf = &srt->vcf_buf[i];

        if ( buf->rec[0] )
        {
            bcf_sr_t *reader = &srt->sr->readers[i];
            for (j=1; j<=reader->nbuffer; j++)
                if ( reader->buffer[j] == buf->rec[0] ) break;

            assert( j<=reader->nbuffer );

            bcf1_t *tmp = reader->buffer[0];
            reader->buffer[0] = reader->buffer[j++];
            for (; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j];
            reader->buffer[ reader->nbuffer ] = tmp;
            reader->nbuffer--;

            nret++;
            srt->sr->has_line[i] = 1;
        }
        else
            srt->sr->has_line[i] = 0;

        buf->nrec--;
        if ( buf->nrec > 0 )
            memmove(buf->rec, &buf->rec[1], buf->nrec*sizeof(bcf1_t*));
    }
    return nret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x1c4(%rax)
jle 0xdf807
jmp 0xdf826
leaq 0x394a9(%rip), %rdi     # 0x118cb7
leaq 0x394b1(%rip), %rsi     # 0x118cc6
movl $0x254, %edx            # imm = 0x254
leaq 0x394b3(%rip), %rcx     # 0x118cd4
callq 0x42d0
movq -0x18(%rbp), %rax
movl 0x1b8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x30(%rcx), %eax
je 0xdf915
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x158(%rax)
movq -0x18(%rbp), %rax
movl 0x1b8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0xdf8f5
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x30(%rax), %rsi
shlq $0x4, %rsi
callq 0x4840
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x150(%rax)
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x1b8(%rax), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x1b8(%rcx), %eax
movslq %eax, %rdx
shlq $0x4, %rdx
xorl %esi, %esi
callq 0x4240
movq -0x18(%rbp), %rax
movl 0x1bc(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x1b8(%rcx), %eax
jge 0xdf8f3
movq -0x18(%rbp), %rax
movl 0x1b8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1bc(%rax)
jmp 0xdf8f5
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1b8(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x1a8(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x1c4(%rax)
jne 0xdfa42
movq -0x10(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jle 0xdf94b
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x30(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x4240
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x1d0(%rcx), %rcx
movslq (%rcx), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0xdf983
jmp 0xdf9a2
leaq 0x39392(%rip), %rdi     # 0x118d1c
leaq 0x39335(%rip), %rsi     # 0x118cc6
movl $0x267, %edx            # imm = 0x267
leaq 0x39337(%rip), %rcx     # 0x118cd4
callq 0x42d0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0xdf9f4
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xdf9b8
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
movl 0x38(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x1d0(%rcx), %rcx
movslq (%rcx), %rcx
movl $0x1, (%rax,%rcx,4)
movl $0x1, -0x4(%rbp)
jmp 0xdfca8
movq -0x18(%rbp), %rax
cmpq $0x0, 0x1a8(%rax)
je 0xdfa7a
movq -0x18(%rbp), %rax
movq 0x1b0(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0xdfa7a
movq -0x18(%rbp), %rax
movq 0x1a8(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x46b0
cmpl $0x0, %eax
je 0xdfa8f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xdfcc0
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rax
cmpl $0x0, (%rax)
jne 0xdfaab
movl $0x0, -0x4(%rbp)
jmp 0xdfca8
movl $0x0, -0x44(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x158(%rcx), %rcx
cmpl 0x30(%rcx), %eax
jge 0xdfca2
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, (%rax)
je 0xdfc40
movq -0x18(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0xdfb59
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x50(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq (%rcx), %rax
jne 0xdfb4c
jmp 0xdfb59
jmp 0xdfb4e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xdfb21
movl -0x30(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0xdfb67
jmp 0xdfb86
leaq 0x391ce(%rip), %rdi     # 0x118d3c
leaq 0x39151(%rip), %rsi     # 0x118cc6
movl $0x282, %edx            # imm = 0x282
leaq 0x39153(%rip), %rcx     # 0x118cd4
callq 0x42d0
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x30(%rbp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq %rcx, (%rax)
movl -0x30(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jg 0xdfbf6
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xdfbba
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x58(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rax
movl 0x38(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x38(%rax)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0xdfc5a
movq -0x18(%rbp), %rax
movq 0x158(%rax), %rax
movq 0x18(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
cmpl $0x0, (%rax)
jle 0xdfc92
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x8, %rsi
movq -0x50(%rbp), %rax
movslq (%rax), %rdx
shlq $0x3, %rdx
callq 0x4830
jmp 0xdfc94
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xdfab9
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)