// File: /workspace/github_c_makefile_star2_O1/gregtour[P]minimal-compiler/lexer.c
// Function: LexSource
L_TOKEN* LexSource(const char*    file,
                   char**         stripped,
                   GRAMMAR_TABLE  table)
{
    FILE* input;
    char* buffer;
    char* format;
    int*  lineNumbers;
    int   line;
    int   size;
    int   read;
    int   i, j;
    int   a, b;

    L_TOKEN* start = NULL;
    L_TOKEN* end = NULL;

    // read source file
    // printf("Loading source file from %s...\n", file);
    input = fopen(file, "rb");
    if (input == 0) {
        printf("Could not open source file.\n");
        return 0;
    }
    fseek(input, 0, SEEK_END);
    size = ftell(input);
    rewind(input);
    buffer = (char*)malloc(size+1);
    read = fread(buffer, 1, size, input);
    buffer[size] = 0;
    fclose(input);
    
    // printf("Read %i of %i bytes.\n", read, size);

    if (size == 0) {
        printf("Unable to read source file.\n");
        return 0;
    }
    
    // count lines
    lineNumbers = (int*)malloc((size+1)*sizeof(int));
    line = 0;
    for (i = 0; i <= size; i++)
    {
        lineNumbers[i] = line;
        if (buffer[i] == '\n')
            line++;
    }

    // strip clean
    format = (char*)malloc(size+1);
    j = 0;
    for (i = 0; i < size; i++)
    {
        if (buffer[i] == '/' &&
            buffer[i+1] == '/')
        {
            // inline comments
            while (i < size && buffer[i] != '\n') i++;
            i--;
        }
        else if (buffer[i] == '/' &&
                 buffer[i+1] == '*')
        {
            // multiline comments
            i++; i++;
            while (i < size - 1 &&
                   (buffer[i] != '*' ||
                    buffer[i+1] != '/'))
            {
                i++;
            }
            i++;
        }
#ifdef IGNORE_MACROS
        else if (buffer[i] == '#')
        {
            while (i < size && buffer[i] != '\n') i++;
            i--;
        }
#endif
        else if (isSpace(buffer[i]))
        {
            // whitespace
            format[j] = ' ';
            lineNumbers[j] = lineNumbers[i];

            while (i < size && isSpace(buffer[i]))
            {
                if (buffer[i] == '\n') {
                    format[j] = '\n';
                    lineNumbers[j] = lineNumbers[i];
                }
                i++;
            }
            i--;
            j++;
        }
        else if (buffer[i] == '"' ||
                 buffer[i] == '\'')
        {
            char quote = buffer[i];
            // string
            format[j++] = buffer[i++];
            while (i < size - 1 && buffer[i] != quote)
            {
                if (buffer[i] == '\\')
                {
                    lineNumbers[j] = lineNumbers[i];
                    format[j++] = buffer[i++];
                }
                lineNumbers[j] = lineNumbers[i];
                format[j++] = buffer[i++];
            }
            lineNumbers[j] = lineNumbers[i];
            format[j++] = buffer[i];
        }
        else
        {
            // character
            lineNumbers[j] = lineNumbers[i];
            format[j] = buffer[i];
            j++;
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbx
xorl %eax, %eax
movq %rax, -0x58(%rbp)
movq %rax, -0x60(%rbp)
leaq 0x40e9(%rip), %rsi      # 0x8142
callq 0x2120
testq %rax, %rax
je 0x43b5
movq %rax, %r15
movq %rbx, -0x70(%rbp)
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2110
movq %r15, %rdi
callq 0x20f0
movq %rax, %r14
movq %r15, %rdi
callq 0x20a0
movq %r14, %rax
shlq $0x20, %rax
movabsq $0x100000000, %r12      # imm = 0x100000000
addq %rax, %r12
movq %r12, %rdi
sarq $0x20, %rdi
movq %rdi, -0x30(%rbp)
callq 0x2100
movq %rax, %r13
movslq %r14d, %rbx
movl $0x1, %esi
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x2060
movb $0x0, (%r13,%rbx)
movq %r15, %rdi
callq 0x2070
testl %ebx, %ebx
je 0x43be
sarq $0x1e, %r12
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
testl %r14d, %r14d
movl $0x0, %esi
js 0x411d
leal 0x1(%r14), %eax
xorl %ecx, %ecx
xorl %esi, %esi
movl %esi, (%r12,%rcx,4)
xorl %edx, %edx
cmpb $0xa, (%r13,%rcx)
sete %dl
addl %edx, %esi
incq %rcx
cmpq %rcx, %rax
jne 0x4104
movq %rsi, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2100
movq %rax, -0x30(%rbp)
testl %r14d, %r14d
jle 0x43d2
leal -0x1(%r14), %eax
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movslq %eax, %rdx
movq %rdx, -0x50(%rbp)
leaq 0x1(%r13), %rdx
movq %rdx, -0x38(%rbp)
xorl %r15d, %r15d
leaq 0x436f(%rip), %rdi      # 0x84cc
xorl %r8d, %r8d
movq %r14, %rdx
movslq %r8d, %r10
movzbl (%r13,%r10), %r9d
cmpl $0x2f, %r9d
jne 0x41ff
cmpb $0x2f, 0x1(%r13,%r10)
jne 0x41ac
cmpl %r14d, %r8d
jge 0x438b
leaq (%r10,%r13), %r9
movq %rcx, %r11
subq %r10, %r11
xorl %r10d, %r10d
cmpb $0xa, (%r9,%r10)
je 0x4388
incq %r10
cmpq %r10, %r11
jne 0x4194
jmp 0x4383
cmpb $0x2f, %r9b
jne 0x41ff
cmpb $0x2a, 0x1(%r13,%r10)
jne 0x41ff
addl $0x2, %r8d
cmpl %eax, %r8d
jge 0x43b0
movslq %r8d, %r10
movq -0x38(%rbp), %rsi
leaq (%rsi,%r10), %r9
movq -0x50(%rbp), %r11
subq %r10, %r11
xorl %r10d, %r10d
cmpb $0x2a, -0x1(%r9,%r10)
jne 0x41ef
cmpb $0x2f, (%r9,%r10)
je 0x43ad
incq %r10
cmpq %r10, %r11
jne 0x41dc
movl %eax, %r8d
jmp 0x43b0
leal -0x20(%r9), %r11d
cmpl $0x7, %r11d
ja 0x4294
movslq (%rdi,%r11,4), %r11
addq %rdi, %r11
jmpq *%r11
movslq %r15d, %r11
movq -0x30(%rbp), %r10
movb %r9b, (%r10,%r11)
incl %r11d
leal 0x1(%r8), %r10d
cmpl %eax, %r10d
jge 0x4326
movslq %r10d, %r14
movb (%r13,%r14), %bl
cmpb %r9b, %bl
je 0x4326
cmpb $0x5c, %bl
jne 0x426b
movl (%r12,%r14,4), %r10d
movslq %r11d, %r11
movl %r10d, (%r12,%r11,4)
addl $0x2, %r8d
addl $0x2, %r15d
movq -0x30(%rbp), %r14
movb %bl, (%r14,%r11)
movl %r8d, %r10d
movl %r15d, %r11d
jmp 0x426f
movq -0x30(%rbp), %r14
movl %r11d, %r15d
movl %r10d, %r8d
movslq %r10d, %r10
movl (%r12,%r10,4), %ebx
movslq %r11d, %r11
movl %ebx, (%r12,%r11,4)
movb (%r13,%r10), %bl
movb %bl, (%r14,%r11)
incl %r11d
incl %r10d
jmp 0x4229
leal -0x9(%r9), %r11d
cmpl $0x2, %r11d
jb 0x42a8
cmpl $0xd, %r9d
jne 0x434d
movslq %r15d, %r9
movq -0x30(%rbp), %r11
movb $0x20, (%r11,%r9)
movl (%r12,%r10,4), %r11d
movl %r11d, (%r12,%r9,4)
cmpl %r14d, %r8d
jge 0x4399
movq %r15, %rsi
leaq (%r10,%r13), %r11
leaq (%r12,%r10,4), %rbx
movq %rcx, %r14
subq %r10, %r14
xorl %r10d, %r10d
movzbl (%r11,%r10), %r15d
cmpl $0xc, %r15d
jg 0x4307
cmpl $0x9, %r15d
je 0x4313
cmpl $0xa, %r15d
jne 0x4390
movq -0x30(%rbp), %r15
movb $0xa, (%r15,%r9)
movl (%rbx,%r10,4), %r15d
movl %r15d, (%r12,%r9,4)
jmp 0x4313
cmpl $0xd, %r15d
je 0x4313
cmpl $0x20, %r15d
jne 0x4390
incq %r10
cmpq %r10, %r14
jne 0x42d9
movq %rdx, %r14
movl %r14d, %r8d
movq %rsi, %r15
jmp 0x4399
movslq %r10d, %r8
movl (%r12,%r8,4), %r9d
movslq %r11d, %r11
movl %r9d, (%r12,%r11,4)
movb (%r13,%r8), %r8b
addl $0x2, %r15d
movq -0x30(%rbp), %r9
movb %r8b, (%r9,%r11)
movl %r10d, %r8d
movq %rdx, %r14
jmp 0x439f
movl (%r12,%r10,4), %r10d
movslq %r15d, %r11
movl %r10d, (%r12,%r11,4)
movq -0x30(%rbp), %r10
movb %r9b, (%r10,%r11)
jmp 0x439c
cmpl %r14d, %r8d
jge 0x438b
leaq (%r10,%r13), %r9
movq %rcx, %r11
subq %r10, %r11
xorl %r10d, %r10d
cmpb $0xa, (%r9,%r10)
je 0x4388
incq %r10
cmpq %r10, %r11
jne 0x4374
movl %r14d, %r8d
jmp 0x438b
addl %r10d, %r8d
decl %r8d
jmp 0x439f
addl %r10d, %r8d
movq %rsi, %r15
movq %rdx, %r14
decl %r8d
incl %r15d
incl %r8d
cmpl %r14d, %r8d
jl 0x4163
jmp 0x43d5
addl %r10d, %r8d
incl %r8d
jmp 0x439f
leaq 0x41bd(%rip), %rdi      # 0x8579
jmp 0x43c5
leaq 0x4198(%rip), %rdi      # 0x855d
callq 0x2050
xorl %r15d, %r15d
jmp 0x484a
xorl %r15d, %r15d
movq %r13, %rdi
callq 0x2030
movslq %r15d, %rax
movq -0x30(%rbp), %r8
movb $0x0, (%r8,%rax)
testl %r15d, %r15d
jle 0x47f5
movl %r15d, %r14d
xorl %r13d, %r13d
movq %r15, -0x38(%rbp)
movq %r12, -0x40(%rbp)
movslq %r13d, %rax
movl (%r12,%rax,4), %r12d
leaq (%r8,%rax), %rcx
movq %rcx, -0x50(%rbp)
movzbl (%r8,%rax), %ecx
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x5b, %dl
cmpb $-0x1a, %dl
movq %r12, -0x48(%rbp)
jae 0x4476
leal -0x3a(%rcx), %esi
cmpb $-0xa, %sil
jae 0x44ba
cmpl $0x27, %ecx
je 0x4440
cmpl $0x22, %ecx
jne 0x4650
leal 0x1(%r13), %edx
cmpl %edx, %r15d
cmovgl %r15d, %edx
leal -0x1(%rdx), %r15d
incq %rax
movl %r13d, %ebx
cmpq %r14, %rax
jge 0x456b
incl %ebx
leaq 0x1(%rax), %rsi
cmpb %cl, (%r8,%rax)
movq %rsi, %rax
jne 0x4455
leal -0x1(%rbx), %r15d
jmp 0x456d
movl %r13d, %r12d
cmpl %r15d, %r13d
jge 0x45b8
movb (%r8,%rax), %cl
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x5b, %dl
cmpb $-0x1b, %dl
ja 0x44aa
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
setae %dl
cmpb $0x5f, %cl
setne %cl
testb %dl, %cl
jne 0x45b5
incq %rax
cmpq %rax, %r14
jne 0x4482
movl %r14d, %r12d
jmp 0x45b8
movl %r13d, %ebx
cmpl %r15d, %r13d
jge 0x44da
movslq %r13d, %rbx
movb (%r8,%rbx), %al
addb $-0x3a, %al
cmpb $-0xa, %al
jb 0x44da
incq %rbx
cmpq %rbx, %r14
jne 0x44c5
movl %r14d, %ebx
movslq %ebx, %rax
cmpb $0x2e, (%r8,%rax)
jne 0x4518
leal 0x1(%rbx), %ecx
cmpl %ecx, %r15d
cmovgl %r15d, %ecx
leal -0x1(%rcx), %r15d
incq %rax
cmpq %r14, %rax
jge 0x467e
movb (%r8,%rax), %dl
addb $-0x3a, %dl
incl %ebx
incq %rax
cmpb $-0xb, %dl
ja 0x44f5
leal -0x1(%rbx), %r15d
jmp 0x4680
movl $0x20, %edi
callq 0x2100
leaq 0x7b97(%rip), %rcx      # 0xc0c0
movl (%rcx), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl %ebx, %ecx
subl %r13d, %ecx
movl %ecx, 0x10(%rax)
movl %r12d, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x3c44
movq -0x30(%rbp), %r8
decl %ebx
movl %ebx, %r13d
movq -0x40(%rbp), %r12
jmp 0x463f
movl %edx, %ebx
movl $0x20, %edi
callq 0x2100
leaq 0x7b4a(%rip), %rcx      # 0xc0c8
movl (%rcx), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
incq %rcx
movq %rcx, 0x8(%rax)
subl %r13d, %r15d
movl %r15d, 0x10(%rax)
movl %r12d, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x3c44
movl %ebx, %r13d
jmp 0x4633
movl %eax, %r12d
movl $0x20, %edi
callq 0x2100
movq %rax, %rbx
movl %r12d, %r15d
subl %r13d, %r15d
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq -0x50(%rbp), %r13
movq %r13, %rdi
movl %r15d, %esi
callq 0x30cd
testl %eax, %eax
jne 0x4604
leaq 0x7aca(%rip), %rax      # 0xc0cc
movl (%rax), %eax
movl %eax, (%rbx)
movq %r13, 0x8(%rbx)
movl %r15d, 0x10(%rbx)
movq -0x48(%rbp), %rax
movl %eax, 0x14(%rbx)
movq $0x0, 0x18(%rbx)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %rbx, %rdx
callq 0x3c44
decl %r12d
movl %r12d, %r13d
movq -0x40(%rbp), %r12
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r15
incl %r13d
cmpl %r15d, %r13d
jl 0x4400
jmp 0x47f5
cmpb $-0x1a, %dl
setae %dl
leal -0x3a(%rcx), %esi
cmpb $-0xa, %sil
setae %sil
orb %dl, %sil
jne 0x46c7
cmpl $0xc, %ecx
jg 0x46e2
cmpl $0xa, %ecx
je 0x4562
cmpl $0x9, %ecx
jne 0x46f4
jmp 0x485f
movl %ecx, %ebx
movl $0x20, %edi
callq 0x2100
leaq 0x7a33(%rip), %rcx      # 0xc0c4
movl (%rcx), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
subl %r13d, %ebx
movl %ebx, 0x10(%rax)
movl %r12d, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x3c44
movl %r15d, %r13d
jmp 0x4633
cmpl $0xa, %ecx
je 0x4562
cmpl $0x20, %ecx
movq -0x40(%rbp), %r12
je 0x463f
jmp 0x485f
cmpl $0x20, %ecx
je 0x4562
cmpl $0xd, %ecx
je 0x485f
xorl %esi, %esi
movl %r13d, %edx
cmpl %r15d, %r13d
movq -0x48(%rbp), %rcx
jge 0x47a8
movq %r14, %rcx
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
xorl %ebx, %ebx
movl %r13d, %edx
xorl %esi, %esi
movq -0x50(%rbp), %r12
movzbl (%r12,%rbx), %eax
leal -0x3a(%rax), %ecx
cmpb $-0xb, %cl
ja 0x47a0
movl %eax, %ecx
andb $-0x21, %cl
addb $-0x5b, %cl
cmpb $-0x1b, %cl
ja 0x47a0
cmpl $0x20, %eax
ja 0x474c
movl %eax, %eax
movabsq $0x100002600, %rcx      # imm = 0x100002600
btq %rax, %rcx
jb 0x47a0
incq %rbx
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq -0x50(%rbp), %r12
movq %r12, %rdi
movl %esi, -0x64(%rbp)
movl %ebx, %esi
movl %edx, %r15d
callq 0x30cd
movl -0x64(%rbp), %esi
movl %r15d, %edx
movq -0x30(%rbp), %r8
incl %edx
testl %eax, %eax
cmovnel %edx, %esi
cmpq %rbx, -0x78(%rbp)
jne 0x471b
movq -0x38(%rbp), %r15
movl %r15d, %edx
jmp 0x47a4
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %rcx
testl %esi, %esi
cmovnel %esi, %edx
leaq 0x10(%rbp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r8, %rdi
movl %r13d, %esi
movl %edx, %ebx
callq 0x3e1e
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x3c44
movq -0x30(%rbp), %r8
decl %ebx
movl %ebx, %r13d
jmp 0x4562
movl $0x20, %edi
movq %r8, %r14
callq 0x2100
leaq 0x78af(%rip), %rcx      # 0xc0b8
movl (%rcx), %ecx
movl %ecx, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movl $0x0, 0x10(%rax)
movq -0x48(%rbp), %rdx
movl %edx, 0x14(%rax)
movq %rcx, 0x18(%rax)
leaq -0x58(%rbp), %rbx
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x3c44
movq %r12, %rdi
callq 0x2030
movq -0x70(%rbp), %rax
movq %r14, (%rax)
movq (%rbx), %r15
movq %r15, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r8, %r14
callq 0x48b2
movq -0x48(%rbp), %rsi
incl %esi
leaq 0x3cac(%rip), %rdi      # 0x8527
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x2090
movq -0x50(%rbp), %rax
movsbl (%rax), %esi
leaq 0x3cae(%rip), %rdi      # 0x8541
xorl %eax, %eax
callq 0x2090
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4961
movq -0x70(%rbp), %rax
movq $0x0, (%rax)
jmp 0x484a