// File: /workspace/github_c_makefile_star2_O3/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 0x44dc
leaq 0x5d5c(%rip), %rdi      # 0xc488
movq %r13, %rsi
callq 0x469b
movq 0x8(%r14), %rax
movq 0x18(%rax), %rax
cmpl $0x38, 0x8(%rax)
jne 0x674b
leaq 0x1ddc(%rip), %rax      # 0x8525
jmp 0x674e
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 0x6b39
leaq 0x1010(%rsp), %rbp
movq 0x8(%r14), %r13
movl 0x8(%r13), %eax
cmpl $0x13, %eax
je 0x678e
cmpl $0x33, %eax
jne 0x67fe
jmp 0x68aa
movq 0x10(%r13), %rax
cmpl $0x1c, 0x8(%rax)
je 0x67bc
movq 0x18(%r13), %rax
cmpl $0x6, 0x8(%rax)
jne 0x67bc
movq (%r13), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x4e01
movq 0x8(%r14), %r13
cmpl $0x13, 0x8(%r13)
jne 0x67fe
movq 0x18(%r13), %rax
cmpl $0x3, 0x8(%rax)
jne 0x67fe
movq 0x10(%r13), %rax
cmpl $0x2f, 0x8(%rax)
je 0x67e5
movq %r14, %rdi
callq 0x1985
movq 0x10(%r13), %r13
cmpl $0x2f, 0x8(%r13)
jne 0x67c6
jmp 0x67fe
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x55c6
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x32, %eax
jne 0x6832
movq %r14, %rdi
callq 0x1985
movl $0x201, %ecx            # imm = 0x201
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6072
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x1a, %eax
jne 0x685a
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 0x66f3
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x16, %eax
jne 0x688a
movq %r14, %rdi
callq 0x1691
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 0x6906
movq 0x8(%r14), %rax
movl 0x8(%rax), %eax
cmpl $0x19, %eax
jne 0x689d
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x4bb1
movq %r14, %rdi
callq 0x1691
jmp 0x6777
movq %r14, %rdi
callq 0x1691
leaq 0x1c6c(%rip), %rsi      # 0x8525
movq 0x1008(%rsp), %r14
movq %r14, %rdi
callq 0x1080
testl %eax, %eax
je 0x68d8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x45f1
leaq 0x5ba9(%rip), %rdi      # 0xc488
callq 0x46be
leaq 0x1010(%rsp), %rdi
movq %rax, (%rdi)
callq 0x4662
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq