// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %rsi, %rbx
xorl %eax, %eax
movq %rax, -0x48(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x40bc(%rip), %rsi      # 0x8142
callq 0x2120
testq %rax, %rax
je 0x439d
movq %rax, %r14
movq %rbx, -0x60(%rbp)
movabsq $0x100000000, %rbx      # imm = 0x100000000
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2110
movq %r14, %rdi
callq 0x20f0
movq %rax, %r13
movq %r14, %rdi
callq 0x20a0
movq %r13, %r12
shlq $0x20, %r12
addq %rbx, %r12
movq %r12, %rdi
sarq $0x20, %rdi
movq %rdi, -0x30(%rbp)
callq 0x2100
movq %rax, %rbx
movslq %r13d, %r15
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r14, %rcx
callq 0x2060
movb $0x0, (%rbx,%r15)
movq %r14, %rdi
callq 0x2070
testl %r15d, %r15d
je 0x43ab
sarq $0x1e, %r12
movq %r12, %rdi
callq 0x2100
testl %r13d, %r13d
movq %rax, -0x68(%rbp)
js 0x43bf
movq %rax, %r12
leal 0x1(%r13), %eax
xorl %ecx, %ecx
xorl %esi, %esi
movl %esi, %edx
movl %esi, (%r12,%rcx,4)
xorl %esi, %esi
cmpb $0xa, (%rbx,%rcx)
sete %sil
addl %edx, %esi
incq %rcx
cmpq %rcx, %rax
jne 0x4134
movl %esi, -0x34(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2100
movq %rax, %r15
leal -0x1(%r13), %eax
movl %r13d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, -0x30(%rbp)
leaq 0x1(%rbx), %rcx
movq %rcx, -0x40(%rbp)
xorl %edx, %edx
leaq 0x434d(%rip), %rsi      # 0x84cc
xorl %edi, %edi
movslq %edi, %r9
movb (%rbx,%r9), %r8b
movzbl %r8b, %r10d
cmpl $0x1f, %r10d
jle 0x4217
leal -0x20(%r10), %r11d
cmpl $0x7, %r11d
ja 0x42c7
movslq (%rsi,%r11,4), %r10
addq %rsi, %r10
jmpq *%r10
movslq %edx, %r9
movb %r8b, (%r15,%r9)
incl %r9d
leal 0x1(%rdi), %r10d
cmpl %eax, %r10d
jge 0x42a6
movslq %r10d, %r11
movb (%rbx,%r11), %r14b
cmpb %r8b, %r14b
je 0x42a6
cmpb $0x5c, %r14b
jne 0x4200
movl (%r12,%r11,4), %r10d
movslq %r9d, %r9
movl %r10d, (%r12,%r9,4)
movslq %edi, %r11
addl $0x2, %edx
movb $0x5c, (%r15,%r9)
movb 0x2(%rbx,%r11), %r14b
addq $0x2, %r11
movl %r11d, %r10d
movl %edx, %r9d
movl %r9d, %edx
movl %r10d, %edi
movl (%r12,%r11,4), %r10d
movslq %r9d, %r9
movl %r10d, (%r12,%r9,4)
movb %r14b, (%r15,%r9)
jmp 0x41b5
leal -0x9(%r10), %r11d
cmpl $0x2, %r11d
jb 0x422b
cmpl $0xd, %r10d
jne 0x4307
movslq %edx, %r8
movb $0x20, (%r15,%r8)
movl (%r12,%r9,4), %r10d
movl %r10d, (%r12,%r8,4)
cmpl %r13d, %edi
jge 0x4348
movq %rdx, %rcx
movq %r15, %rdx
leaq (%rbx,%r9), %r10
leaq (%r12,%r9,4), %r11
movq -0x30(%rbp), %r14
subq %r9, %r14
xorl %r9d, %r9d
movzbl (%r10,%r9), %r15d
cmpl $0xc, %r15d
jg 0x4286
cmpl $0x9, %r15d
je 0x4296
cmpl $0xa, %r15d
jne 0x433f
movb $0xa, (%rdx,%r8)
movl (%r11,%r9,4), %r15d
movl %r15d, (%r12,%r8,4)
jmp 0x4296
cmpl $0xd, %r15d
je 0x4296
cmpl $0x20, %r15d
jne 0x433f
incq %r9
cmpq %r9, %r14
jne 0x425c
movl %r13d, %edi
jmp 0x4342
movslq %r10d, %rdi
movl (%r12,%rdi,4), %r8d
movslq %r9d, %r9
movl %r8d, (%r12,%r9,4)
movb (%rbx,%rdi), %dil
addl $0x2, %edx
movb %dil, (%r15,%r9)
movl %r10d, %edi
jmp 0x434c
cmpl $0x2f, %r10d
jne 0x4307
movzbl 0x1(%rbx,%r9), %r10d
cmpl $0x2a, %r10d
je 0x4360
cmpl $0x2f, %r10d
jne 0x4307
cmpl %r13d, %edi
jge 0x435c
leaq (%rbx,%r9), %r8
movq -0x30(%rbp), %r10
subq %r9, %r10
xorl %r9d, %r9d
cmpb $0xa, (%r8,%r9)
je 0x4359
incq %r9
cmpq %r9, %r10
jne 0x42f6
jmp 0x433a
movl (%r12,%r9,4), %r9d
movslq %edx, %r10
movl %r9d, (%r12,%r10,4)
movb %r8b, (%r15,%r10)
jmp 0x434a
cmpl %r13d, %edi
jge 0x435c
leaq (%rbx,%r9), %r8
movq -0x30(%rbp), %r10
subq %r9, %r10
xorl %r9d, %r9d
cmpb $0xa, (%r8,%r9)
je 0x4359
incq %r9
cmpq %r9, %r10
jne 0x432b
movl %r13d, %edi
jmp 0x435c
addl %r9d, %edi
movq %rdx, %r15
movq %rcx, %rdx
decl %edi
incl %edx
incl %edi
cmpl %r13d, %edi
jl 0x4181
jmp 0x43a6
addl %r9d, %edi
decl %edi
jmp 0x434c
addl $0x2, %edi
cmpl %eax, %edi
jge 0x4399
movslq %edi, %r9
movq -0x40(%rbp), %rcx
leaq (%rcx,%r9), %r8
movq %rax, %r10
subq %r9, %r10
xorl %r9d, %r9d
cmpb $0x2a, -0x1(%r8,%r9)
jne 0x438a
cmpb $0x2f, (%r8,%r9)
je 0x4396
incq %r9
cmpq %r9, %r10
jne 0x437b
movl %eax, %edi
jmp 0x4399
addl %r9d, %edi
incl %edi
jmp 0x434c
leaq 0x41d5(%rip), %rdi      # 0x8579
jmp 0x43b2
movq %rdx, %r14
jmp 0x43d5
leaq 0x41ab(%rip), %rdi      # 0x855d
callq 0x2050
xorl %r14d, %r14d
jmp 0x485f
movq -0x30(%rbp), %rdi
callq 0x2100
movq %rax, %r15
movl $0x0, -0x34(%rbp)
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x2030
movslq %r14d, %rdi
movb $0x0, (%r15,%rdi)
testl %edi, %edi
jle 0x480d
movq %r14, %rdx
xorl %r12d, %r12d
movq %r15, -0x30(%rbp)
movq %r14, -0x40(%rbp)
movq %rdi, -0x58(%rbp)
movslq %r12d, %r14
movq -0x68(%rbp), %rax
movl (%rax,%r14,4), %r8d
leaq (%r15,%r14), %rbx
movzbl (%r15,%r14), %eax
movl %eax, %ecx
andb $-0x21, %cl
addb $-0x5b, %cl
cmpb $-0x1a, %cl
movl %r8d, -0x34(%rbp)
jae 0x44af
leal -0x3a(%rax), %ecx
cmpb $-0xa, %cl
movabsq $0x100000000, %rdx      # imm = 0x100000000
jae 0x44f6
cmpl $0x27, %eax
movq -0x40(%rbp), %rdx
ja 0x4713
movl %eax, %ecx
movabsq $0x100000400, %rsi      # imm = 0x100000400
btq %rcx, %rsi
jb 0x4801
movabsq $0x8400000000, %rsi     # imm = 0x8400000000
btq %rcx, %rsi
jae 0x4704
leal 0x1(%r12), %ecx
cmpl %ecx, %edx
cmovgl %edx, %ecx
leal -0x1(%rcx), %r13d
incq %r14
movl %r12d, %r15d
cmpq %rdi, %r14
jge 0x466f
incl %r15d
leaq 0x1(%r14), %rdx
movq -0x30(%rbp), %rsi
cmpb %al, (%rsi,%r14)
movq %rdx, %r14
jne 0x4489
leal -0x1(%r15), %r13d
jmp 0x4672
movl %r12d, %r13d
cmpl %edx, %r12d
jge 0x453d
movq %rdi, %rax
subq %r14, %rax
xorl %r13d, %r13d
movb (%rbx,%r13), %cl
movl %ecx, %edx
andb $-0x21, %dl
addb $-0x5b, %dl
cmpb $-0x1b, %dl
ja 0x44e8
leal -0x30(%rcx), %edx
cmpb $0xa, %dl
setae %dl
cmpb $0x5f, %cl
setne %cl
testb %dl, %cl
jne 0x453a
incq %r13
cmpq %r13, %rax
jne 0x44c4
movq -0x40(%rbp), %r13
jmp 0x453d
movl %r12d, %r15d
cmpl -0x40(%rbp), %r12d
jge 0x4617
movq %rdi, %rax
subq %r14, %rax
shlq $0x20, %r14
xorl %r15d, %r15d
movb (%rbx,%r15), %cl
addb $-0x3a, %cl
cmpb $-0xb, %cl
jbe 0x45c6
addq %rdx, %r14
incq %r15
cmpq %r15, %rax
jne 0x4510
movq %rdi, %r14
movq -0x40(%rbp), %rcx
movl %ecx, %r15d
jmp 0x45d1
addl %r12d, %r13d
movl $0x20, %edi
callq 0x2100
movq %rax, %r15
movl %r13d, %r14d
subl %r12d, %r14d
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 %rbx, %rdi
movl %r14d, %esi
callq 0x30a5
testl %eax, %eax
jne 0x4585
leaq 0x7b49(%rip), %rax      # 0xc0cc
movl (%rax), %eax
movl %eax, (%r15)
movq %rbx, 0x8(%r15)
movl %r14d, 0x10(%r15)
movl -0x34(%rbp), %eax
movl %eax, 0x14(%r15)
movq $0x0, 0x18(%r15)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %r15, %rdx
callq 0x3c6c
decl %r13d
movl %r13d, %r12d
movq -0x30(%rbp), %r15
movq -0x40(%rbp), %rdx
movq -0x58(%rbp), %rdi
jmp 0x4801
addl %r12d, %r15d
sarq $0x20, %r14
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
cmpb $0x2e, (%rax,%r14)
jne 0x4617
incl %r15d
cmpl %r15d, %ecx
cmovgl %ecx, %r15d
leal -0x1(%r15), %r13d
movq %r14, %rax
incq %rax
cmpq %rdi, %rax
jge 0x46bb
movq -0x30(%rbp), %rcx
movb (%rcx,%rax), %cl
addb $-0x3a, %cl
incl %r14d
incq %rax
cmpb $-0xb, %cl
ja 0x45f0
leal -0x1(%r14), %r13d
jmp 0x46be
movl $0x20, %edi
movl %r8d, %r14d
callq 0x2100
leaq 0x7a95(%rip), %rcx      # 0xc0c0
movl (%rcx), %ecx
movl %ecx, (%rax)
movq %rbx, 0x8(%rax)
movl %r15d, %ecx
subl %r12d, %ecx
movl %ecx, 0x10(%rax)
movl %r14d, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x3c6c
movq -0x58(%rbp), %rdi
decl %r15d
movl %r15d, %r12d
movq -0x30(%rbp), %r15
movq -0x40(%rbp), %rdx
jmp 0x4801
movl %ecx, %r15d
movl $0x20, %edi
callq 0x2100
leaq 0x7a45(%rip), %rcx      # 0xc0c8
movl (%rcx), %ecx
movl %ecx, (%rax)
incq %rbx
movq %rbx, 0x8(%rax)
subl %r12d, %r13d
movl %r13d, 0x10(%rax)
movl -0x34(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x3c6c
movl %r15d, %r12d
jmp 0x45b5
movl %r15d, %r14d
movl $0x20, %edi
callq 0x2100
leaq 0x79f5(%rip), %rcx      # 0xc0c4
movl (%rcx), %ecx
movl %ecx, (%rax)
movq %rbx, 0x8(%rax)
subl %r12d, %r14d
movl %r14d, 0x10(%rax)
movl -0x34(%rbp), %ecx
movl %ecx, 0x14(%rax)
movq $0x0, 0x18(%rax)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x3c6c
movl %r13d, %r12d
jmp 0x45b5
movl $0x2200, %eax           # imm = 0x2200
btq %rcx, %rax
jb 0x4871
movl %r12d, %r13d
cmpl %edx, %r12d
jge 0x47b5
subq %r14, %rdi
movq %rdi, -0x70(%rbp)
xorl %r15d, %r15d
movl %r12d, %r13d
xorl %r14d, %r14d
movzbl (%rbx,%r15), %eax
leal -0x3a(%rax), %ecx
cmpb $-0xb, %cl
ja 0x47a6
movl %eax, %ecx
andb $-0x21, %cl
addb $-0x5b, %cl
cmpb $-0x1b, %cl
ja 0x47a6
cmpl $0x20, %eax
ja 0x4760
movl %eax, %eax
movabsq $0x100002600, %rcx      # imm = 0x100002600
btq %rax, %rcx
jb 0x47a6
incq %r15
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 %rbx, %rdi
movl %r15d, %esi
callq 0x30a5
movq -0x40(%rbp), %rcx
movl %r13d, %edx
incl %edx
testl %eax, %eax
movl %edx, %r13d
cmovnel %edx, %r14d
cmpq %r15, -0x70(%rbp)
jne 0x472f
movl %ecx, %r13d
testl %r14d, %r14d
cmovnel %r14d, %r13d
movq -0x30(%rbp), %r15
movl -0x34(%rbp), %r8d
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 %r15, %rdi
movl %r12d, %esi
movl %r13d, %edx
movl %r8d, %ecx
callq 0x3e4e
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movq %rax, %rdx
callq 0x3c6c
movq -0x58(%rbp), %rdi
movq -0x40(%rbp), %rdx
decl %r13d
movl %r13d, %r12d
incl %r12d
cmpl %edx, %r12d
jl 0x43ff
movl $0x20, %edi
callq 0x2100
leaq 0x789a(%rip), %rcx      # 0xc0b8
movl (%rcx), %ecx
movl %ecx, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movl $0x0, 0x10(%rax)
movl -0x34(%rbp), %edx
movl %edx, 0x14(%rax)
movq %rcx, 0x18(%rax)
leaq -0x48(%rbp), %rbx
leaq -0x50(%rbp), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x3c6c
movq -0x68(%rbp), %rdi
callq 0x2030
movq -0x60(%rbp), %rax
movq %r15, (%rax)
movq (%rbx), %r14
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r12
movq -0x48(%rbp), %r15
movq %r15, %rdi
movl %r8d, %r13d
callq 0x48c3
incl %r13d
leaq 0x3c9a(%rip), %rdi      # 0x8527
xorl %r14d, %r14d
movl %r13d, %esi
xorl %eax, %eax
callq 0x2090
movsbl (%rbx), %esi
leaq 0x3c9d(%rip), %rdi      # 0x8541
xorl %eax, %eax
callq 0x2090
movq %r15, %rdi
movq %r12, %rsi
callq 0x4972
movq -0x60(%rbp), %rax
movq $0x0, (%rax)
jmp 0x485f