// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rsi, 0x1008(%rsp)
movq %rdi, %r14
movq $0x0, 0x1010(%rsp)
callq 0x1695
movq %r14, %rdi
callq 0x1695
movq 0x8(%r14), %rbp
movq (%rbp), %r12
leaq 0xda4(%rip), %rsi       # 0x8527
movq %r12, %rdi
callq 0x1080
testl %eax, %eax
je 0x77ec
xorl %r13d, %r13d
leaq 0xd8e(%rip), %r15       # 0x8527
cmpl $0x13, 0x8(%rbp)
je 0x77c0
movq %r14, %rdi
callq 0x1695
movq 0x8(%r14), %rbp
movq (%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1080
testl %eax, %eax
jne 0x7799
jmp 0x77ec
movq %r12, 0x1018(%rsp,%r13,8)
movq 0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x1818(%rsp,%r13,4)
incq %r13
movl %r13d, 0x1010(%rsp)
movq %r14, %rdi
callq 0x1695
jmp 0x779f
movq %r14, %rdi
callq 0x1695
movq 0x8(%r14), %rbx
movq (%rbx), %r13
leaq 0xd25(%rip), %rsi       # 0x8527
movq %r13, %rdi
callq 0x1080
testl %eax, %eax
je 0x7874
xorl %ebp, %ebp
leaq 0xd60(%rip), %r15       # 0x8577
leaq 0xd09(%rip), %r12       # 0x8527
movq %r13, %rdi
movq %r15, %rsi
callq 0x1080
testl %eax, %eax
je 0x7874
movq 0x18(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x18, %eax
ja 0x7856
movl $0x1900000, %ecx        # imm = 0x1900000
btl %eax, %ecx
jae 0x7856
movslq %ebp, %rbp
movl %eax, 0x1c18(%rsp,%rbp,4)
incl %ebp
movl %ebp, 0x1014(%rsp)
movq %r14, %rdi
callq 0x1695
movq 0x8(%r14), %rbx
movq (%rbx), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x1080
testl %eax, %eax
jne 0x781e
leaq 0x1010(%rsp), %r15
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x76ca
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x6b29(%rip), %rdi      # 0xe3d0
movq 0x1008(%rsp), %rsi
callq 0x43fe
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq