// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rax
xorl %ecx, %ecx
cmpq %r15, %rcx
jae 0x44ad0
movzbl (%r14,%rcx), %edx
cmpl $0xd, %edx
je 0x44ab9
cmpl $0xa, %edx
jne 0x44acb
movb $0xd, %dl
jmp 0x44abb
movb $0xa, %dl
xorl %esi, %esi
cmpb %dl, 0x1(%r14,%rcx)
sete %sil
addq %rsi, %rcx
incl %eax
incq %rcx
jmp 0x44aa1
movl %eax, 0x30(%rbx)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x69a0
movq %rax, 0x38(%rbx)
xorl %eax, %eax
pushq $0x1
popq %rcx
pushq $0x2
popq %rdx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %edi, %edi
xorl %esi, %esi
movslq %r8d, %r12
movslq %eax, %r13
cmpq %r15, %rsi
jae 0x44c25
movzbl (%r14,%rsi), %r11d
cmpl $0xd, %r11d
je 0x44b1d
cmpl $0xa, %r11d
jne 0x44b53
movb $0xd, %r11b
jmp 0x44b20
movb $0xa, %r11b
xorl %r9d, %r9d
cmpb %r11b, 0x1(%r14,%rsi)
sete %bpl
movq 0x38(%rbx), %r11
movl %r8d, (%r11,%r13,4)
xorl %r11d, %r11d
cmpl $0x1, %r10d
je 0x44b40
movl %r10d, %r11d
movb %bpl, %r9b
addq %r9, %rsi
incl %eax
movl %ecx, %r9d
movl %r11d, %r10d
incq %rsi
jmp 0x44af8
testl %edi, %edi
je 0x44b9f
movl %r10d, %ebp
testl %r10d, %r10d
jne 0x44b61
movl %ecx, %ebp
cmpb $0x3b, %r11b
cmovnel %r10d, %ebp
cmpl $0x2a, %r11d
je 0x44bb2
cmpl $0x2f, %r11d
jne 0x44bc7
movl %ebp, %r10d
testl %ebp, %ebp
jne 0x44b7f
movl %ecx, %r10d
movb 0x1(%r14,%rsi), %r13b
cmpb $0x2f, %r13b
cmovnel %ebp, %r10d
cmpb $0x2a, %r13b
jne 0x44bca
testl %r10d, %r10d
jne 0x44bca
movl %ecx, %r9d
movl %edx, %r10d
jmp 0x44b4e
cmpl $0x9, %r11d
je 0x44bab
cmpl $0x20, %r11d
jne 0x44b57
movl %ecx, %r9d
xorl %edi, %edi
jmp 0x44b4e
cmpb $0x2f, 0x1(%r14,%rsi)
jne 0x44bc7
movl %ebp, %r10d
cmpl $0x2, %ebp
jne 0x44bca
incq %rsi
jmp 0x44c1d
movl %ebp, %r10d
testl %r10d, %r10d
jne 0x44b4e
testl %r9d, %r9d
je 0x44be4
incl %r8d
movb $0x0, (%r14,%r12)
movb (%r14,%rsi), %r11b
cmpb $0x22, %r11b
je 0x44c17
movzbl %r11b, %r10d
movslq %r8d, %r9
cmpl $0x5c, %r10d
jne 0x44c0d
cmpb $0x22, 0x1(%r14,%rsi)
jne 0x44c0d
incq %rsi
leal 0x1(%r9), %r8d
movb $0x22, (%r14,%r9)
jmp 0x44c1a
leal 0x1(%r9), %r8d
movb %r11b, (%r14,%r9)
jmp 0x44c1a
xorl $0x1, %edi
xorl %r9d, %r9d
xorl %r10d, %r10d
jmp 0x44b4e
leaq 0x1(%r12), %rax
xorl %ecx, %ecx
leaq (%r14,%r12), %rdx
incq %rdx
movb %cl, -0x1(%rdx)
movq 0x38(%rbx), %rsi
movl %eax, (%rsi,%r13,4)
addl $0x2, %r12d
movb %cl, (%rdx)
movq %r14, 0x18(%rbx)
movq %r14, (%rbx)
movl %r12d, 0x8(%rbx)
movq %rdx, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq