// File: /workspace/github_c_makefile_star2_O2/gregtour[P]minimal-compiler/main.c
// Function: TestParser
int TestParser(const char* program)
{
    L_TOKEN*      lexing;
    SYNTAX_TREE*  syntax;
    char*         buffer;
    SOURCE*       sourceIndex;

    printf("\n");
    PrintGrammar(CONTEXT_FREE_GRAMMAR);

    // lex source
    buffer = 0;
    lexing = LexSource(program, &buffer, CONTEXT_FREE_GRAMMAR);
    if (lexing == NULL)
    {
        printf("Error lexing source or empty source file.\n");
        FreeLexing(lexing, buffer);
        return 3;
    }
    PrintLexing(lexing);

#ifdef USE_COMPRESSED_TABLES
    DecompressAndPatchParseTable(&PARSE_TABLE, 
        COMPRESSED_GOTO_TABLE, sizeof(COMPRESSED_GOTO_TABLE)/sizeof(int),
        COMPRESSED_ACTION_TABLE, sizeof(COMPRESSED_ACTION_TABLE)/sizeof(int));
#endif

    // parse source
    syntax = ParseSource(lexing, PARSE_TABLE, CONTEXT_FREE_GRAMMAR);
    if (syntax == NULL)
    {
        printf("Error parsing source.\n");
        FreeLexing(lexing, buffer);
        return 4;
    }

    // linker
    LinkPrintf();
    
    // preprocessor
    PrePassReductions(&syntax);
    PrintParseTree(syntax, CONTEXT_FREE_GRAMMAR);

    // index source in source list
    AddSourceToList(&gPrgrmSources, program, lexing, syntax);
    sourceIndex = GetSourceFromList(gPrgrmSources, program);

    Assert(sourceIndex);

    sourceIndex->buffer = buffer;

    // compilation stage 1
    SourceReductions(&syntax);
    StaticAnalysis(syntax);

    // done for now
    printf("Success.\n");
    //FreeLexing(lexing, buffer);
    //FreeParseTree(syntax);

    // free compiler data structures
    FreeCompiler();

#ifdef USE_COMPRESSED_TABLES
    // free uncompressed parse tables
    free(PARSE_TABLE.gotoTable);
    free(PARSE_TABLE.actionTable);
#endif

    getchar();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
pushq $0xa
popq %rdi
callq 0x2040
leaq 0x722b(%rip), %r14      # 0xba20
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x3814
leaq -0x30(%rbp), %rsi
andq $0x0, (%rsi)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x3eff
testq %rax, %rax
je 0x496b
movq %rax, %r12
movq %rax, %rdi
callq 0x45e9
leaq 0x139eb(%rip), %r15     # 0x18248
leaq 0x71ec(%rip), %rsi      # 0xba50
leaq 0x8685(%rip), %rcx      # 0xcef0
movq %r15, %rdi
movl $0x526, %edx            # imm = 0x526
movl $0x2cd6, %r8d           # imm = 0x2CD6
callq 0x5e23
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x40(%rsp)
movups %xmm1, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x4faf
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x4986
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x46dc
leaq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x5610
movq (%r13), %rdi
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x550f
movq (%r13), %rcx
leaq 0x13a60(%rip), %r14     # 0x18368
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x5b1c
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x5df4
movq -0x30(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq %r13, %rdi
callq 0x57e3
movq (%r13), %rdi
callq 0x57e9
leaq 0x2cb2(%rip), %rdi      # 0x75f3
callq 0x2050
callq 0x49b4
leaq 0x138f6(%rip), %rbx     # 0x18248
movq 0x18(%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
callq 0x20d0
jmp 0x49a2
leaq 0x2ca0(%rip), %rdi      # 0x7612
callq 0x2050
movq -0x30(%rbp), %rsi
xorl %edi, %edi
callq 0x4699
pushq $0x3
jmp 0x49a0
leaq 0x2c6f(%rip), %rdi      # 0x75fc
callq 0x2050
movq -0x30(%rbp), %rsi
movq %r12, %rdi
callq 0x4699
pushq $0x4
popq %r15
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq