// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0xa5a1(%rip), %r15      # 0xbfd8
leaq 0xa982(%rip), %rbx      # 0xc3c0
leaq 0x6643(%rip), %r12      # 0x8088
pushq $0x2
popq %rbp
leaq 0xa999(%rip), %r14      # 0xc3e8
movabsq $0xa03c00b0fc6, %r13    # imm = 0xA03C00B0FC6
movl 0xa981(%rip), %eax      # 0xc3e0
leal -0x13(%rax), %ecx
cmpl $0x7, %ecx
ja 0x1b08
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa955(%rip)      # 0xc3d8
movl %edx, 0xa957(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
cmpl $0x34, 0xa945(%rip)     # 0xc3e0
jne 0x1aa7
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
movq %r14, %rdi
callq 0x12d4
movl 0xa92b(%rip), %edx      # 0xc3e0
cmpq $0x34, %rdx
ja 0x1afc
btq %rdx, %r13
jae 0x1af2
movq 0xa910(%rip), %rsi      # 0xc3d8
movq %r14, %rdi
callq 0x1345
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa8f9(%rip)      # 0xc3d8
movl %edx, 0xa8fb(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1aaf
cmpq $0x34, %rdx
je 0x1b7f
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
jmp 0x1aaf
cmpl $0x2f, %eax
jne 0x1edf
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa8b8(%rip)      # 0xc3d8
movl %edx, 0xa8ba(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1a59
callq 0x2929
jmp 0x1a59
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa889(%rip)      # 0xc3d8
movl %edx, 0xa88b(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
callq 0x257a
movq %r14, %rdi
callq 0x12d4
cmpl $0x38, 0xa86c(%rip)     # 0xc3e0
jne 0x1d4e
jmp 0x1d44
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7282
movq %r14, %rdi
callq 0x12e0
cmpl $0x34, 0xa847(%rip)     # 0xc3e0
jne 0x1bc3
incl 0xa81b(%rip)            # 0xc3bc
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa828(%rip)      # 0xc3d8
movl %edx, 0xa82a(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1bcd
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa80c(%rip)     # 0xc3e0
jne 0x1bf8
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa7f3(%rip)      # 0xc3d8
movl %edx, 0xa7f5(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1c02
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa7d7(%rip)     # 0xc3e0
jne 0x1c10
callq 0x2b16
callq 0x1a25
movl 0xa7c5(%rip), %eax      # 0xc3e0
cmpl $0x2f, %eax
jne 0x1c2b
callq 0x2b16
movl 0xa7b5(%rip), %eax      # 0xc3e0
cmpl $0x33, %eax
jne 0x1c58
decl 0xa786(%rip)            # 0xc3bc
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa793(%rip)      # 0xc3d8
movl %edx, 0xa795(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1c62
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x15, 0xa777(%rip)     # 0xc3e0
jne 0x1c8d
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa75e(%rip)      # 0xc3d8
movl %edx, 0xa760(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1c97
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x34, 0xa742(%rip)     # 0xc3e0
jne 0x1cc8
incl 0xa716(%rip)            # 0xc3bc
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa723(%rip)      # 0xc3d8
movl %edx, 0xa725(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1cd2
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa707(%rip)     # 0xc3e0
jne 0x1cfd
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa6ee(%rip)      # 0xc3d8
movl %edx, 0xa6f0(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1d07
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa6d2(%rip)     # 0xc3e0
jne 0x1d15
callq 0x2b16
callq 0x1a25
movl 0xa6c0(%rip), %eax      # 0xc3e0
cmpl $0x2f, %eax
jne 0x1d30
callq 0x2b16
movl 0xa6b0(%rip), %eax      # 0xc3e0
cmpl $0x33, %eax
jne 0x1e89
decl 0xa67d(%rip)            # 0xc3bc
jmp 0x1e67
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
movl 0xa68c(%rip), %edx      # 0xc3e0
cmpq $0x38, %rdx
ja 0x1d44
btq %rdx, %r13
jae 0x1d91
movq 0xa671(%rip), %rsi      # 0xc3d8
movq %r14, %rdi
callq 0x1345
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa65a(%rip)      # 0xc3d8
movl %edx, 0xa65c(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1d4e
cmpq $0x38, %rdx
jne 0x1d44
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7282
movq %r14, %rdi
callq 0x12e0
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa61f(%rip)      # 0xc3d8
movl %edx, 0xa621(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
callq 0x26ff
cmpl $0x34, 0xa60a(%rip)     # 0xc3e0
jne 0x1dfa
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa5f1(%rip)      # 0xc3d8
movl %edx, 0xa5f3(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1e04
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa5d5(%rip)     # 0xc3e0
jne 0x1e2f
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa5bc(%rip)      # 0xc3d8
movl %edx, 0xa5be(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1e39
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa5a0(%rip)     # 0xc3e0
jne 0x1e47
callq 0x2b16
callq 0x1a25
movl 0xa58e(%rip), %eax      # 0xc3e0
cmpl $0x2f, %eax
jne 0x1e62
callq 0x2b16
movl 0xa57e(%rip), %eax      # 0xc3e0
cmpl $0x33, %eax
jne 0x1e89
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa562(%rip)      # 0xc3d8
movl %edx, 0xa564(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1e93
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa546(%rip)     # 0xc3e0
jne 0x1ebe
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa52d(%rip)      # 0xc3d8
movl %edx, 0xa52f(%rip)      # 0xc3e0
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1345
jmp 0x1ec8
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3ac4
cmpl $0x2f, 0xa511(%rip)     # 0xc3e0
jne 0x1a59
callq 0x2b16
jmp 0x1a59
cmpl $0x33, %eax
jne 0x1ef3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa4c6(%rip), %rsi      # 0xc3c0
pushq $0x2
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3ac4
movq (%r15), %rdi
callq 0x2dbc
movq %rax, 0xa4b9(%rip)      # 0xc3d8
movl %edx, 0xa4bb(%rip)      # 0xc3e0
leaq 0xa494(%rip), %rdi      # 0xc3c0
movq %rax, %rsi
callq 0x1345
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1f47