// File: /workspace/github_c_makefile_star2_O3/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 %rsi, %r12
movq %rdi, %rbx
cmpb $0x0, 0x3c(%rdi)
je 0x2a806
movb $0x0, 0x3c(%rbx)
testq %rdx, %rdx
je 0x2a7d4
movl 0x30(%rbx), %eax
subl 0x2c(%rbx), %eax
movl %eax, (%rdx)
movslq 0x2c(%rbx), %rsi
addq 0x40(%rbx), %rsi
movq %rsi, (%r12)
movl $0x1, %ebp
cmpq $0x0, 0x50(%rbx)
je 0x2ab45
cmpb $0x23, (%rsi)
jne 0x2ab45
movq %rbx, %rdi
callq 0x2ab98
jmp 0x2ab45
movq 0xb8(%rbx), %rax
testq %rax, %rax
je 0x2a828
movq %rbx, %rdi
movq %r12, %rsi
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 0x2a891
callq 0x41e25
movq %rax, 0x18(%rbx)
movq 0x88(%rbx), %rdi
callq 0x41b91
testq %rax, %rax
je 0x2ab43
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 0x2e0a0
movq %r14, 0x40(%rbx)
movl %r15d, 0x14(%rbx)
movl $0x1, %ebp
jmp 0x2ab45
movq %rdx, 0x8(%rsp)
cmpq $0x0, 0x70(%rbx)
je 0x2a943
cmpq $0x0, 0x78(%rbx)
je 0x2a943
movq 0x68(%rbx), %rdi
callq 0x4e921
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rsi
movq 0x80(%rbx), %rdx
movq %rax, %rdi
callq 0x51bdd
cmpl $-0x1, %eax
je 0x2ab43
movl %eax, %r14d
movq $-0x1, 0x18(%rbx)
movl %eax, 0x20(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x28(%rbx)
movl %r14d, 0x30(%rbx)
movl 0x14(%rbx), %eax
cmpl %eax, %r14d
jle 0x2a909
movl %r14d, %esi
addl %r14d, %esi
movq %rbx, %rdi
callq 0x2a58f
movl 0x14(%rbx), %eax
movq 0x40(%rbx), %rdi
movq 0x80(%rbx), %rcx
movslq %eax, %rsi
movq 0x10(%rcx), %rdx
callq 0x21600
movq 0x40(%rbx), %rax
movq %rax, (%r12)
movl $0x1, %ebp
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x2ab45
movl %r14d, (%rax)
jmp 0x2ab45
movq %r12, 0x18(%rsp)
movq 0x40(%rbx), %r15
movslq 0x30(%rbx), %rsi
leaq 0x4(%rsp), %r14
movl %esi, (%r14)
movl 0x20(%rbx), %ebp
movl %ebp, %edx
subl %esi, %edx
addq %r15, %rsi
movq %rbx, %rdi
callq 0x2ac01
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x2ac4e
testl %eax, %eax
je 0x2a9eb
movq 0x8(%rsp), %rsi
cmpb $0x0, 0x34(%rbx)
movl 0x4(%rsp), %eax
movq 0x18(%rsp), %rdx
je 0x2a9b9
cltq
movb $0x0, -0x1(%rax,%r15)
cmpl $0x2, 0x38(%rbx)
movl 0x4(%rsp), %eax
jne 0x2a9b9
movslq %eax, %rcx
cmpb $0xd, -0x2(%rcx,%r15)
jne 0x2a9b9
movb $0x0, -0x2(%r15,%rcx)
movl 0x4(%rsp), %eax
movslq 0x30(%rbx), %rcx
movl %ecx, 0x2c(%rbx)
movl %eax, 0x30(%rbx)
incl 0x28(%rbx)
testq %rsi, %rsi
je 0x2a9cf
subl %ecx, %eax
movl %eax, (%rsi)
leaq (%r15,%rcx), %rsi
movq %rsi, (%rdx)
movl $0x1, %ebp
cmpb $0x23, (%r15,%rcx)
je 0x2a7f9
jmp 0x2ab45
movq %r15, 0x20(%rsp)
movslq 0x30(%rbx), %r14
subl %r14d, %ebp
movl 0x14(%rbx), %r12d
testq %r14, %r14
jle 0x2aa12
testl %ebp, %ebp
jle 0x2aa12
leaq (%r15,%r14), %rsi
movl %ebp, %edx
movq %r15, %rdi
callq 0x6c60
movl %r12d, 0x14(%rsp)
movq %r14, 0x30(%rsp)
addq %r14, 0x18(%rbx)
subl %ebp, %r12d
movl 0x10(%rbx), %r14d
movslq %ebp, %r13
testl %r14d, %r14d
movq %r13, 0x28(%rsp)
js 0x2aa66
testl %r12d, %r12d
jle 0x2aa85
addq %r15, %r13
xorl %r15d, %r15d
movl %r12d, %edx
movl %r14d, %edi
movq %r13, %rsi
callq 0x6aa0
testl %eax, %eax
jle 0x2aa88
addl %eax, %r15d
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq %rcx, %r13
subl %eax, %r12d
jg 0x2aa3f
jmp 0x2aa9c
xorl %r15d, %r15d
cmpq $0x0, 0x70(%rbx)
je 0x2aa88
testl %r12d, %r12d
jle 0x2aa88
leaq 0x666a8(%rip), %rdi     # 0x91124
xorl %eax, %eax
callq 0x26e94
jmp 0x2aaad
xorl %r15d, %r15d
testl %r15d, %r15d
jne 0x2aa9c
movq 0x30(%rsp), %rax
cmpl %eax, 0x4(%rsp)
jg 0x2ab56
movl %r15d, %r12d
testl %r15d, %r15d
movq 0x28(%rsp), %r13
jle 0x2ab34
movl %ebp, 0x4(%rsp)
addl %r12d, %ebp
movl %ebp, 0x20(%rbx)
movl $0x0, 0x30(%rbx)
movq 0x20(%rsp), %r15
addq %r15, %r13
movq %rbx, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x2ac01
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
leaq 0x4(%rsp), %rcx
callq 0x2ac4e
testl %eax, %eax
jne 0x2a97e
cmpl 0x14(%rbx), %ebp
jne 0x2a9f0
movl 0x14(%rsp), %esi
cmpl $0x20000000, %esi       # imm = 0x20000000
jl 0x2ab21
movl 0x28(%rbx), %edx
incl %edx
movq 0x8(%rbx), %rcx
leaq 0x6663b(%rip), %rdi     # 0x9114e
movl %ebp, %esi
xorl %eax, %eax
callq 0x26e94
jmp 0x2a9f0
addl %esi, %esi
movq %rbx, %rdi
callq 0x2a58f
movq 0x40(%rbx), %r15
jmp 0x2a9eb
movq $0x0, 0x2c(%rbx)
movl $0x0, 0x20(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, 0x4(%rsp)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rax
movb $0x0, (%rsi,%rax)
xorl %eax, %eax
movl %eax, 0x2c(%rbx)
movl %eax, 0x20(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x30(%rbx)
incl 0x28(%rbx)
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x2ab86
movl %eax, (%rcx)
movq 0x18(%rsp), %rax
movq %rsi, (%rax)
movl $0x1, %ebp
jmp 0x2a7f0