// File: /workspace/github_c_makefile_star2_O3/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 0x50bf
leaq 0x1010(%rsp), %r12
movq %r12, %rdi
callq 0x44dc
leaq 0x5b30(%rip), %rdi      # 0xc488
movq %r12, %rsi
callq 0x469b
movq %rbx, %rdi
callq 0x1691
leaq 0x1008(%rsp), %rbp
movq 0x8(%rbx), %r13
movl 0x8(%r13), %eax
cmpl $0x13, %eax
je 0x6987
cmpl $0x34, %eax
jne 0x69f7
jmp 0x6b1f
movq 0x10(%r13), %rax
cmpl $0x1c, 0x8(%rax)
je 0x69b5
movq 0x18(%r13), %rax
cmpl $0x6, 0x8(%rax)
jne 0x69b5
movq (%r13), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x4e01
movq 0x8(%rbx), %r13
cmpl $0x13, 0x8(%r13)
jne 0x69f7
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x69f7
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x69de
movq %rbx, %rdi
callq 0x1985
movq 0x10(%r13), %r13
cmpl $0x2f, 0x8(%r13)
jne 0x69bf
jmp 0x69f7
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x55c6
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x32, %eax
jne 0x6a2b
movq %rbx, %rdi
callq 0x1985
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6072
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x1a, %eax
jne 0x6a53
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 0x66f3
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x16, %eax
jne 0x6a83
movq %rbx, %rdi
callq 0x1691
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 0x6906
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x19, %eax
jne 0x6a9d
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x4bb1
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x15, %eax
jne 0x6b12
leaq 0x59df(%rip), %r13      # 0xc488
movq %r13, %rdi
callq 0x46be
movq %rax, 0x1010(%rsp)
movq %r12, %rdi
callq 0x4662
movq %rbp, %rdi
callq 0x44dc
movq %r13, %rdi
movq %rbp, %rsi
callq 0x469b
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 0x5458
movq %r13, %rdi
callq 0x46be
movq %rax, 0x1008(%rsp)
movq %rbp, %rdi
callq 0x4662
movq 0x8(%rbx), %rax
cmpl $0x33, 0x8(%rax)
je 0x6b1f
movq %rbx, %rdi
callq 0x1691
jmp 0x6970
movq %rbx, %rdi
callq 0x1691
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq