// File: /workspace/github_c_makefile_star2_O3/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
movl $0xa, %edi
callq 0x2040
leaq 0x7f49(%rip), %r14      # 0xca20
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x3940
leaq -0x30(%rbp), %rsi
movq $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 0x4061
testq %rax, %rax
je 0x4c50
movq %rax, %r12
movq %rax, %rdi
callq 0x48c3
leaq 0x14706(%rip), %r15     # 0x19248
leaq 0x7f07(%rip), %rsi      # 0xca50
leaq 0x93a0(%rip), %rcx      # 0xdef0
movq %r15, %rdi
movl $0x526, %edx            # imm = 0x526
movl $0x2cd6, %r8d           # imm = 0x2CD6
callq 0x6519
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 0x53ce
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x4c6f
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x49bc
leaq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x5b24
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 0x5a20
movq (%r13), %rcx
leaq 0x1477b(%rip), %r14     # 0x19368
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x61ac
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x64e5
movq -0x30(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq %r13, %rdi
callq 0x5cf8
movq (%r13), %rdi
callq 0x5cfe
leaq 0x39cd(%rip), %rdi      # 0x85f3
callq 0x2050
callq 0x4c9f
leaq 0x14611(%rip), %rbx     # 0x19248
movq 0x18(%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
callq 0x20d0
jmp 0x4c8d
leaq 0x39bb(%rip), %rdi      # 0x8612
callq 0x2050
movq -0x30(%rbp), %rsi
xorl %edi, %edi
callq 0x4972
movl $0x3, %r15d
jmp 0x4c8d
leaq 0x3986(%rip), %rdi      # 0x85fc
callq 0x2050
movq -0x30(%rbp), %rsi
movq %r12, %rdi
callq 0x4972
movl $0x4, %r15d
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq