// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
cmpb $0x0, 0x3c(%rdi)
je 0x25706
movb $0x0, 0x3c(%rbx)
testq %r15, %r15
je 0x256d6
movl 0x30(%rbx), %eax
subl 0x2c(%rbx), %eax
movl %eax, (%r15)
movslq 0x2c(%rbx), %rsi
addq 0x40(%rbx), %rsi
movq %rsi, (%r12)
pushq $0x1
popq %rbp
cmpq $0x0, 0x50(%rbx)
je 0x25a0b
cmpb $0x23, (%rsi)
jne 0x25a0b
movq %rbx, %rdi
callq 0x25a53
jmp 0x25a0b
movq 0xb8(%rbx), %rax
testq %rax, %rax
je 0x2572b
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
movq 0x88(%rbx), %rdi
testq %rdi, %rdi
je 0x2578f
callq 0x3bb84
movq %rax, 0x18(%rbx)
movq 0x88(%rbx), %rdi
callq 0x3b91d
testq %rax, %rax
je 0x25a09
movq %rax, %r14
movq %rax, %rdi
callq 0x62d0
movq %rax, %r15
movl %r15d, 0x20(%rbx)
incl 0x28(%rbx)
andl $0x0, 0x2c(%rbx)
movl %r15d, 0x30(%rbx)
movq %r14, (%r12)
movq 0x40(%rbx), %rdi
callq 0x28c2d
movq %r14, 0x40(%rbx)
movl %r15d, 0x14(%rbx)
pushq $0x1
popq %rbp
jmp 0x25a0b
cmpq $0x0, 0x70(%rbx)
je 0x25832
cmpq $0x0, 0x78(%rbx)
je 0x25832
movq 0x68(%rbx), %rdi
callq 0x479b0
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rsi
movq 0x80(%rbx), %rdx
movq %rax, %rdi
callq 0x4a1fc
cmpl $-0x1, %eax
je 0x25a09
movl %eax, %r14d
orq $-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 0x257ff
movl %r14d, %esi
addl %r14d, %esi
movq %rbx, %rdi
callq 0x254a6
movl 0x14(%rbx), %eax
movq 0x40(%rbx), %rdi
movq 0x80(%rbx), %rcx
movslq %eax, %rsi
movq 0x10(%rcx), %rdx
callq 0x1d6d3
movq 0x40(%rbx), %rax
movq %rax, (%r12)
pushq $0x1
popq %rbp
testq %r15, %r15
je 0x25a0b
movl %r14d, (%r15)
jmp 0x25a0b
movq %r15, 0x20(%rsp)
movq %r12, 0x10(%rsp)
movq 0x40(%rbx), %r15
movslq 0x30(%rbx), %rsi
leaq 0xc(%rsp), %r14
movl %esi, (%r14)
movl 0x20(%rbx), %ebp
movl %ebp, %edx
subl %esi, %edx
addq %r15, %rsi
movq %rbx, %rdi
callq 0x25ab9
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x25b02
testl %eax, %eax
sete %r14b
testb $0x1, %r14b
je 0x25981
movslq 0x30(%rbx), %r12
subl %r12d, %ebp
movl 0x14(%rbx), %r14d
testq %r12, %r12
jle 0x258a0
testl %ebp, %ebp
jle 0x258a0
leaq (%r15,%r12), %rsi
movl %ebp, %edx
movq %r15, %rdi
callq 0x6c60
movl %r14d, 0x1c(%rsp)
movl %r14d, %r13d
addq %r12, 0x18(%rbx)
subl %ebp, %r13d
movl 0x10(%rbx), %edi
movslq %ebp, %r14
testl %edi, %edi
js 0x258c9
leaq (%r15,%r14), %rsi
movl %r13d, %edx
callq 0x2565b
movl %eax, %edx
jmp 0x258e8
xorl %edx, %edx
cmpq $0x0, 0x70(%rbx)
je 0x258e8
testl %r13d, %r13d
jle 0x258e8
leaq 0x5a746(%rip), %rdi     # 0x80024
xorl %eax, %eax
callq 0x223fb
movl %r13d, %edx
testl %edx, %edx
jne 0x258f7
cmpl %r12d, 0xc(%rsp)
jg 0x259bd
testl %edx, %edx
je 0x25a00
movl %ebp, 0xc(%rsp)
addl %edx, %ebp
movl %ebp, 0x20(%rbx)
andl $0x0, 0x30(%rbx)
addq %r15, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x25ab9
movq %rbx, %rdi
movq %r15, %rsi
movl %ebp, %edx
leaq 0xc(%rsp), %rcx
callq 0x25b02
testl %eax, %eax
sete %r14b
jne 0x25874
cmpl 0x14(%rbx), %ebp
jne 0x25874
movl 0x1c(%rsp), %esi
cmpl $0x20000000, %esi       # imm = 0x20000000
jl 0x2596b
movl 0x28(%rbx), %edx
incl %edx
movq 0x8(%rbx), %rcx
leaq 0x5a6f1(%rip), %rdi     # 0x8004e
movl %ebp, %esi
xorl %eax, %eax
callq 0x223fb
jmp 0x25874
addl %esi, %esi
movq %rbx, %rdi
callq 0x254a6
movq 0x40(%rbx), %r15
movb $0x1, %r14b
jmp 0x25874
cmpb $0x0, 0x34(%rbx)
movl 0xc(%rsp), %eax
je 0x25a1c
cltq
movb $0x0, -0x1(%rax,%r15)
cmpl $0x2, 0x38(%rbx)
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %rdx
jne 0x25a21
movslq %eax, %rcx
cmpb $0xd, -0x2(%rcx,%r15)
jne 0x25a21
movb $0x0, -0x2(%r15,%rcx)
movl 0xc(%rsp), %eax
jmp 0x25a21
movl %ebp, 0xc(%rsp)
movb $0x0, (%r15,%r14)
andl $0x0, 0x2c(%rbx)
andl $0x0, 0x20(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x30(%rbx)
incl 0x28(%rbx)
movq 0x20(%rsp), %rcx
testq %rcx, %rcx
je 0x259e4
movl %eax, (%rcx)
movq 0x10(%rsp), %rax
movq %r15, (%rax)
pushq $0x1
popq %rbp
cmpb $0x23, (%r15)
jne 0x25a0b
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x256fc
andq $0x0, 0x2c(%rbx)
andl $0x0, 0x20(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdx
movslq 0x30(%rbx), %rcx
movl %ecx, 0x2c(%rbx)
movl %eax, 0x30(%rbx)
incl 0x28(%rbx)
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x25a3c
subl %ecx, %eax
movl %eax, (%rsi)
leaq (%r15,%rcx), %rsi
movq %rsi, (%rdx)
pushq $0x1
popq %rbp
cmpb $0x23, (%r15,%rcx)
je 0x256f9
jmp 0x25a0b