// File: /workspace/github_c_makefile_star2_O1/MartinNovotny25[P]VUT-FIT-IFJ2020/parser.c
// Function: rule_stat
void rule_stat() {
    //switch podla typu tokenu
    switch (token.type) {
        // <stat> -> id ID_N/CALL_FUNC -- ak pride id
        // ak príde ID, môže sa jednat buď o volanie funkcie bez návratových hodnôt (napr. PRINT), alebo môže ísť o priradenie/definíciu
        // voláme rule_id_n_or_call_func na rozhonutie
        case t_IDENTIFIER:
            token = get_next_token(stdin);
            TDLLInsertLast(&tokens, token);
            rule_id_n_or_call_func();

            break;

            // ak príde IF
        case t_IF:
            token = get_next_token(stdin);
            TDLLInsertLast(&tokens, token);

            // If bez vyrazu
            if (token.type == t_BRACES_L) {error_call(ERR_SYN, &tokens);}

            //Nacitavanie tokenov vyrazu do listu -- PSA
            TDLLInitList(&psa_list);

             while (token.type != t_BRACES_L)
            {
                if ((token.type == t_PLUS)
                    || (token.type == t_MINUS)
                    || (token.type == t_DIVIDE)
                    || (token.type == t_MULTIPLY)
                    || (token.type == t_RIGHT_BRACKET)
                    || (token.type == t_LEFT_BRACKET)
                    || (token.type == t_LESS)
                    || (token.type == t_LESSOREQUAL)
                    || (token.type == t_GREATER)
                    || (token.type == t_GREATEROREQUAL)
                    || (token.type == t_EQUAL)
                    || (token.type == t_NOT_EQUAL)
                    || (token.type == t_IDENTIFIER)
                    || (token.type == t_FLOAT)
                    || (token.type == t_INT_NON_ZERO)
                    || (token.type == t_INT_ZERO)
                    || (token.type == t_STRING)) {

                    TDLLInsertLast(&psa_list, token);
                    token = get_next_token(stdin);
                    TDLLInsertLast(&tokens, token);

                    
                } else {error_call(ERR_SYN, &tokens);}


            }
            // TU SA ZAVOLA PRECEDENCNA S NAPLNENYM LISTOM
            evaluation(&psa_list, &tokens);
             TDLLDisposeList(&psa_list);

            // Otváracia množinová zátvorka pre telo IFu
            if (token.type != t_BRACES_L) {
                error_call(ERR_SYN, &tokens);
            }
            else {
                global_brace_count++;
                token = get_next_token(stdin);
                TDLLInsertLast(&tokens, token);
            }

            //Vynútenie eolu po otváracej množinovej zátvorke
            if (token.type != t_EOL) {
                error_call(ERR_SYN, &tokens);
            }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            //rekurzivne volanie stat v tele stat if -- dalsi token sa nacita v rule_eol

            rule_stat();

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            // Ukoncovacia množinová zátvorka tela IFu
            if (token.type != t_BRACES_R) {
                error_call(ERR_SYN, &tokens);
            }
            else {
                global_brace_count--;
                token = get_next_token(stdin);
                TDLLInsertLast(&tokens, token);
            }

            //ELSE statement

            // token ELSE
            if (token.type != t_ELSE) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }


            //Otváracia množinová zátvorka tela bloku ELSE
            if (token.type != t_BRACES_L) {
                error_call(ERR_SYN, &tokens);
            }
            else {
                global_brace_count++;
                token = get_next_token(stdin);
                TDLLInsertLast(&tokens, token);
            }

            //Vynútenie EOlu po otváracej zátvorke
            if (token.type != t_EOL) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            //rekurzivne volanie stat v else vetve
            rule_stat();

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            // ukoncovacia mnozinová zátvorka na konci tela bloku ELSE
            if (token.type != t_BRACES_R) { error_call(ERR_SYN, &tokens); }
            else {
                global_brace_count--;
                token = get_next_token(stdin);
                TDLLInsertLast(&tokens, token);
            }

            // Vynútenie EOLu za zatvorkou
            if (token.type != t_EOL) {
                error_call(ERR_SYN, &tokens);
            }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            //volanie stat po skonceni if  pre dalsie možné príkazy v tele funkie
            rule_stat();
            break;

         // token FOR
        case t_FOR:
            token = get_next_token(stdin);
            TDLLInsertLast(&tokens, token);


            //rule for_def, ktoré skontroluje definíciu LOKALNEJ ITERACNEJ PREMENNEJ
            //Bodkociarka sa kontroluje v pravidle
            rule_for_def();

            TDLLInitList(&psa_list);

            //for bez výrazu
            if (token.type == T_SEMICOLON) {error_call(ERR_SYN, &tokens);}

            while (token.type != T_SEMICOLON)
            {
                if ((token.type == t_PLUS)
                    || (token.type == t_MINUS)
                    || (token.type == t_DIVIDE)
                    || (token.type == t_MULTIPLY)
                    || (token.type == t_RIGHT_BRACKET)
                    || (token.type == t_LEFT_BRACKET)
                    || (token.type == t_LESS)
                    || (token.type == t_LESSOREQUAL)
                    || (token.type == t_GREATER)
                    || (token.type == t_GREATEROREQUAL)
                    || (token.type == t_EQUAL)
                    || (token.type == t_NOT_EQUAL)
                    || (token.type == t_IDENTIFIER)
                    || (token.type == t_FLOAT)
                    || (token.type == t_INT_NON_ZERO)
                    || (token.type == t_INT_ZERO)
                    || (token.type == t_STRING)) {

                    TDLLInsertLast(&psa_list, token);
                    token = get_next_token(stdin); TDLLInsertLast(&tokens, token);

                } else {error_call(ERR_SYN, &tokens);}


            }
            evaluation(&psa_list, &tokens);
            TDLLDisposeList(&psa_list);
            token = get_next_token(stdin); TDLLInsertLast(&tokens, token);



            // Pravidlo for_assign pre priradenie hodnoty premennej po vykonaní FOR cyklu
            //bodkociarka sa kontroluje v pravidle
            rule_for_assign();

            // token otváracej množinovej zátvorky tela for cyklu
            if (token.type != t_BRACES_L) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Vynútenie eolu po zatvorke
            if (token.type != t_EOL) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            //rekurzivne volanie stat v tele for cyklu

            rule_stat();

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            // token ukončovacej zátvorky tela for cyklu
            if (token.type != t_BRACES_R) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Vynútenie EOLu po ukončovacej zátvorke
            if (token.type != t_EOL) { error_call(ERR_SYN, &tokens); }
            else { token = get_next_token(stdin); TDLLInsertLast(&tokens, token); }

            // Dalsie optional EOLy
            if (token.type == t_EOL) {
                rule_eol();
            }

            // Volanie pravidla stat po vykonaní príkazu FOR
            rule_stat();
            break;

        // Prípad, kedy stat príde EOL -- nepovinný eol medzi príkazmy (STATEMENTAMI)
        case t_EOL:
            token = get_next_token(stdin);
            TDLLInsertLast(&tokens, token);
            rule_stat();
            break;

            //ak po stat nebude nič a skonči sa blok
        case t_BRACES_R:
            break;

        // Ak príde return -- pokracujeme do rule_return a za tym rule_stat
        // TU POZOR -- Syntakticky môže byt return hocikde v kóde, nie je to chyba, avšak parser bude dalej parsovat kód.
        // Generator by ASI mal vediet jak s tym naložiť
        case t_RETURN:
            rule_return();
            rule_stat();
            break;
         // Pride hocico ine - ERROR
        default:
            error_call(ERR_SYN, &tokens);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0xa18e(%rip), %r15      # 0xbfd8
leaq 0xa55f(%rip), %rbx      # 0xc3b0
leaq 0x6230(%rip), %r12      # 0x8088
leaq 0xa579(%rip), %r14      # 0xc3d8
movabsq $0xa03c00b0fc6, %r13    # imm = 0xA03C00B0FC6
movl 0xa561(%rip), %eax      # 0xc3d0
leal -0x13(%rax), %ecx
cmpl $0x7, %ecx
ja 0x1f1e
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa535(%rip)      # 0xc3c8
movl %edx, 0xa537(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
cmpl $0x34, 0xa525(%rip)     # 0xc3d0
jne 0x1eba
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
movq %r14, %rdi
callq 0x16a7
movl 0xa508(%rip), %edx      # 0xc3d0
cmpq $0x34, %rdx
ja 0x1f0f
btq %rdx, %r13
jae 0x1f05
movq 0xa4ed(%rip), %rsi      # 0xc3c8
movq %r14, %rdi
callq 0x1726
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa4d6(%rip)      # 0xc3c8
movl %edx, 0xa4d8(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x1ec2
cmpq $0x34, %rdx
je 0x1f95
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
jmp 0x1ec2
cmpl $0x2f, %eax
jne 0x230a
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa492(%rip)      # 0xc3c8
movl %edx, 0xa494(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x1e69
callq 0x2d5e
jmp 0x1e69
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa463(%rip)      # 0xc3c8
movl %edx, 0xa465(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
callq 0x29a0
movq %r14, %rdi
callq 0x16a7
cmpl $0x38, 0xa446(%rip)     # 0xc3d0
jne 0x2171
jmp 0x2164
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7d13
movq %r14, %rdi
callq 0x16b6
cmpl $0x34, 0xa421(%rip)     # 0xc3d0
jne 0x1fd9
incl 0xa3f5(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa402(%rip)      # 0xc3c8
movl %edx, 0xa404(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x1fe6
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa3e3(%rip)     # 0xc3d0
jne 0x2011
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa3ca(%rip)      # 0xc3c8
movl %edx, 0xa3cc(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x201e
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa3ab(%rip)     # 0xc3d0
jne 0x202c
callq 0x2f42
callq 0x1e3a
cmpl $0x2f, 0xa398(%rip)     # 0xc3d0
jne 0x203f
callq 0x2f42
cmpl $0x33, 0xa38a(%rip)     # 0xc3d0
jne 0x2070
decl 0xa35e(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa36b(%rip)      # 0xc3c8
movl %edx, 0xa36d(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x207d
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x15, 0xa34c(%rip)     # 0xc3d0
jne 0x20a8
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa333(%rip)      # 0xc3c8
movl %edx, 0xa335(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x20b5
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x34, 0xa314(%rip)     # 0xc3d0
jne 0x20e6
incl 0xa2e8(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa2f5(%rip)      # 0xc3c8
movl %edx, 0xa2f7(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x20f3
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa2d6(%rip)     # 0xc3d0
jne 0x211e
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa2bd(%rip)      # 0xc3c8
movl %edx, 0xa2bf(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x212b
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa29e(%rip)     # 0xc3d0
jne 0x2139
callq 0x2f42
callq 0x1e3a
cmpl $0x2f, 0xa28b(%rip)     # 0xc3d0
jne 0x214c
callq 0x2f42
cmpl $0x33, 0xa27d(%rip)     # 0xc3d0
jne 0x22ae
decl 0xa24d(%rip)            # 0xc3ac
jmp 0x228c
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
movl 0xa259(%rip), %edx      # 0xc3d0
cmpq $0x38, %rdx
ja 0x2164
btq %rdx, %r13
jae 0x21b4
movq 0xa23e(%rip), %rsi      # 0xc3c8
movq %r14, %rdi
callq 0x1726
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa227(%rip)      # 0xc3c8
movl %edx, 0xa229(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x2171
cmpq $0x38, %rdx
jne 0x2164
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7d13
movq %r14, %rdi
callq 0x16b6
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa1ec(%rip)      # 0xc3c8
movl %edx, 0xa1ee(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
callq 0x2b2f
cmpl $0x34, 0xa1d7(%rip)     # 0xc3d0
jne 0x221d
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa1be(%rip)      # 0xc3c8
movl %edx, 0xa1c0(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x222a
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa19f(%rip)     # 0xc3d0
jne 0x2255
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa186(%rip)      # 0xc3c8
movl %edx, 0xa188(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x2262
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa167(%rip)     # 0xc3d0
jne 0x2270
callq 0x2f42
callq 0x1e3a
cmpl $0x2f, 0xa154(%rip)     # 0xc3d0
jne 0x2283
callq 0x2f42
cmpl $0x33, 0xa146(%rip)     # 0xc3d0
jne 0x22ae
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa12d(%rip)      # 0xc3c8
movl %edx, 0xa12f(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x22bb
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa10e(%rip)     # 0xc3d0
jne 0x22e6
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa0f5(%rip)      # 0xc3c8
movl %edx, 0xa0f7(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1726
jmp 0x22f3
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42c8
cmpl $0x2f, 0xa0d6(%rip)     # 0xc3d0
jne 0x1e69
callq 0x2f42
jmp 0x1e69
cmpl $0x33, %eax
jne 0x2319
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xa090(%rip), %rsi      # 0xc3b0
movl $0x2, %edi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x42c8
movq (%r15), %rdi
callq 0x31f0
movq %rax, 0xa086(%rip)      # 0xc3c8
movl %edx, 0xa088(%rip)      # 0xc3d0
leaq 0xa061(%rip), %rdi      # 0xc3b0
movq %rax, %rsi
callq 0x1726
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2365