// File: /workspace/github_c_makefile_star2_O3/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 0xa19a(%rip), %r15      # 0xbfd8
leaq 0xa56b(%rip), %rbx      # 0xc3b0
leaq 0x623c(%rip), %r12      # 0x8088
leaq 0xa585(%rip), %r14      # 0xc3d8
movabsq $0xa03c00b0fc6, %r13    # imm = 0xA03C00B0FC6
movl 0xa56d(%rip), %eax      # 0xc3d0
leal -0x13(%rax), %ecx
cmpl $0x7, %ecx
ja 0x1f12
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa541(%rip)      # 0xc3c8
movl %edx, 0xa543(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
cmpl $0x34, 0xa531(%rip)     # 0xc3d0
jne 0x1eae
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
movq %r14, %rdi
callq 0x16a3
movl 0xa514(%rip), %edx      # 0xc3d0
cmpq $0x34, %rdx
ja 0x1f03
btq %rdx, %r13
jae 0x1ef9
movq 0xa4f9(%rip), %rsi      # 0xc3c8
movq %r14, %rdi
callq 0x1722
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa4e2(%rip)      # 0xc3c8
movl %edx, 0xa4e4(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x1eb6
cmpq $0x34, %rdx
je 0x1f89
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
jmp 0x1eb6
cmpl $0x2f, %eax
jne 0x230a
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa49e(%rip)      # 0xc3c8
movl %edx, 0xa4a0(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x1e5d
callq 0x2d61
jmp 0x1e5d
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa46f(%rip)      # 0xc3c8
movl %edx, 0xa471(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
callq 0x29a3
movq %r14, %rdi
callq 0x16a3
cmpl $0x38, 0xa452(%rip)     # 0xc3d0
jne 0x216d
jmp 0x2160
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7bf8
movq %r14, %rdi
callq 0x16b2
cmpl $0x34, 0xa42d(%rip)     # 0xc3d0
jne 0x1fcd
incl 0xa401(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa40e(%rip)      # 0xc3c8
movl %edx, 0xa410(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x1fda
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa3ef(%rip)     # 0xc3d0
jne 0x2005
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa3d6(%rip)      # 0xc3c8
movl %edx, 0xa3d8(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x2012
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa3b7(%rip)     # 0xc3d0
jne 0x2020
callq 0x2f48
callq 0x1e2e
movl 0xa3a5(%rip), %eax      # 0xc3d0
cmpl $0x2f, %eax
jne 0x203b
callq 0x2f48
movl 0xa395(%rip), %eax      # 0xc3d0
cmpl $0x33, %eax
jne 0x2068
decl 0xa366(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa373(%rip)      # 0xc3c8
movl %edx, 0xa375(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x2075
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x15, 0xa354(%rip)     # 0xc3d0
jne 0x20a0
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa33b(%rip)      # 0xc3c8
movl %edx, 0xa33d(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x20ad
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x34, 0xa31c(%rip)     # 0xc3d0
jne 0x20de
incl 0xa2f0(%rip)            # 0xc3ac
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa2fd(%rip)      # 0xc3c8
movl %edx, 0xa2ff(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x20eb
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa2de(%rip)     # 0xc3d0
jne 0x2116
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa2c5(%rip)      # 0xc3c8
movl %edx, 0xa2c7(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x2123
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa2a6(%rip)     # 0xc3d0
jne 0x2131
callq 0x2f48
callq 0x1e2e
movl 0xa294(%rip), %eax      # 0xc3d0
cmpl $0x2f, %eax
jne 0x214c
callq 0x2f48
movl 0xa284(%rip), %eax      # 0xc3d0
cmpl $0x33, %eax
jne 0x22ae
decl 0xa251(%rip)            # 0xc3ac
jmp 0x228c
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
movl 0xa25d(%rip), %edx      # 0xc3d0
cmpq $0x38, %rdx
ja 0x2160
btq %rdx, %r13
jae 0x21b0
movq 0xa242(%rip), %rsi      # 0xc3c8
movq %r14, %rdi
callq 0x1722
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa22b(%rip)      # 0xc3c8
movl %edx, 0xa22d(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x216d
cmpq $0x38, %rdx
jne 0x2160
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7bf8
movq %r14, %rdi
callq 0x16b2
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa1f0(%rip)      # 0xc3c8
movl %edx, 0xa1f2(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
callq 0x2b32
cmpl $0x34, 0xa1db(%rip)     # 0xc3d0
jne 0x2219
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa1c2(%rip)      # 0xc3c8
movl %edx, 0xa1c4(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x2226
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa1a3(%rip)     # 0xc3d0
jne 0x2251
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa18a(%rip)      # 0xc3c8
movl %edx, 0xa18c(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x225e
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa16b(%rip)     # 0xc3d0
jne 0x226c
callq 0x2f48
callq 0x1e2e
movl 0xa159(%rip), %eax      # 0xc3d0
cmpl $0x2f, %eax
jne 0x2287
callq 0x2f48
movl 0xa149(%rip), %eax      # 0xc3d0
cmpl $0x33, %eax
jne 0x22ae
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa12d(%rip)      # 0xc3c8
movl %edx, 0xa12f(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x22bb
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa10e(%rip)     # 0xc3d0
jne 0x22e6
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa0f5(%rip)      # 0xc3c8
movl %edx, 0xa0f7(%rip)      # 0xc3d0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1722
jmp 0x22f3
movl $0x2, %edi
movq %rbx, %rsi
callq 0x42d0
cmpl $0x2f, 0xa0d6(%rip)     # 0xc3d0
jne 0x1e5d
callq 0x2f48
jmp 0x1e5d
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 0x42d0
movq (%r15), %rdi
callq 0x31f4
movq %rax, 0xa086(%rip)      # 0xc3c8
movl %edx, 0xa088(%rip)      # 0xc3d0
leaq 0xa061(%rip), %rdi      # 0xc3b0
movq %rax, %rsi
callq 0x1722
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2365