// File: /workspace/github_c_makefile_star2_O1/MartinNovotny25[P]VUT-FIT-IFJ2020/semantics.c
// Function: enter_if_body
void enter_if_body(TDLList *L, tBSTNodePtrLocal *funcnode, functionData params, char *id){
   
    if_control(L, funcnode, params);
    // lokalny strom na vyuzivanie v ife
    // pri kazdom ife sa vytvori novy strom
    tBSTNodePtrLocal if_node;
    BSTInitLocal(&if_node);
    // pri kazdom ide sa ulozie ifnode na zasobnik
    PushTreeMain(&mainstack, &if_node);
    // chod za { ifu
    // kvoli podmienke while-u
    TDLLSucc(L);
    
    // chod az za else
    // v else nie je ziadnka podmienka tzv. co je pred { nas nemusi trapit
    while(L->Act->tdata.type != t_BRACES_L){        
        if ((L->Act->tdata.type == t_IDENTIFIER) && (L->Act->lptr->tdata.type != t_FUNC) && (L->Act->rptr->tdata.type == t_LEFT_BRACKET)) {
            checkCallFunction(L, L->Act->tdata.lex, &if_node);
        }
        if(L->Act->tdata.type == t_IDENTIFIER && L->Act->rptr->tdata.type == t_ASSIGN){
			TDLLElemPtr temp_node = L->Act;
			while(temp_node->tdata.type != t_EOL){
				if(temp_node->lptr->tdata.type == t_EOL){
					assign_vals_control(L, &if_node, params);
					break;
				}
				TDLLPred(L);
				temp_node = temp_node->lptr;
			}
		}
        
        if (L->Act->tdata.type == t_DEFINITION_2) {
            TDLLPred(L);
			dec_var_control(L, &if_node, params);
        }
        if (L->Act->tdata.type == t_FOR) {           
            enter_for_body(L, &if_node, params, id);
        }
        if (L->Act->tdata.type == t_IF) {
            TDLLSucc(L);        
			enter_if_body(L, &if_node, params, id);
        }
        if (L->Act->tdata.type == t_RETURN) {
            checkReturnStatement(L, id, &if_node);
        }
        if(L->Act->tdata.type == t_ELSE){
            if_node = PopTreeMain(&mainstack);
            // uvolnenie celeho lokalneho stromu ifu
            BSTDisposeLocal(&if_node);
            // lokalny strom na vyuzivanie v ife
            // pri kazdom ife sa vytvori novy strom
            tBSTNodePtrLocal else_node;
            BSTInitLocal(&else_node);
            // pri kazdom else sa ulozie elsenode na zasobnik
            PushTreeMain(&mainstack, &else_node);
            enter_else_body(L, &else_node, params, id);

            else_node = PopTreeMain(&mainstack);
            // uvolnenie celeho lokalneho stromu else
            BSTDisposeLocal(&else_node);
            // po else sa vrati }
            // break aby nedoslo k seg fault
            // while by pokracoval pokym nenajde { ale ten po else uz nie je
            // pokracoval by teda donekonecna alebo po seg fault
            if(L->Act->tdata.type == t_BRACES_R) break;
        }
        TDLLSucc(L);
    }   
    TDLLSucc(L);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rdx, %r14
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x1050(%rsp), %r15
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5131
leaq 0x1010(%rsp), %r12
movq %r12, %rdi
callq 0x4527
leaq 0x5b0e(%rip), %rdi      # 0xc488
movq %r12, %rsi
callq 0x46e4
movq %rbx, %rdi
callq 0x1695
leaq 0x1008(%rsp), %rbp
movq 0x8(%rbx), %rax
movl 0x8(%rax), %ecx
cmpl $0x13, %ecx
je 0x69a8
cmpl $0x34, %ecx
jne 0x69ca
jmp 0x6b35
movq 0x10(%rax), %rcx
cmpl $0x1c, 0x8(%rcx)
je 0x69ca
movq 0x18(%rax), %rcx
cmpl $0x6, 0x8(%rcx)
jne 0x69ca
movq (%rax), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x4e67
movq 0x8(%rbx), %r13
cmpl $0x13, 0x8(%r13)
jne 0x6a17
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x6a17
cmpl $0x2f, 0x8(%r13)
je 0x6a17
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x69fe
movq %rbx, %rdi
callq 0x19a1
movq 0x10(%r13), %r13
jmp 0x69df
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5689
movq 0x8(%rbx), %rax
cmpl $0x32, 0x8(%rax)
jne 0x6a42
movq %rbx, %rdi
callq 0x19a1
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x611b
movq 0x8(%rbx), %rax
cmpl $0x1a, 0x8(%rax)
jne 0x6a68
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x671f
movq 0x8(%rbx), %rax
cmpl $0x16, 0x8(%rax)
jne 0x6a96
movq %rbx, %rdi
callq 0x1695
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x6928
movq 0x8(%rbx), %rax
cmpl $0x19, 0x8(%rax)
jne 0x6aae
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4c12
movq 0x8(%rbx), %rax
cmpl $0x15, 0x8(%rax)
jne 0x6b28
leaq 0x59c9(%rip), %r13      # 0xc488
movq %r13, %rdi
callq 0x4707
movq %rax, 0x1010(%rsp)
movq %r12, %rdi
callq 0x46ab
movq %rbp, %rdi
callq 0x4527
movq %r13, %rdi
movq %rbp, %rsi
callq 0x46e4
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x5525
movq %r13, %rdi
callq 0x4707
movq %rax, 0x1008(%rsp)
movq %rbp, %rdi
callq 0x46ab
movq 0x8(%rbx), %rax
cmpl $0x33, 0x8(%rax)
je 0x6b35
movq %rbx, %rdi
callq 0x1695
jmp 0x6992
movq %rbx, %rdi
callq 0x1695
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq