// File: /workspace/github_c_makefile_star2_O1/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 0x7f59(%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 0x38f2
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 0x4031
testq %rax, %rax
je 0x4c40
movq %rax, %r12
movq %rax, %rdi
callq 0x48b2
leaq 0x14716(%rip), %r15     # 0x19248
leaq 0x7f17(%rip), %rsi      # 0xca50
leaq 0x93b0(%rip), %rcx      # 0xdef0
movq %r15, %rdi
movl $0x526, %edx            # imm = 0x526
movl $0x2cd6, %r8d           # imm = 0x2CD6
callq 0x640e
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 0x535a
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x4c5f
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x49ac
leaq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x59f0
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 0x58df
movq (%r13), %rcx
leaq 0x1478b(%rip), %r14     # 0x19368
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6094
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x63da
movq -0x30(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq %r13, %rdi
callq 0x5bd1
movq (%r13), %rdi
callq 0x5bd7
leaq 0x39dd(%rip), %rdi      # 0x85f3
callq 0x2050
callq 0x4c8f
leaq 0x14621(%rip), %rbx     # 0x19248
movq 0x18(%rbx), %rdi
callq 0x2030
movq 0x10(%rbx), %rdi
callq 0x2030
callq 0x20d0
jmp 0x4c7d
leaq 0x39cb(%rip), %rdi      # 0x8612
callq 0x2050
movq -0x30(%rbp), %rsi
xorl %edi, %edi
callq 0x4961
movl $0x3, %r15d
jmp 0x4c7d
leaq 0x3996(%rip), %rdi      # 0x85fc
callq 0x2050
movq -0x30(%rbp), %rsi
movq %r12, %rdi
callq 0x4961
movl $0x4, %r15d
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq