// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x4543(%rip), %rdi      # 0xb3d9
movb $0x0, %al
callq 0x2070
leaq 0x8b6c(%rip), %rax      # 0xfa10
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x5380
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x8b3b(%rip), %rax      # 0xfa10
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x28(%rbp), %rsi
callq 0x6120
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6f29
leaq 0x46e7(%rip), %rdi      # 0xb5f0
movb $0x0, %al
callq 0x2070
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6ce0
movl $0x3, -0x4(%rbp)
jmp 0x708d
movq -0x18(%rbp), %rdi
callq 0x6be0
leaq 0x152ff(%rip), %rdi     # 0x1c238
leaq 0x8b00(%rip), %rsi      # 0xfa40
movl $0x526, %edx            # imm = 0x526
leaq 0x9f94(%rip), %rcx      # 0x10ee0
movl $0x2cd6, %r8d           # imm = 0x2CD6
callq 0x9380
movq -0x18(%rbp), %rdi
leaq 0x8aae(%rip), %rax      # 0xfa10
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x40(%rax)
movups %xmm1, 0x30(%rax)
movups %xmm0, 0x20(%rax)
leaq 0x152b5(%rip), %rcx     # 0x1c238
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x7ad0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x6fc8
leaq 0x4673(%rip), %rdi      # 0xb61b
movb $0x0, %al
callq 0x2070
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x6ce0
movl $0x4, -0x4(%rbp)
jmp 0x708d
movb $0x0, %al
callq 0x6d40
leaq -0x20(%rbp), %rdi
callq 0x8410
movq -0x20(%rbp), %rdi
leaq 0x8a2d(%rip), %rax      # 0xfa10
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x82a0
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x15344(%rip), %rdi     # 0x1c358
callq 0x8d20
leaq 0x15338(%rip), %rax     # 0x1c358
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x9320
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
leaq -0x20(%rbp), %rdi
callq 0x8780
movq -0x20(%rbp), %rdi
callq 0x8790
leaq 0x45dd(%rip), %rdi      # 0xb632
movb $0x0, %al
callq 0x2070
callq 0x70a0
leaq 0x151d0(%rip), %rax     # 0x1c238
movq 0x18(%rax), %rdi
callq 0x2030
leaq 0x151c0(%rip), %rax     # 0x1c238
movq 0x10(%rax), %rdi
callq 0x2030
callq 0x20b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)