// File: /workspace/github_c_makefile_star2_O1/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 0x4527
leaq 0x5d30(%rip), %rdi      # 0xc488
movq %r13, %rsi
callq 0x46e4
movq 0x8(%r14), %rax
movq 0x18(%rax), %rax
cmpl $0x38, 0x8(%rax)
jne 0x6777
leaq 0x1db6(%rip), %rax      # 0x852b
jmp 0x677a
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 0x6b4f
leaq 0x1010(%rsp), %rbp
movq 0x8(%r14), %rax
movl 0x8(%rax), %ecx
cmpl $0x13, %ecx
je 0x67b9
cmpl $0x33, %ecx
jne 0x67db
jmp 0x68cc
movq 0x10(%rax), %rcx
cmpl $0x1c, 0x8(%rcx)
je 0x67db
movq 0x18(%rax), %rcx
cmpl $0x6, 0x8(%rcx)
jne 0x67db
movq (%rax), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x4e67
movq 0x8(%r14), %r13
cmpl $0x13, 0x8(%r13)
jne 0x6828
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x6828
cmpl $0x2f, 0x8(%r13)
je 0x6828
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x680f
movq %r14, %rdi
callq 0x19a1
movq 0x10(%r13), %r13
jmp 0x67f0
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5689
movq 0x8(%r14), %rax
cmpl $0x32, 0x8(%rax)
jne 0x6853
movq %r14, %rdi
callq 0x19a1
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x611b
movq 0x8(%r14), %rax
cmpl $0x1a, 0x8(%rax)
jne 0x6879
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 0x671f
movq 0x8(%r14), %rax
cmpl $0x16, 0x8(%rax)
jne 0x68a7
movq %r14, %rdi
callq 0x1695
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 0x6928
movq 0x8(%r14), %rax
cmpl $0x19, 0x8(%rax)
jne 0x68bf
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x4c12
movq %r14, %rdi
callq 0x1695
jmp 0x67a3
movq %r14, %rdi
callq 0x1695
leaq 0x1c50(%rip), %rsi      # 0x852b
movq 0x1008(%rsp), %r14
movq %r14, %rdi
callq 0x1080
testl %eax, %eax
je 0x68fa
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4625
leaq 0x5b87(%rip), %rdi      # 0xc488
callq 0x4707
leaq 0x1010(%rsp), %rdi
movq %rax, (%rdi)
callq 0x46ab
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq