// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rsi, %rbx
movq %rdi, %r14
movq $0x0, 0x1010(%rsp)
callq 0x1691
movq %r14, %rdi
callq 0x1691
xorl %r15d, %r15d
movq 0x8(%r14), %rax
movq (%rax), %rcx
cmpb $0x29, (%rcx)
jne 0x7700
cmpb $0x0, 0x1(%rcx)
je 0x773c
cmpl $0x13, 0x8(%rax)
je 0x7710
movq %r14, %rdi
callq 0x1691
jmp 0x76ee
movq %rcx, 0x1018(%rsp,%r15,8)
movq 0x18(%rax), %rax
movl 0x8(%rax), %eax
movl %eax, 0x1818(%rsp,%r15,4)
incq %r15
movl %r15d, 0x1010(%rsp)
movq %r14, %rdi
callq 0x1691
jmp 0x7706
movq %r14, %rdi
callq 0x1691
xorl %r15d, %r15d
movl $0x1900000, %ebp        # imm = 0x1900000
movq 0x8(%r14), %rax
movq (%rax), %rcx
movzbl (%rcx), %edx
cmpl $0x7b, %edx
je 0x7760
cmpl $0x29, %edx
jne 0x7766
cmpb $0x0, 0x1(%rcx)
je 0x7797
movq 0x18(%rax), %rax
movl 0x8(%rax), %eax
cmpl $0x18, %eax
ja 0x778d
btl %eax, %ebp
jae 0x778d
movslq %r15d, %r15
movl %eax, 0x1c18(%rsp,%r15,4)
incl %r15d
movl %r15d, 0x1014(%rsp)
movq %r14, %rdi
callq 0x1691
jmp 0x774c
leaq 0x1010(%rsp), %r15
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x764a
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x6c06(%rip), %rdi      # 0xe3d0
movq %rbx, %rsi
callq 0x440a
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r14
popq %r15
popq %rbp
retq