// File: /workspace/github_c_makefile_star2_O0/MartinNovotny25[P]VUT-FIT-IFJ2020/semantics.c
// Function: checkFunctionParams
void checkFunctionParams(TDLList *L, char *id) {
    //pocitadla parametrov a navratovych typov
    int paramsCt = 0;
    int retCt = 0;
    //sem sa ulozia udaje o funkcii, numOfParams a Returns treba nastavit na nulu, inak robi problemy
    functionData data;
    data.numOfParams = paramsCt;
    data.numOfReturns = retCt;
    //posun aktivity na prvu zatvorku ( z klucoveho slova "func"
    TDLLSucc(L);
    TDLLSucc(L);
    //cita tokeny kym nenajde ")" / citame parametre
    while (strcmp(L->Act->tdata.lex, ")")) {
        //nasleduje identifikator
        if (L->Act->tdata.type == 19) {
            //ulozime potrebne udaje(nazvy, typy a pocet parametrov)(cyklicky ich pridavam)
            data.params[paramsCt] = L->Act->tdata.lex;
            data.paramsType[paramsCt] = L->Act->rptr->tdata.type;
            paramsCt++;
            data.numOfParams = paramsCt;
            //posun aktivny prvok na id->typ->','
            TDLLSucc(L);
            TDLLSucc(L);
            //keby tu nebolo continue, hrozi preskocenie zatvorky, teda by sa while zastavil nespravne
            continue;
        }
        //posun '(' -> id alebo ',' -> id
        TDLLSucc(L);
    }
    //posun ')' -> '(' alebo ')' -> '{'
    TDLLSucc(L);
    //cita tokeny kym nenajde ")" / citame navratove typy
    while (strcmp(L->Act->tdata.lex, ")")) {
        //navratove typy nemusia byt deklarovane, v tom pripade { ukonci cyklus
        if (!strcmp(L->Act->tdata.lex, "{")) {
            break;
        }
        //ak najdeme navratove typy, vlozime do symtable
        if ((L->Act->rptr->tdata.type == t_INT_ID) ||
            (L->Act->rptr->tdata.type == t_STRING_ID) ||
            (L->Act->rptr->tdata.type == t_FLOAT64)) {
            //ulozim potrebne udaje(typy a pocet navratovych hodnot)
            data.returns[retCt] = L->Act->rptr->tdata.type;
            retCt++;
            data.numOfReturns = retCt;
        }
        TDLLSucc(L);
    }
    //overime ci sa parametre funkcie navzajom neredifinuju
    paramsRedefinitionCheck(data, L);
    //vlozenie funkcie do symtable
    BSTInsertGlobal(&functions, id, data);
    //printFunction(id, data);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2040, %rsp           # imm = 0x2040
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1020(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x101c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x12e0
movq -0x8(%rbp), %rdi
callq 0x12e0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
leaq 0x180b(%rip), %rsi      # 0xd5d2
callq 0x1070
cmpl $0x0, %eax
je 0xbe47
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x13, 0x8(%rax)
jne 0xbe39
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
movslq -0x14(%rbp), %rax
movq %rcx, -0x1018(%rbp,%rax,8)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x8(%rax), %ecx
movslq -0x14(%rbp), %rax
movl %ecx, -0x818(%rbp,%rax,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1020(%rbp)
movq -0x8(%rbp), %rdi
callq 0x12e0
movq -0x8(%rbp), %rdi
callq 0x12e0
jmp 0xbdb5
movq -0x8(%rbp), %rdi
callq 0x12e0
jmp 0xbdb5
movq -0x8(%rbp), %rdi
callq 0x12e0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
leaq 0x1770(%rip), %rsi      # 0xd5d2
callq 0x1070
cmpl $0x0, %eax
je 0xbefe
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
leaq 0x17a0(%rip), %rsi      # 0xd622
callq 0x1070
cmpl $0x0, %eax
jne 0xbe8e
jmp 0xbefe
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x18, 0x8(%rax)
je 0xbec4
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x14, 0x8(%rax)
je 0xbec4
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x17, 0x8(%rax)
jne 0xbef0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x8(%rax), %ecx
movslq -0x18(%rbp), %rax
movl %ecx, -0x418(%rbp,%rax,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x101c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x12e0
jmp 0xbe50
movq -0x8(%rbp), %rax
movq %rax, -0x1030(%rbp)
movq %rsp, %rdi
movl $0x201, %ecx            # imm = 0x201
leaq -0x1020(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x1030(%rbp), %rdi
callq 0xbcc0
movq -0x10(%rbp), %rax
movq %rax, -0x1028(%rbp)
movq %rsp, %rdi
movl $0x201, %ecx            # imm = 0x201
leaq -0x1020(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq -0x1028(%rbp), %rsi
leaq 0x647e(%rip), %rdi      # 0x123d0
callq 0x67b0
addq $0x2040, %rsp           # imm = 0x2040
popq %rbp
retq