// File: /workspace/github_c_makefile_star2_O0/gregtour[P]minimal-compiler/typechecker.c
// Function: LinkSourceRoot
void LinkSourceRoot(const char* sourceFile, SYNTAX_TREE** tree)
{
    printf("Linking source file %s.\n", sourceFile);
    
    // allow for linking multiple source files in one project
    if (AddSourceToList(&gPrgrmSources, sourceFile, NULL, NULL) != 0)
    {
        SOURCE* source = GetSourceFromList(gPrgrmSources, sourceFile);

        source->lexing = LexSource(sourceFile, 
                                   &source->buffer, 
                                   CONTEXT_FREE_GRAMMAR);
        if (source->lexing == NULL) {
            printf("Error lexing source '%s'.\n", sourceFile);
            FreeLexing(source->lexing, source->buffer);
            return;
        }

        source->syntax = ParseSource(source->lexing,
                                     PARSE_TABLE,
                                     CONTEXT_FREE_GRAMMAR);
        if (source->syntax == NULL) {
            printf("Error parsing source '%s'.\n", sourceFile);
            FreeLexing(source->lexing, source->buffer);
            source->lexing = NULL;
            return;
        }

        PrePassReductions(&source->syntax);
        SourceReductions(&source->syntax);
        // add to intermediate framework
        FirstPassStaticAnalyzer(source->syntax);
    }
    
    // link standard library
    // if (IsLibraryDefinition(sourceFile))
    // {
    //    LinkLibrary(sourceFile);
    // }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq 0x1fed(%rip), %rdi      # 0xb998
movb $0x0, %al
callq 0x2070
movq -0x8(%rbp), %rsi
leaq 0x1299b(%rip), %rdi     # 0x1c358
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x8d20
cmpl $0x0, %eax
je 0x9b11
leaq 0x1297f(%rip), %rax     # 0x1c358
movq (%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x9320
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
leaq 0x6014(%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 0x6120
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x9a5c
movq -0x8(%rbp), %rsi
leaq 0x1f76(%rip), %rdi      # 0xb9b1
movb $0x0, %al
callq 0x2070
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x6ce0
jmp 0x9b11
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x5fa5(%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 0x127ac(%rip), %rcx     # 0x1c238
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x7ad0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x9aea
movq -0x8(%rbp), %rsi
leaq 0x1f0c(%rip), %rdi      # 0xb9cc
movb $0x0, %al
callq 0x2070
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x6ce0
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x9b11
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
callq 0x8410
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
callq 0x8780
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x87e0
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)