// File: /workspace/github_c_makefile_star2_O2/MartinNovotny25[P]VUT-FIT-IFJ2020/semantics.c
// Function: enter_for_body
void enter_for_body(TDLList *L, tBSTNodePtrLocal *fornode, functionData params, char *id){

    tBSTNodePtrLocal for_node;
    BSTInitLocal(&for_node);
    char *nametodelete;
    PushTreeMain(&mainstack, &for_node);
    if(L->Act->rptr->tdata.type != T_SEMICOLON){
        // uloz premennu resp. uzol stromu do tempnode
        nametodelete = L->Act->rptr->tdata.lex;
    } else {
        nametodelete = "none";
    }
    
    for_control(L, fornode, params);
   
    while(L->Act->tdata.type != t_BRACES_R){        
        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, &for_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, &for_node, params);
					break;
				}
				TDLLPred(L);
				temp_node = temp_node->lptr;
			}
		}
        
        if (L->Act->tdata.type == t_DEFINITION_2) {
            TDLLPred(L);
			dec_var_control(L, &for_node, params);
        }
        if (L->Act->tdata.type == t_FOR) {          
            enter_for_body(L, &for_node, params, id);   
        }
        if (L->Act->tdata.type == t_IF) {
            TDLLSucc(L);
			enter_if_body(L, &for_node, params, id);
        }
        if (L->Act->tdata.type == t_RETURN) {
            checkReturnStatement(L, id, fornode);
        }
        TDLLSucc(L);
    }

    // chod za }
    // v enterfuncbody sa nezapocitalo {
    // tak sa nemoze ani }
    // inac ide o chybne pocitanie
    TDLLSucc(L);
    
    if(!(strcmp(nametodelete, "none"))){

    }else{
        BSTDelete(fornode, nametodelete);
    }
    for_node = PopTreeMain(&mainstack);
    BSTDisposeLocal(&for_node);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x1050(%rsp), %r12
leaq 0x1010(%rsp), %r13
movq %r13, %rdi
callq 0x3ccc
leaq 0x667e(%rip), %rdi      # 0xc498
movq %r13, %rsi
callq 0x3e79
movq 0x8(%r14), %rax
movq 0x18(%rax), %rax
cmpl $0x38, 0x8(%rax)
jne 0x5e39
leaq 0x26ee(%rip), %rax      # 0x8525
jmp 0x5e3c
movq (%rax), %rax
movq %rax, 0x1008(%rsp)
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6231
leaq 0x1010(%rsp), %rbp
movq 0x8(%r14), %r13
movl 0x8(%r13), %eax
cmpl $0x13, %eax
je 0x5e7c
cmpl $0x33, %eax
jne 0x5ef1
jmp 0x5f9d
movq 0x10(%r13), %rax
cmpl $0x1c, 0x8(%rax)
je 0x5eaa
movq 0x18(%r13), %rax
cmpl $0x6, 0x8(%rax)
jne 0x5eaa
movq (%r13), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x45c5
movq 0x8(%r14), %r13
cmpl $0x13, 0x8(%r13)
jne 0x5ef1
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x5ef1
pushq $0x13
popq %rax
cmpl $0x2f, %eax
je 0x5ef1
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x5ed8
movq %r14, %rdi
callq 0x1586
movq 0x10(%r13), %r13
movl 0x8(%r13), %eax
jmp 0x5eb7
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x4d97
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x32, %eax
jne 0x5f25
movq %r14, %rdi
callq 0x1586
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5770
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x1a, %eax
jne 0x5f4d
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x5de1
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x16, %eax
jne 0x5f7d
movq %r14, %rdi
callq 0x12c2
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x5ff9
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x19, %eax
jne 0x5f90
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x437c
movq %r14, %rdi
callq 0x12c2
jmp 0x5e65
movq %r14, %rdi
callq 0x12c2
leaq 0x2579(%rip), %rsi      # 0x8525
movq 0x1008(%rsp), %r14
movq %r14, %rdi
callq 0x1080
testl %eax, %eax
je 0x5fcb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3dd8
leaq 0x64c6(%rip), %rdi      # 0xc498
callq 0x3e9c
leaq 0x1010(%rsp), %rdi
movq %rax, (%rdi)
callq 0x3e46
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq