// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/lib/linefile.c
// Function: lineFileNext
boolean lineFileNext(struct lineFile *lf, char **retStart, int *retSize)
/* Fetch next line from file. */
{
char *buf = lf->buf;
int bytesInBuf = lf->bytesInBuf;
int endIx = lf->lineEnd;
boolean gotLf = FALSE;
int newStart;

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

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


#ifdef USE_TABIX
if (lf->tabix != NULL && lf->tabixIter != NULL)
    {
    // Just use line-oriented ti_read:
    int lineSize = 0;
    const char *line = ti_read(lf->tabix, lf->tabixIter, &lineSize);
    if (line == NULL)
	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);
    safecpy(lf->buf, lf->bufSize, line);
    *retStart = lf->buf;
    if (retSize != NULL)
	*retSize = lineSize;
    return TRUE;
    }
#endif // USE_TABIX

determineNlType(lf, buf+endIx, bytesInBuf);

/* Find next end of line in buffer. */
switch(lf->nlType)
    {
    case nlt_unix:
    case nlt_dos:
	for (endIx = lf->lineEnd; endIx < bytesInBuf; ++endIx)
	    {
	    if (buf[endIx] == '\n')
		{
		gotLf = TRUE;
		endIx += 1;
		break;
		}
	    }
	break;
    case nlt_mac:
	for (endIx = lf->lineEnd; endIx < bytesInBuf; ++endIx)
	    {
	    if (buf[endIx] == '\r')
		{
		gotLf = TRUE;
		endIx += 1;
		break;
		}
	    }
	break;
    case nlt_undet:
	break;
    }

/* 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);
#ifdef USE_TABIX
    else if (lf->tabix != NULL && readSize > 0)
	{
	readSize = ti_bgzf_read(lf->tabix->fp, buf+sizeLeft, readSize);
	if (readSize < 1)
	    return FALSE;
	}
#endif // USE_TABIX
    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;
	}
    bytesInBuf = lf->bytesInBuf = readSize + sizeLeft;
    lf->lineEnd = 0;

    determineNlType(lf, buf+endIx, bytesInBuf);

    /* Look for next end of line.  */
    switch(lf->nlType)
	{
    	case nlt_unix:
	case nlt_dos:
	    for (endIx = sizeLeft; endIx <bytesInBuf; ++endIx)
		{
		if (buf[endIx] == '\n')
		    {
		    endIx += 1;
		    gotLf = TRUE;
		    break;
		    }
		}
	    break;
	case nlt_mac:
	    for (endIx = sizeLeft; endIx <bytesInBuf; ++endIx)
		{
		if (buf[endIx] == '\r')
		    {
		    endIx += 1;
		    gotLf = TRUE;
		    break;
		    }
		}
	    break;
	case nlt_undet:
	    break;
	}
    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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3c(%rax)
je 0x12704
movq -0x10(%rbp), %rax
movb $0x0, 0x3c(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x126b8
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x10(%rbp), %rax
subl 0x2c(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movslq 0x2c(%rax), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x126f8
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x126f8
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x12ba0
movl $0x1, -0x4(%rbp)
jmp 0x12b89
movq -0x10(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x12733
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq *%rax
movl %eax, -0x4(%rbp)
jmp 0x12b89
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x30(%rbp), %rax
addq %rax, %rsi
movl -0x2c(%rbp), %edx
callq 0x12c50
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x127ff
jmp 0x1275e
movl -0x4c(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x12777
jmp 0x1276a
movl -0x4c(%rbp), %eax
subl $0x3, %eax
je 0x127bb
jmp 0x12801
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x127b9
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x127ac
movl $0x1, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x127b9
jmp 0x127ae
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x12781
jmp 0x12801
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x127fd
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x127f0
movl $0x1, -0x34(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x127fd
jmp 0x127f2
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x127c5
jmp 0x12801
jmp 0x12801
jmp 0x12803
cmpl $0x0, -0x34(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x12815
jmp 0x12ac8
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x3c(%rbp)
jle 0x1285f
cmpl $0x0, -0x40(%rbp)
jle 0x1285f
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x3c(%rbp), %rax
addq %rax, %rsi
movslq -0x40(%rbp), %rdx
callq 0x35a0
movslq -0x3c(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jl 0x12898
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x28(%rbp), %rsi
movslq -0x40(%rbp), %rax
addq %rax, %rsi
movl -0x48(%rbp), %edx
callq 0x125e0
movl %eax, -0x48(%rbp)
jmp 0x1289f
movl $0x0, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0x1294b
movl -0x30(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x1294b
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1290e
movl -0x30(%rbp), %ecx
subl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movslq -0x38(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x1293f
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x12ba0
movl $0x1, -0x4(%rbp)
jmp 0x12b89
cmpl $0x0, -0x48(%rbp)
jg 0x1297e
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x12b89
jmp 0x12980
movl -0x48(%rbp), %eax
movl -0x40(%rbp), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movl %eax, 0x20(%rcx)
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x30(%rbp), %rax
addq %rax, %rsi
movl -0x2c(%rbp), %edx
callq 0x12c50
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x50(%rbp)
testl %eax, %eax
je 0x12a61
jmp 0x129c8
movl -0x50(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x129e1
jmp 0x129d4
movl -0x50(%rbp), %eax
subl $0x3, %eax
je 0x12a21
jmp 0x12a63
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x12a1f
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x12a12
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
jmp 0x12a1f
jmp 0x12a14
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x129e7
jmp 0x12a63
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x12a5f
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x12a52
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
jmp 0x12a5f
jmp 0x12a54
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x12a27
jmp 0x12a63
jmp 0x12a63
cmpl $0x0, -0x34(%rbp)
jne 0x12ac3
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jne 0x12ac3
cmpl $0x20000000, -0x44(%rbp) # imm = 0x20000000
jl 0x12aa7
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq 0x1243b(%rip), %rdi     # 0x24ed9
movb $0x0, %al
callq 0xfd50
jmp 0x12ac1
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
shll %esi
callq 0x122b0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x12ac3
jmp 0x12803
movq -0x10(%rbp), %rax
cmpb $0x0, 0x34(%rax)
je 0x12b16
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x38(%rax)
jne 0x12b14
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0x12b14
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x12b16
movq -0x10(%rbp), %rax
movl 0x30(%rax), %ecx
movl %ecx, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x12b51
movl -0x30(%rbp), %ecx
subl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rcx
movslq -0x38(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x12b82
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
callq 0x12ba0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)