// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1020, %rsp           # imm = 0x1020
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movq %rax, -0x1018(%rbp)
movq -0x1018(%rbp), %rdi
leaq 0x1632(%rip), %rsi      # 0xd5c5
callq 0x1070
cmpl $0x0, %eax
jne 0xc10d
testb $0x1, 0x44d8(%rip)      # 0x10480
je 0xbfbd
movq -0x8(%rbp), %rsi
movl $0x3, %edi
callq 0x64e0
jmp 0xc14b
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x1020(%rbp)
movq -0x1020(%rbp), %rax
movq (%rax), %rdi
leaq 0x15ef(%rip), %rsi      # 0xd5d4
callq 0x1070
cmpl $0x0, %eax
jne 0xc03d
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x15ce(%rip), %rsi      # 0xd5d2
callq 0x1070
cmpl $0x0, %eax
jne 0xc03d
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x15fb(%rip), %rsi      # 0xd622
callq 0x1070
cmpl $0x0, %eax
jne 0xc03d
movb $0x1, 0x4448(%rip)      # 0x10480
jmp 0xc10b
movq -0x1020(%rbp), %rax
movq (%rax), %rdi
leaq 0x1586(%rip), %rsi      # 0xd5d4
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f9
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x1561(%rip), %rsi      # 0xd5d2
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f9
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x1540(%rip), %rsi      # 0xd5d4
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f9
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x1517(%rip), %rsi      # 0xd5d2
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f9
movq -0x1020(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
leaq 0x153c(%rip), %rsi      # 0xd622
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f9
movb $0x1, 0x4389(%rip)      # 0x10480
jmp 0xc109
movq -0x8(%rbp), %rsi
movl $0x6, %edi
callq 0x64e0
jmp 0xc14b
jmp 0xc10b
jmp 0xc14b
movq 0x62bc(%rip), %rdi      # 0x123d0
movq -0x1018(%rbp), %rsi
leaq -0x1010(%rbp), %rdx
callq 0x66f0
testb $0x1, %al
jne 0xc12d
jmp 0xc13b
movq -0x8(%rbp), %rsi
movl $0x3, %edi
callq 0x64e0
movq -0x8(%rbp), %rdi
movq -0x1018(%rbp), %rsi
callq 0xbd70
addq $0x1020, %rsp           # imm = 0x1020
popq %rbp
retq
nopw %cs:(%rax,%rax)