// File: /workspace/github_c_makefile_star2_O2/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 0x4855
leaq 0x1010(%rsp), %r12
movq %r12, %rdi
callq 0x3ccc
leaq 0x644d(%rip), %rdi      # 0xc498
movq %r12, %rsi
callq 0x3e79
movq %rbx, %rdi
callq 0x12c2
leaq 0x1008(%rsp), %rbp
movq 0x8(%rbx), %r13
movl 0x8(%r13), %eax
cmpl $0x13, %eax
je 0x607a
cmpl $0x34, %eax
jne 0x60ef
jmp 0x6217
movq 0x10(%r13), %rax
cmpl $0x1c, 0x8(%rax)
je 0x60a8
movq 0x18(%r13), %rax
cmpl $0x6, 0x8(%rax)
jne 0x60a8
movq (%r13), %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x45c5
movq 0x8(%rbx), %r13
cmpl $0x13, 0x8(%r13)
jne 0x60ef
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x60ef
pushq $0x13
popq %rax
cmpl $0x2f, %eax
je 0x60ef
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x60d6
movq %rbx, %rdi
callq 0x1586
movq 0x10(%r13), %r13
movl 0x8(%r13), %eax
jmp 0x60b5
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4d97
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x32, %eax
jne 0x6123
movq %rbx, %rdi
callq 0x1586
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5770
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x1a, %eax
jne 0x614b
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 0x5de1
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x16, %eax
jne 0x617b
movq %rbx, %rdi
callq 0x12c2
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 0x5ff9
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x19, %eax
jne 0x6195
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x437c
movq 0x8(%rbx), %rax
movl 0x8(%rax), %eax
cmpl $0x15, %eax
jne 0x620a
leaq 0x62f7(%rip), %r13      # 0xc498
movq %r13, %rdi
callq 0x3e9c
movq %rax, 0x1010(%rsp)
movq %r12, %rdi
callq 0x3e46
movq %rbp, %rdi
callq 0x3ccc
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3e79
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 0x4c1c
movq %r13, %rdi
callq 0x3e9c
movq %rax, 0x1008(%rsp)
movq %rbp, %rdi
callq 0x3e46
movq 0x8(%rbx), %rax
cmpl $0x33, 0x8(%rax)
je 0x6217
movq %rbx, %rdi
callq 0x12c2
jmp 0x6063
movq %rbx, %rdi
callq 0x12c2
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq