// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/scriptfile.c
// Function: scriptfile_preparse
void scriptfile_preparse (scriptfile *sf, char *tx, size_t flen)
{
	int cr, numcr, nflen, ws, cs, inquote;
	size_t i;

		//Count number of lines
	numcr = 1;
	for(i=0;i<flen;i++)
	{
			//detect all 4 types of carriage return (\r, \n, \r\n, \n\r :)
		cr=0;if (tx[i] == '\r') { i += (tx[i+1] == '\n'); cr = 1; }
		else if (tx[i] == '\n') { i += (tx[i+1] == '\r'); cr = 1; }
		if (cr) { numcr++; continue; }
	}

	sf->linenum = numcr;
	sf->lineoffs = (int *)malloc(sf->linenum*sizeof(int));

		//Preprocess file for comments (// and /*...*/, and convert all whitespace to single spaces)
	nflen = 0; ws = 0; cs = 0; numcr = 0; inquote = 0;
	for(i=0;i<flen;i++)
	{
			//detect all 4 types of carriage return (\r, \n, \r\n, \n\r :)
		cr=0;if (tx[i] == '\r') { i += (tx[i+1] == '\n'); cr = 1; }
		else if (tx[i] == '\n') { i += (tx[i+1] == '\r'); cr = 1; }
		if (cr)
		{
				//Remember line numbers by storing the byte index at the start of each line
				//Line numbers can be retrieved by doing a binary search on the byte index :)
			sf->lineoffs[numcr++] = nflen;
			if (cs == 1) cs = 0;
			ws = 1; continue; //strip CR/LF
		}

		if ((!inquote) && ((tx[i] == ' ') || (tx[i] == '\t'))) { ws = 1; continue; } //strip Space/Tab
		if ((tx[i] == ';') && (!cs)) cs = 1;	// ; comment
		if ((tx[i] == '/') && (tx[i+1] == '/') && (!cs)) cs = 1;
		if ((tx[i] == '/') && (tx[i+1] == '*') && (!cs)) { ws = 1; cs = 2; }
		if ((tx[i] == '*') && (tx[i+1] == '/') && (cs == 2)) { cs = 0; i++; continue; }
		if (cs) continue;

		if (ws) { tx[nflen++] = 0; ws = 0; }

			//quotes inside strings: \"
		if ((tx[i] == '\\') && (tx[i+1] == '\"')) { i++; tx[nflen++] = '\"'; continue; }
		if (tx[i] == '\"') { inquote ^= 1; continue; }
		tx[nflen++] = tx[i];
	}
	tx[nflen++] = 0; sf->lineoffs[numcr] = nflen;
	tx[nflen++] = 0;

#if 0
		//for debugging only:
	printf("pre-parsed file:flen=%d,nflen=%d\n",flen,nflen);
	for(i=0;i<nflen;i++) { if (tx[i] < 32) printf("_"); else printf("%c",tx[i]); }
	printf("[eof]\nnumlines=%d\n",sf->linenum);
	for(i=0;i<sf->linenum;i++) printf("line %d = byte %d\n",i,sf->lineoffs[i]);
#endif
	flen = nflen;

	sf->textbuf = sf->textptr = tx;
	sf->textlength = nflen;
	sf->eof = &sf->textbuf[nflen-1];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl $0x1, %eax
testq %rdx, %rdx
je 0x4b273
xorl %ecx, %ecx
movzbl (%r14,%rcx), %edx
cmpl $0xd, %edx
je 0x4b250
cmpl $0xa, %edx
jne 0x4b267
movb $0xd, %dl
jmp 0x4b252
movb $0xa, %dl
xorl %esi, %esi
cmpb %dl, 0x1(%r14,%rcx)
sete %sil
addq %rsi, %rcx
movl $0x1, %edx
jmp 0x4b269
xorl %edx, %edx
addl %edx, %eax
incq %rcx
cmpq %r15, %rcx
jb 0x4b23d
movl %eax, 0x30(%rbx)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x69a0
movq %rax, 0x38(%rbx)
xorl %ecx, %ecx
testq %r15, %r15
je 0x4b3fd
movl $0x1, %edx
movl $0x2, %esi
xorl %edi, %edi
xorl %r9d, %r9d
xorl %r11d, %r11d
xorl %r10d, %r10d
xorl %eax, %eax
xorl %r8d, %r8d
movzbl (%r14,%rdi), %r12d
cmpl $0xd, %r12d
je 0x4b2c4
movb $0x1, %bpl
cmpl $0xa, %r12d
jne 0x4b2d8
movb $0xd, %bpl
jmp 0x4b2c7
movb $0xa, %bpl
xorl %r12d, %r12d
cmpb %bpl, 0x1(%r14,%rdi)
sete %r12b
addq %r12, %rdi
xorl %ebp, %ebp
testb %bpl, %bpl
je 0x4b355
testl %r9d, %r9d
je 0x4b37c
movb (%r14,%rdi), %r12b
testl %r11d, %r11d
movl $0x1, %ebp
cmovnel %r11d, %ebp
cmpb $0x3b, %r12b
cmovnel %r11d, %ebp
cmpb $0x2f, %r12b
jne 0x4b31a
testl %ebp, %ebp
movl $0x1, %r11d
cmovnel %ebp, %r11d
cmpb $0x2f, 0x1(%r14,%rdi)
cmovel %r11d, %ebp
cmpb $0x2f, %r12b
jne 0x4b33a
cmpb $0x2a, 0x1(%r14,%rdi)
setne %r11b
testl %ebp, %ebp
setne %r13b
orb %r11b, %r13b
cmovel %edx, %r10d
cmovel %esi, %ebp
cmpb $0x2a, %r12b
jne 0x4b373
cmpb $0x2f, 0x1(%r14,%rdi)
jne 0x4b373
cmpl $0x2, %ebp
jne 0x4b373
incq %rdi
jmp 0x4b3e9
movq 0x38(%rbx), %r10
movslq %r8d, %r12
incl %r8d
movl %eax, (%r10,%r12,4)
cmpl $0x1, %r11d
cmovel %ecx, %r11d
movl $0x1, %r10d
jmp 0x4b3ec
testl %ebp, %ebp
je 0x4b39a
movl %ebp, %r11d
jmp 0x4b3ec
movzbl (%r14,%rdi), %ebp
cmpl $0x9, %ebp
je 0x4b38f
cmpl $0x20, %ebp
jne 0x4b2e6
movl $0x1, %r10d
xorl %r9d, %r9d
jmp 0x4b3ec
testl %r10d, %r10d
je 0x4b3a9
movslq %eax, %r10
incl %eax
movb $0x0, (%r14,%r10)
movzbl (%r14,%rdi), %r10d
cmpl $0x22, %r10d
je 0x4b3d7
cmpl $0x5c, %r10d
jne 0x4b3dd
cmpb $0x22, 0x1(%r14,%rdi)
jne 0x4b3d1
incq %rdi
movslq %eax, %r10
incl %eax
movb $0x22, (%r14,%r10)
jmp 0x4b3e6
cmpb $0x22, %r10b
jne 0x4b3dd
xorl $0x1, %r9d
jmp 0x4b3e6
movslq %eax, %r11
incl %eax
movb %r10b, (%r14,%r11)
xorl %r10d, %r10d
xorl %r11d, %r11d
incq %rdi
cmpq %r15, %rdi
jb 0x4b2ab
movslq %r8d, %rcx
jmp 0x4b3ff
xorl %eax, %eax
cltq
leaq 0x1(%rax), %rdx
xorl %esi, %esi
leaq (%r14,%rax), %rdi
incq %rdi
movb %sil, -0x1(%rdi)
movq 0x38(%rbx), %r8
movl %edx, (%r8,%rcx,4)
addl $0x2, %eax
movb %sil, (%rdi)
movq %r14, 0x18(%rbx)
movq %r14, (%rbx)
movl %eax, 0x8(%rbx)
movq %rdi, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq