// File: /workspace/github_c_makefile_star2_O1/MartinNovotny25[P]VUT-FIT-IFJ2020/semantics.c
// Function: checkFunction
void checkFunction(TDLList *L) {
    //pomocna premenna, BSTSearchGlobal() sem vravcia data
    functionData data;
    //pomocny string, ulozime sem identifikator fcie
    char *id = L->Act->rptr->tdata.lex;
    //identifikator funkcie je "main"
    if (!strcmp(id, "main")) {
        //ak uz main bol raz najdeny, volaj error
        if (mainFound) {
            error_call(ERR_SEM_UNDEF, L);
            return;
        }
        //pomocny pointer, mal by ukazovat vpravo od lexemu main, teda (
        struct TDLLElem *tmp = L->Act->rptr->rptr;
        //overime lexemi vpravo od identifikatoru main, ak su (){, tak sme nasli main
        if ((!strcmp(tmp->tdata.lex, "(")) && (!strcmp(tmp->rptr->tdata.lex, ")")) && (!strcmp(tmp->rptr->rptr->tdata.lex, "{"))) {
            mainFound = true;
        }
        else {
            if ((!strcmp(tmp->tdata.lex, "(")) &&
                (!strcmp(tmp->rptr->tdata.lex, ")")) &&
                (!strcmp(tmp->rptr->rptr->tdata.lex, "(")) &&
                (!strcmp(tmp->rptr->rptr->rptr->tdata.lex, ")")) &&
                (!strcmp(tmp->rptr->rptr->rptr->rptr->tdata.lex, "{"))) {
                mainFound = true;
            } else {
                //main nema spravne parametre, volaj error
                error_call(ERR_SEM_RETURN, L);
                return;
            }
        }
    } else {
        //skontroluj ci identifikator uz neni v symtable
        if (BSTSearchGlobal(functions, id, &data)) {
            error_call(ERR_SEM_UNDEF, L);
        }
        checkFunctionParams(L, id);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x1008, %rsp           # imm = 0x1008
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq 0x18(%rax), %r15
movq (%r15), %r14
leaq 0xc32(%rip), %rsi       # 0x851a
movq %r14, %rdi
callq 0x1080
testl %eax, %eax
je 0x7930
movq 0x6ad5(%rip), %rdi      # 0xe3d0
movq %rsp, %rdx
movq %r14, %rsi
callq 0x43a8
testb %al, %al
je 0x7917
movl $0x3, %edi
movq %rbx, %rsi
callq 0x42c8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x773f
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x4b49(%rip)      # 0xc480
jne 0x7943
movl $0x3, %edi
jmp 0x79f3
movq 0x18(%r15), %r14
movq (%r14), %rdi
leaq 0xbd8(%rip), %rsi       # 0x8529
callq 0x1080
testl %eax, %eax
jne 0x79ee
movl %eax, %ebp
movq 0x18(%r14), %r15
movq (%r15), %rdi
leaq 0xbb9(%rip), %rsi       # 0x8527
callq 0x1080
testl %eax, %eax
jne 0x798e
movq 0x18(%r15), %rax
movq (%rax), %rdi
leaq 0xbf2(%rip), %rsi       # 0x8577
callq 0x1080
testl %eax, %eax
je 0x7a08
testl %ebp, %ebp
jne 0x79ee
movq 0x18(%r14), %r14
movq (%r14), %rdi
leaq 0xb87(%rip), %rsi       # 0x8527
callq 0x1080
testl %eax, %eax
jne 0x79ee
movq 0x18(%r14), %r14
movq (%r14), %rdi
leaq 0xb72(%rip), %rsi       # 0x8529
callq 0x1080
testl %eax, %eax
jne 0x79ee
movq 0x18(%r14), %r14
movq (%r14), %rdi
leaq 0xb59(%rip), %rsi       # 0x8527
callq 0x1080
testl %eax, %eax
jne 0x79ee
movq 0x18(%r14), %rax
movq (%rax), %rdi
leaq 0xb92(%rip), %rsi       # 0x8577
callq 0x1080
testl %eax, %eax
je 0x7a08
movl $0x6, %edi
movq %rbx, %rsi
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x42c8
movb $0x1, 0x4a71(%rip)      # 0xc480
jmp 0x7922