// File: /workspace/github_cpp_makefile_star2_O2/gioannides[P]Language_Processors/src/../include/ast/ast_node.hpp
// Function: FunctionDefinition::render_asm(std::basic_ofstream<char, std::char_traits<char>>&, Context&)
void render_asm(std::ofstream& file, Context& contxt) {
			
			contxt.function_dec=false;
			if( DeclarationSpecifiersPtr != NULL ) {
				contxt.functionReturnType = true;
				DeclarationSpecifiersPtr->render_asm(file,contxt);			//check the return type
				contxt.functionReturnType = false;
			}
			contxt.funcion_temp.returnType=contxt.functionReturnTypetemp; 

			if( DeclaratorPtr != NULL ) {				//function_def.name and function_def.no_parameters are assigned here
				
				contxt.protect = false; //protect overwriting currennt scope global/function
				//contxt.max_offset = 0;
				DeclaratorPtr->render_asm(file,contxt);
				//std::cout << "end of declarator" << std::endl;
				file << std::endl;
				file << std::endl << "\t.text" << std::endl;
				file << std::endl << "\t.align\t2" << std::endl; 
				file << std::endl << "\t.globl\t" << contxt.funct_id << std::endl;
				file << std::endl << "\t.set\t" << "nomips16" << std::endl;
				file << std::endl << "\t.set\t" << "nomicromips" << std::endl;
				file << std::endl << "\t.ent\t" << contxt.funct_id << std::endl;
				file << std::endl << "\t.type\t" << contxt.funct_id << "," << " @function" << std::endl;
				file << contxt.funct_id << ":" << std::endl;
				contxt.protect = true;
			}
			//contxt.Scopes.push_back(contxt.funct_id);
			//contxt.funcion_temp.returnType=contxt.functionReturnTypetemp; 
			contxt.funcion_temp.name=contxt.funct_id;
			contxt.functions_declared.push_back(contxt.funcion_temp);
			contxt.funcion_temp.paramters_size=0;
			if( DeclarationListPtr != NULL ) {   			//( functions having const-correctness for example )
				//DeclarationListPtr->render_asm(file,contxt);
			}
			//std::cout << "start of compund" << contxt.funct_id << std::endl;
			if( CompoundStatementPtr != NULL ) { // function_def.area is calculated here
				contxt.totalStackArea = 12+104+120;
				contxt.reading = true;						// this flag is used to prevent writing asm on file<< while reading ahead
				CompoundStatementPtr->render_asm(file,contxt);  // ...(file,initialized,function)
				contxt.reading = false;
			}
			contxt.is_function_call=false;	
			//std:: cout << "\nmax_offset" << contxt.max_offset << " " <<  contxt.funct_id <<"\n";
			contxt.totalStackArea+=contxt.max_offset;
			//file << "\n max_offset = " << contxt.max_offset << "\n";
			contxt.max_offset=16;
			//print_scopes(contxt, file);
			if(contxt.Scopes.size()>=1){
				for (int k=0; k<contxt.Variables.size(); k++)
				{	for (int j=contxt.Scopes.size()-1; j>=0; j--)
					{			
						if(contxt.Scopes[j]==contxt.Variables[k].scope)
						{
							contxt.Variables[k].param_offset = contxt.Variables[k].offset-4;
							contxt.Variables[k].offset += contxt.totalStackArea;
						}
					}
				}
			}		
			//contxt.function_def.name = contxt.funct_id;
			//contxt.function_def.no_parameters = no_parameters; // private var in ParameterList
			//no_parameters = 0;
			//contxt.function_def.area = contxt.totalStackArea;
			
			//contxt.functions.push_back(contxt.function_def);
			file << std::endl << "\t.set noreorder" << std::endl;
			file << std::endl << "\t.set nomacro" << std::endl;
			
			file << std::endl << "\taddiu $sp,$sp,-"<< contxt.totalStackArea+4;
			file << std::endl << "\tsw $fp," << contxt.totalStackArea << "($sp)";
			file << std::endl << "\tsw $31," << contxt.totalStackArea-4 <<"($sp)";
			file << std::endl << "\tmove $fp,$sp\n";
			// file << std::endl << "\tlui $28,%hi(__gnu_local_gp)";
			// file << std::endl << "\taddiu $28,$28,%lo(__gnu_local_gp)";

			
			contxt.floatt=0;
			for(int i=0; i<contxt.Variables.size(); i++)
			{
				if(contxt.Variables[i].param_offset==0 && contxt.Variables[i].scope==contxt.funct_id && contxt.Variables[i].DataType == "float")
				{
					contxt.floatt++;
				}
				if(contxt.floatt==1 && contxt.Variables[i].param_offset==4 && contxt.Variables[i].scope==contxt.funct_id && contxt.Variables[i].DataType == "float")
				{
					contxt.floatt++;	
				}
			}
			if(contxt.floatt)
			{
				file << std::endl << "\tswc1\t$f12," <<  contxt.totalStackArea + 4*(4-3) << "($sp)"; 
			}
			if(contxt.floatt==2)
			{
				file << std::endl << "\tswc1 $f14, " << contxt.totalStackArea + 4*(5-3) << "($sp)"; 
			}

			std::string dataType = "";
			int j = 0;	
			for(int i=4+contxt.floatt; i<=7; i++) //shift by 4 all the parameters
			{
				if(contxt.Variables.size() > j){						
					dataType = contxt.Variables[j].DataType;
				}
						
				if(dataType == "char"){
					file << std::endl << "\tsb $" << i <<  "," << contxt.totalStackArea + 4*(i-3) << "($sp)";
				}
				else if(dataType == "short"){
					file << std::endl << "\tsh $" << i <<  "," << contxt.totalStackArea + 4*(i-3) << "($sp)";
				}
				else{
					file << std::endl << "\tsw $" << i <<  "," << contxt.totalStackArea + 4*(i-3) << "($sp)";
				}
				dataType = "";
				j++;
				
			}

			contxt.variable.offset=contxt.totalStackArea-4;
			if( CompoundStatementPtr != NULL ) {
				//contxt.reading = false;
				CompoundStatementPtr->render_asm(file,contxt);
				//contxt.reading = false;
			}

			file << std::endl << "\tmove $sp,$fp";
			file << std::endl << "\tlw $31," << contxt.totalStackArea-4 <<"($sp)";
			file << std::endl << "\tlw $fp," << contxt.totalStackArea << "($sp)";
			file << std::endl << "\taddiu $sp,$sp," << contxt.totalStackArea + 4;
			file << std::endl << "\tj $31" << std::endl;
			file << std::endl << "\tnop" << std::endl;
			file << std::endl << "\t.set macro" << std::endl;
			file << std::endl << "\t.set reorder" << std::endl;
			file << std::endl << "\t.end " << contxt.funct_id << std::endl;
			file << std::endl << "\t.size " << contxt.funct_id << ", .-" << contxt.funct_id << std::endl;
			//contxt.totalStackArea = 8;
			//print_variables(contxt, file);
			if(contxt.Scopes.size()>0){
					contxt.Scopes.pop_back(); //assign the variable the scope it is in
				}
				else 
				{
					//std::cout << "PROBLEMS with Scopes" << std::endl;
				}
		}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r14
movb $0x0, 0x13e7c(%rdx)
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0xbfbe
movb $0x1, 0x360(%rbx)
movq %rbp, %rsi
movq %rbx, %rdx
callq 0xc8fa
movb $0x0, 0x360(%rbx)
leaq 0x368(%rbx), %rsi
leaq 0x418(%rbx), %r12
leaq 0x440(%rbx), %rdi
callq 0x71e0
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xc16a
movb $0x0, 0x21a(%rbx)
movq %rbp, %rsi
movq %rbx, %rdx
callq 0xc9d4
movq %rbp, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x214db(%rip), %rsi     # 0x2d4e9
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x214c3(%rip), %rsi     # 0x2d4f0
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x214ae(%rip), %rsi     # 0x2d4fa
movq %rax, %rdi
callq 0x7310
movq %r14, %r13
leaq 0x220(%rbx), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x72d0
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x21483(%rip), %r15     # 0x2d503
movq %rax, %rdi
movq %r15, %rsi
callq 0x7310
leaq 0x21478(%rip), %rsi     # 0x2d50a
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
movq %rax, %rdi
movq %r15, %rsi
callq 0x7310
leaq 0x21457(%rip), %rsi     # 0x2d513
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x21444(%rip), %rsi     # 0x2d51f
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movq %r14, %rsi
callq 0x72d0
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x21421(%rip), %rsi     # 0x2d526
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movq %r14, %rsi
callq 0x72d0
leaq 0x21569(%rip), %rsi     # 0x2d688
movq %rax, %rdi
callq 0x7310
leaq 0x21400(%rip), %rsi     # 0x2d52e
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %r14
callq 0x72d0
leaq 0x212a3(%rip), %rsi     # 0x2d3f6
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movb $0x1, 0x21a(%rbx)
leaq 0x220(%rbx), %rsi
leaq 0x420(%rbx), %rdi
movq %rsi, 0x10(%rsp)
callq 0x71e0
leaq 0x400(%rbx), %rdi
movq %r12, %rsi
callq 0xca58
andl $0x0, 0x418(%rbx)
movq %r14, 0x28(%rsp)
movq 0x20(%r14), %rdi
testq %rdi, %rdi
je 0xc1c9
movl $0xec, 0x308(%rbx)
movb $0x1, 0x21b(%rbx)
movq %rbp, %rsi
movq %rbx, %rdx
callq 0xca84
movb $0x0, 0x21b(%rbx)
movb $0x0, 0x4b0(%rbx)
movl 0x4ac(%rbx), %eax
addl %eax, 0x308(%rbx)
movl $0x10, 0x4ac(%rbx)
movq 0x468(%rbx), %rax
cmpq 0x460(%rbx), %rax
je 0xc29a
xorl %r14d, %r14d
movl $0xb0, %r15d
movq 0x248(%rbx), %rax
subq 0x240(%rbx), %rax
cqto
idivq %r15
cmpq %r14, %rax
jbe 0xc29a
movq 0x468(%rbx), %rax
subq 0x460(%rbx), %rax
shrq $0x5, %rax
movl %eax, %r12d
decq %r12
imulq $0xb0, %r14, %r13
testl %r12d, %r12d
js 0xc292
movl %r12d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
shlq $0x5, %rdi
addq 0x460(%rbx), %rdi
movq 0x240(%rbx), %rax
leaq (%rax,%r13), %rsi
addq $0x30, %rsi
callq 0xcbbb
testb %al, %al
je 0xc28d
movq 0x240(%rbx), %rax
movl 0x50(%rax,%r13), %ecx
leal -0x4(%rcx), %edx
movl %edx, 0x98(%rax,%r13)
addl 0x308(%rbx), %ecx
movl %ecx, 0x50(%rax,%r13)
decq %r12
jmp 0xc23a
incq %r14
jmp 0xc203
leaq 0x460(%rbx), %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
callq 0x7190
leaq 0x21284(%rip), %rsi     # 0x2d539
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x21275(%rip), %rsi     # 0x2d549
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %rbp, %rdi
callq 0x7190
leaq 0x21264(%rip), %rsi     # 0x2d557
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $0x4, %esi
movq %rax, %rdi
callq 0x7590
movq %rbp, %rdi
callq 0x7190
leaq 0x2124d(%rip), %rsi     # 0x2d568
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
movq %rax, %rdi
callq 0x7590
leaq 0x21239(%rip), %r14     # 0x2d571
movq %rax, %rdi
movq %r14, %rsi
callq 0x7310
movq %rbp, %rdi
callq 0x7190
leaq 0x21225(%rip), %rsi     # 0x2d577
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $-0x4, %esi
movq %rax, %rdi
callq 0x7590
movq %rax, %rdi
movq %r14, %rsi
callq 0x7310
movq %rbp, %rdi
callq 0x7190
leaq 0x211fb(%rip), %rsi     # 0x2d580
movq %rax, %rdi
callq 0x7310
andl $0x0, 0xb8(%rbx)
pushq $0x58
popq %r15
xorl %r12d, %r12d
movl $0xb0, %r13d
leaq 0x211e7(%rip), %r14     # 0x2d58f
movq 0x240(%rbx), %rcx
movq 0x248(%rbx), %rax
subq %rcx, %rax
cqto
idivq %r13
cmpq %r12, %rax
jbe 0xc466
cmpl $0x0, 0x40(%rcx,%r15)
jne 0xc40b
leaq (%rcx,%r15), %rdi
addq $-0x28, %rdi
movq 0x10(%rsp), %rsi
callq 0xcbbb
testb %al, %al
je 0xc40b
movq 0x240(%rbx), %rdi
addq %r15, %rdi
movq %r14, %rsi
callq 0x820e
testb %al, %al
je 0xc40b
movl 0xb8(%rbx), %eax
incl %eax
movl %eax, 0xb8(%rbx)
jmp 0xc411
movl 0xb8(%rbx), %eax
cmpl $0x1, %eax
jne 0xc457
movq 0x240(%rbx), %rax
cmpl $0x4, 0x40(%rax,%r15)
jne 0xc457
leaq (%rax,%r15), %rdi
addq $-0x28, %rdi
movq 0x10(%rsp), %rsi
callq 0xcbbb
testb %al, %al
je 0xc457
movq 0x240(%rbx), %rdi
addq %r15, %rdi
movq %r14, %rsi
callq 0x820e
testb %al, %al
je 0xc457
incl 0xb8(%rbx)
incq %r12
addq $0xb0, %r15
jmp 0xc3a8
cmpl $0x0, 0xb8(%rbx)
je 0xc4e6
movq %rbp, %rdi
callq 0x7190
leaq 0x21117(%rip), %rsi     # 0x2d595
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $0x4, %esi
movq %rax, %rdi
callq 0x7590
leaq 0x210d3(%rip), %rsi     # 0x2d571
movq %rax, %rdi
callq 0x7310
cmpl $0x2, 0xb8(%rbx)
jne 0xc4e6
movq %rbp, %rdi
callq 0x7190
leaq 0x210e3(%rip), %rsi     # 0x2d5a1
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $0x8, %esi
movq %rax, %rdi
callq 0x7590
leaq 0x21093(%rip), %rsi     # 0x2d571
movq %rax, %rdi
callq 0x7310
movq %rbp, 0x18(%rsp)
leaq 0x21215(%rip), %rsi     # 0x2d707
leaq 0x38(%rsp), %r12
leaq 0xf(%rsp), %rdx
movq %r12, %rdi
callq 0x7120
movl 0xb8(%rbx), %eax
leal 0x4(%rax), %ecx
movq %rcx, 0x30(%rsp)
leal 0x4(,%rax,4), %r15d
pushq $0x58
popq %r14
xorl %r13d, %r13d
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rbp
cmpl $0x8, %ebp
jge 0xc61e
movq 0x240(%rbx), %rsi
movq 0x248(%rbx), %rax
subq %rsi, %rax
cqto
movl $0xb0, %ecx
idivq %rcx
cmpq %r13, %rax
jbe 0xc55e
addq %r14, %rsi
movq %r12, %rdi
callq 0x71e0
movq %r12, %rdi
leaq 0x21046(%rip), %rsi     # 0x2d5ae
callq 0x820e
testb %al, %al
je 0xc584
movq 0x18(%rsp), %rdi
callq 0x7190
leaq 0x21031(%rip), %rsi     # 0x2d5b3
jmp 0xc5bb
movq %r12, %rdi
leaq 0x2102b(%rip), %rsi     # 0x2d5b9
callq 0x820e
testb %al, %al
je 0xc5aa
movq 0x18(%rsp), %rdi
callq 0x7190
leaq 0x21017(%rip), %rsi     # 0x2d5bf
jmp 0xc5bb
movq 0x18(%rsp), %rdi
callq 0x7190
leaq 0x21390(%rip), %rsi     # 0x2d94b
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movl %ebp, %esi
callq 0x7590
movq %rax, %rdi
leaq 0x210b1(%rip), %rsi     # 0x2d688
callq 0x7310
movl 0x308(%rbx), %esi
addl %r15d, %esi
movq %rax, %rdi
callq 0x7590
movq %rax, %rdi
leaq 0x20f7a(%rip), %rsi     # 0x2d571
callq 0x7310
movq %r12, %rdi
leaq 0x21101(%rip), %rsi     # 0x2d707
callq 0x7630
incq %r13
addq $0xb0, %r14
addl $0x4, %r15d
jmp 0xc521
movl 0x308(%rbx), %eax
addl $-0x4, %eax
movl %eax, 0x2a8(%rbx)
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %r14
je 0xc64b
movq %r14, %rsi
movq %rbx, %rdx
callq 0xca84
movq %r14, %rdi
callq 0x7190
leaq 0x20f6b(%rip), %rsi     # 0x2d5c5
movq %rax, %rdi
callq 0x7310
movq %r14, %rdi
callq 0x7190
leaq 0x20f62(%rip), %rsi     # 0x2d5d3
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $-0x4, %esi
movq %rax, %rdi
callq 0x7590
leaq 0x20ee0(%rip), %rsi     # 0x2d571
movq %rax, %rdi
callq 0x7310
movq %r14, %rdi
callq 0x7190
leaq 0x20f34(%rip), %rsi     # 0x2d5dc
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
movq %rax, %rdi
callq 0x7590
leaq 0x20eac(%rip), %rsi     # 0x2d571
movq %rax, %rdi
callq 0x7310
movq %r14, %rdi
callq 0x7190
leaq 0x20f09(%rip), %rsi     # 0x2d5e5
movq %rax, %rdi
callq 0x7310
movl 0x308(%rbx), %esi
addl $0x4, %esi
movq %rax, %rdi
callq 0x7590
movq %r14, %rdi
callq 0x7190
leaq 0x20ef1(%rip), %rsi     # 0x2d5f5
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %r14, %rdi
callq 0x7190
leaq 0x20ed9(%rip), %rsi     # 0x2d5fc
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %r14, %rdi
callq 0x7190
leaq 0x20ebf(%rip), %rsi     # 0x2d601
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %r14, %rdi
callq 0x7190
leaq 0x20eac(%rip), %rsi     # 0x2d60d
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
callq 0x7190
movq %r14, %rdi
callq 0x7190
leaq 0x20e9b(%rip), %rsi     # 0x2d61b
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x72d0
movq %rax, %rdi
callq 0x7190
movq %r14, %rdi
callq 0x7190
leaq 0x20e76(%rip), %rsi     # 0x2d622
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x72d0
leaq 0x20e62(%rip), %rsi     # 0x2d62a
movq %rax, %rdi
callq 0x7310
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x72d0
movq %rax, %rdi
callq 0x7190
movq 0x468(%rbx), %rax
cmpq 0x460(%rbx), %rax
je 0xc7ff
movq 0x20(%rsp), %rdi
callq 0xcbde
leaq 0x38(%rsp), %rdi
callq 0x7170
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc81a
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x7170
movq %rbx, %rdi
callq 0x75c0
nop