// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/linefile.c
// Function: lineFileNext
boolean lineFileNext(struct lineFile *lf, char **retStart, int *retSize)
/* Fetch next line from file. */
{
int newStart;

if (lf->reuse)
    {
    lf->reuse = FALSE;
    if (retSize != NULL)
	*retSize = lf->lineEnd - lf->lineStart;
    *retStart = lf->buf + lf->lineStart;
    if (lf->metaOutput && *retStart[0] == '#')
        metaDataAdd(lf, *retStart);
    return TRUE;
    }

if (lf->nextCallBack)
    return lf->nextCallBack(lf, retStart, retSize);

if (lf->udcFile)
    {
    lf->bufOffsetInFile = udcTell(lf->udcFile);
    char *line = udcReadLine(lf->udcFile);
    if (line==NULL)
        return FALSE;
    int lineSize = strlen(line);
    lf->bytesInBuf = lineSize;
    ++lf->lineIx;
    lf->lineStart = 0;
    lf->lineEnd = lineSize;
    *retStart = line;
    freeMem(lf->buf);
    lf->buf = line;
    lf->bufSize = lineSize;
    return TRUE;
    }

if (lf->tabix != NULL && lf->tabixIter != NULL)
    {
    // Just use line-oriented ti_read:
    int lineSize = 0;
    lineSize = tbx_itr_next(lf->htsFile, lf->tabix, lf->tabixIter, lf->kline);
    if (lineSize == -1)
	return FALSE;
    lf->bufOffsetInFile = -1;
    lf->bytesInBuf = lineSize;
    lf->lineIx = -1;
    lf->lineStart = 0;
    lf->lineEnd = lineSize;
    if (lineSize > lf->bufSize)
	// shouldn't be!  but just in case:
	lineFileExpandBuf(lf, lineSize * 2);
    kstring_t *kline = lf->kline;
    safecpy(lf->buf, lf->bufSize, kline->s);
    *retStart = lf->buf;
    if (retSize != NULL)
	*retSize = lineSize;
    return TRUE;
    }

char *buf = lf->buf;
int endIx = lf->lineEnd;
int bytesInBuf = lf->bytesInBuf;
determineNlType(lf, buf+endIx, bytesInBuf-endIx);
boolean gotLf = findNextNewline(lf, buf, bytesInBuf, &endIx);

/* If not in buffer read in a new buffer's worth. */
while (!gotLf)
    {
    int oldEnd = lf->lineEnd;
    int sizeLeft = bytesInBuf - oldEnd;
    int bufSize = lf->bufSize;
    int readSize = bufSize - sizeLeft;

    if (oldEnd > 0 && sizeLeft > 0)
	{
	memmove(buf, buf+oldEnd, sizeLeft);
	}
    lf->bufOffsetInFile += oldEnd;
    if (lf->fd >= 0)
	readSize = lineFileLongNetRead(lf->fd, buf+sizeLeft, readSize);
    else if (lf->tabix != NULL && readSize > 0)
	{
        errAbort("bgzf read not supported with htslib (yet)");
	if (readSize < 1)
	    return FALSE;
	}
    else
        readSize = 0;

    if ((readSize == 0) && (endIx > oldEnd))
	{
	endIx = sizeLeft;
	buf[endIx] = 0;
	lf->bytesInBuf = newStart = lf->lineStart = 0;
	lf->lineEnd = endIx;
	++lf->lineIx;
	if (retSize != NULL)
	    *retSize = endIx - newStart;
	*retStart = buf + newStart;
        if (*retStart[0] == '#')
            metaDataAdd(lf, *retStart);
	return TRUE;
	}
    else if (readSize <= 0)
	{
	lf->bytesInBuf = lf->lineStart = lf->lineEnd = 0;
	return FALSE;
	}
    else
        endIx = sizeLeft;

    bytesInBuf = lf->bytesInBuf = readSize + sizeLeft;
    lf->lineEnd = 0;

    determineNlType(lf, buf+endIx, bytesInBuf-endIx);
    gotLf = findNextNewline(lf, buf, bytesInBuf, &endIx);

    if (!gotLf && bytesInBuf == lf->bufSize)
        {
	if (bufSize >= 512*1024*1024)
	    {
	    errAbort("Line too long (more than %d chars) line %d of %s",
		lf->bufSize, lf->lineIx+1, lf->fileName);
	    }
	else
	    {
	    lineFileExpandBuf(lf, bufSize*2);
	    buf = lf->buf;
	    }
	}
    }

if (lf->zTerm)
    {
    buf[endIx-1] = 0;
    if ((lf->nlType == nlt_dos) && (buf[endIx-2]=='\r'))
	{
	buf[endIx-2] = 0;
	}
    }

lf->lineStart = newStart = lf->lineEnd;
lf->lineEnd = endIx;
++lf->lineIx;
if (retSize != NULL)
    *retSize = endIx - newStart;
*retStart = buf + newStart;
if (*retStart[0] == '#')
    metaDataAdd(lf, *retStart);
return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
movq %rsi, %rcx
movq %rdi, %rbx
cmpb $0x0, 0x3c(%rdi)
je 0x2a4b6
movb $0x0, 0x3c(%rbx)
testq %r14, %r14
je 0x2a484
movl 0x30(%rbx), %eax
subl 0x2c(%rbx), %eax
movl %eax, (%r14)
movslq 0x2c(%rbx), %rsi
addq 0x40(%rbx), %rsi
movq %rsi, (%rcx)
movl $0x1, %r15d
cmpq $0x0, 0x50(%rbx)
je 0x2a874
cmpb $0x23, (%rsi)
jne 0x2a874
movq %rbx, %rdi
callq 0x2a886
jmp 0x2a874
movq 0xb8(%rbx), %rax
testq %rax, %rax
je 0x2a4db
movq %rbx, %rdi
movq %rcx, %rsi
movq %r14, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x2a548
movq %rcx, %r12
callq 0x41ade
movq %rax, 0x18(%rbx)
movq 0x88(%rbx), %rdi
callq 0x41825
testq %rax, %rax
je 0x2a5ed
movq %rax, %r14
movq %rax, %rdi
callq 0x62d0
movq %rax, %r15
movl %r15d, 0x20(%rbx)
incl 0x28(%rbx)
movl $0x0, 0x2c(%rbx)
movl %r15d, 0x30(%rbx)
movq %r14, (%r12)
movq 0x40(%rbx), %rdi
callq 0x2dd41
movq %r14, 0x40(%rbx)
movl %r15d, 0x14(%rbx)
movl $0x1, %r15d
jmp 0x2a874
movq %rcx, 0x18(%rsp)
cmpq $0x0, 0x70(%rbx)
je 0x2a5f5
cmpq $0x0, 0x78(%rbx)
je 0x2a5f5
movq 0x68(%rbx), %rdi
callq 0x4e707
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rsi
movq 0x80(%rbx), %rdx
movq %rax, %rdi
callq 0x518c4
cmpl $-0x1, %eax
je 0x2a5ed
movl %eax, %ebp
movq $-0x1, 0x18(%rbx)
movl %eax, 0x20(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x28(%rbx)
movl %ebp, 0x30(%rbx)
cmpl 0x14(%rbx), %ebp
jle 0x2a5b2
movl %ebp, %esi
addl %ebp, %esi
movq %rbx, %rdi
callq 0x2a23b
movq 0x40(%rbx), %rdi
movq 0x80(%rbx), %rax
movslq 0x14(%rbx), %rsi
movq 0x10(%rax), %rdx
callq 0x21264
movq 0x40(%rbx), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl $0x1, %r15d
testq %r14, %r14
je 0x2a874
movl %ebp, (%r14)
jmp 0x2a874
xorl %r15d, %r15d
jmp 0x2a874
movq 0x40(%rbx), %r12
movslq 0x30(%rbx), %rsi
movq %rsp, %r15
movl %esi, (%r15)
movl 0x20(%rbx), %r13d
movl %r13d, %edx
subl %esi, %edx
addq %r12, %rsi
movq %rbx, %rdi
callq 0x2a8ef
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %r15, %rcx
callq 0x2a93c
movl %eax, 0x8(%rsp)
movq %r14, 0x10(%rsp)
cmpl $0x0, 0x8(%rsp)
jne 0x2a80a
movslq 0x30(%rbx), %rbp
movl %r13d, 0xc(%rsp)
movl %r13d, %r15d
subl %ebp, %r15d
movl 0x14(%rbx), %r14d
testq %rbp, %rbp
jle 0x2a668
testl %r15d, %r15d
jle 0x2a668
leaq (%r12,%rbp), %rsi
movl %r15d, %edx
movq %r12, %rdi
callq 0x6c60
movq %rbp, 0x30(%rsp)
addq %rbp, 0x18(%rbx)
movl %r14d, %r13d
subl %r15d, %r13d
movl 0x10(%rbx), %ebp
testl %ebp, %ebp
movq %r12, 0x20(%rsp)
movl %r14d, 0x2c(%rsp)
js 0x2a6be
testl %r13d, %r13d
jle 0x2a6e0
movslq %r15d, %r12
addq 0x20(%rsp), %r12
xorl %r14d, %r14d
movl %r13d, %edx
movl %ebp, %edi
movq %r12, %rsi
callq 0x6aa0
testl %eax, %eax
jle 0x2a6e3
addl %eax, %r14d
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %r12
subl %eax, %r13d
jg 0x2a698
jmp 0x2a6e3
xorl %r14d, %r14d
cmpq $0x0, 0x70(%rbx)
je 0x2a6e3
testl %r13d, %r13d
jle 0x2a6e3
leaq 0x66960(%rip), %rdi     # 0x91034
xorl %eax, %eax
callq 0x26b6f
movl %r13d, %r14d
jmp 0x2a6e3
xorl %r14d, %r14d
testl %r14d, %r14d
jne 0x2a74f
movq 0x30(%rsp), %rax
cmpl %eax, (%rsp)
jle 0x2a74f
movl %r15d, (%rsp)
movslq %r15d, %rax
movq 0x20(%rsp), %r12
movb $0x0, (%r12,%rax)
xorl %eax, %eax
movl %eax, 0x2c(%rbx)
movl %eax, 0x20(%rbx)
movl (%rsp), %eax
incl 0x28(%rbx)
movl %eax, 0x30(%rbx)
movq 0x10(%rsp), %r14
testq %r14, %r14
movq 0x18(%rsp), %rcx
movl 0xc(%rsp), %r13d
je 0x2a72b
movl %eax, (%r14)
movq %r12, (%rcx)
movl $0x1, 0x4(%rsp)
cmpb $0x23, (%r12)
jne 0x2a748
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2a886
xorl %ebp, %ebp
jmp 0x2a7ed
testl %r14d, %r14d
movq 0x20(%rsp), %r12
movl 0xc(%rsp), %r13d
jle 0x2a7cf
movl %r15d, (%rsp)
leal (%r14,%r15), %r13d
movl %r13d, 0x20(%rbx)
movl $0x0, 0x30(%rbx)
movslq %r15d, %rsi
addq %r12, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x2a8ef
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %rsp, %rcx
callq 0x2a93c
movb $0x1, %bpl
movl %eax, 0x8(%rsp)
testl %eax, %eax
jne 0x2a7e8
movl 0x14(%rbx), %esi
cmpl %esi, %r13d
movq 0x10(%rsp), %r14
jne 0x2a7ed
movl 0x2c(%rsp), %eax
cmpl $0x20000000, %eax       # imm = 0x20000000
jl 0x2a7f8
movl 0x28(%rbx), %edx
incl %edx
movq 0x8(%rbx), %rcx
leaq 0x66898(%rip), %rdi     # 0x9105e
xorl %eax, %eax
callq 0x26b6f
jmp 0x2a7ed
movq $0x0, 0x2c(%rbx)
movl $0x0, 0x20(%rbx)
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %r14
testb %bpl, %bpl
jne 0x2a631
jmp 0x2a86f
addl %eax, %eax
movq %rbx, %rdi
movl %eax, %esi
callq 0x2a23b
movq 0x40(%rbx), %r12
jmp 0x2a7ed
cmpb $0x0, 0x34(%rbx)
je 0x2a832
movslq (%rsp), %rax
movb $0x0, -0x1(%rax,%r12)
cmpl $0x2, 0x38(%rbx)
jne 0x2a832
movslq (%rsp), %rax
cmpb $0xd, -0x2(%rax,%r12)
jne 0x2a832
movb $0x0, -0x2(%r12,%rax)
movslq 0x30(%rbx), %rax
movl %eax, 0x2c(%rbx)
movl (%rsp), %ecx
movl %ecx, 0x30(%rbx)
incl 0x28(%rbx)
testq %r14, %r14
je 0x2a84c
subl %eax, %ecx
movl %ecx, (%r14)
leaq (%r12,%rax), %rsi
movq 0x18(%rsp), %rcx
movq %rsi, (%rcx)
movl $0x1, 0x4(%rsp)
cmpb $0x23, (%r12,%rax)
jne 0x2a86f
movq %rbx, %rdi
callq 0x2a886
movl 0x4(%rsp), %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq