// File: /workspace/github_cpp_makefile_star2_O2/nikhilYadala[P]Python_to_cpp/Source/src/functionize.cpp
// Function: source_code::functionize()
void source_code::functionize()
{

	code.push_back('\n');
	self_sanitize(&code);
	std::cout<<code<<"\n\n\n";
	for(std::string::iterator itr=code.begin();itr!=code.end();)   //This for loop has no increment part to provide flexibility to inner code 
	{
		
		int i=0,space_count=0;
		
		if(*itr=='\n'){		//skips an empty line or a comment line
			itr++;
			continue;
		}

		if(*itr=='#')
		{
			while(*itr!='\n')
				itr++;	
		}


		while(*(itr)==' '||*itr=='	'){
				if(*itr=' ')
					space_count++;
				else space_count+=tab_size;
				itr++;
		} 
				
		int flag = 0;
		std::string buff;
		while(!(*itr=='\n'||*itr=='#' && flag%2==0)){			//This doesn't supports yet #,key words,etc. in strings ... small feature to implement later
			if(*itr=='"')
				flag+=1;
			buff.push_back(*itr);
			itr++;
		}
			
		
		if(buff.size())							//If line isn't empty 
			lines.push_back(line_pair(buff,space_count));
	}

	    // for(std::vector< line_pair >::iterator itr=lines.begin();itr!=lines.end();++itr)
		   // std::cout<<"lin"<<itr-lines.begin()<<": "<<itr->second<<"          "<<itr->first<<"\n"; 

	functions.resize(1);//Add sparse code here later
	only_functions=1;

	for(std::vector< line_pair >::iterator itr=lines.begin();itr!=lines.end();)
		{
			if(itr->first[0]=='d'&&itr->first[1]=='e'&&itr->first[2]=='f')
				{
					int space_count=itr->second;
					int i1=itr-lines.begin(),i2;
					while((++itr)->second>space_count);
					i2=itr-lines.begin()-1; 	
					std::cout<<"Fucntion -> "<<i1<<"   "<<i2<<"\n";	
					functions.push_back(int_pair(i1,i2));
				}

			else if(itr->first[0]=='c'&&itr->first[1]=='l'&&itr->first[2]=='a'&&itr->first[3]=='s'&&itr->first[4]=='s')
	        {

	            //classes inherited are taken care off in convert_to_cpp_classes.cpp
	            
	        	int space_count=itr->second;
	        	int i1,i2;
	        	i1=itr-lines.begin();
	        	while((++itr)->second > space_count);
				i2=itr-lines.begin()-1;
					std::cout<<"Classes -> "<<i1<<"   "<<i2<<"\n";	

				classes.push_back(int_pair(i1,i2));

            }
			else 
				{
					only_functions=0;
					int i1=itr-lines.begin(),i2=lines.size()-1;
					functions[0]=int_pair(i1,i2);	
					std::cout<<"Main -> "<<i1<<"   "<<i2<<"\n";	

					break;	
				}
		}

		number_of_functions=(functions.end()-functions.begin())-!(only_functions);  //Remove the sparse(outside of functions) code part


		  // for(std::vector< int_pair >::iterator itr=functions.begin();itr!=functions.end();++itr)
			   // std::cout<<"Function: "<<itr-functions.begin()<<"\n"<<itr->first<<"-----"<<itr->second<<"\n\n";			

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
pushq $0xa
popq %rsi
callq 0x2160
movq %rbx, %rdi
callq 0x4fc0
movq 0x7c7d(%rip), %rdi      # 0xcfd8
movq %rbx, %rsi
callq 0x2180
leaq 0x3e91(%rip), %rsi      # 0x91fb
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rcx
leaq 0x38(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq -0x90(%rbp), %r15
movq %rcx, %r13
movq %rbx, -0x30(%rbp)
addq 0x8(%rbx), %rcx
cmpq %rcx, %r13
je 0x546d
movzbl (%r13), %eax
cmpl $0xa, %eax
jne 0x53a7
incq %r13
jmp 0x538f
cmpl $0x23, %eax
jne 0x53bb
cmpb $0xa, %al
je 0x53b9
movb 0x1(%r13), %al
incq %r13
jmp 0x53ac
movb $0xa, %al
xorl %r14d, %r14d
cmpb $0x20, %al
je 0x53ca
movzbl %al, %eax
cmpl $0x9, %eax
jne 0x53da
movb $0x20, (%r13,%r14)
movb 0x1(%r13,%r14), %al
incq %r14
jmp 0x53be
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
addq %r14, %r13
xorl %r12d, %r12d
movb (%r13), %bl
cmpb $0xa, %bl
je 0x5428
cmpb $0x23, %bl
jne 0x540d
movl %r12d, %eax
andl $0x1, %eax
je 0x5428
movsbl %bl, %esi
movq %r15, %rdi
callq 0x2160
xorl %eax, %eax
cmpb $0x22, %bl
sete %al
addl %eax, %r12d
incq %r13
jmp 0x53f7
cmpq $0x0, -0x88(%rbp)
je 0x5459
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2290
movl %r14d, -0x50(%rbp)
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x574e
movq %rbx, %rdi
callq 0x20e0
movq %r15, %rdi
callq 0x20e0
movq -0x30(%rbp), %rbx
movq (%rbx), %rcx
jmp 0x538b
movq -0x30(%rbp), %rbx
leaq 0x50(%rbx), %rdi
pushq $0x1
popq %rsi
movq %rdi, -0x48(%rbp)
callq 0x5716
movb $0x1, 0x28(%rbx)
movq 0x38(%rbx), %r12
leaq 0x68(%rbx), %rax
movq %rax, -0x40(%rbp)
pushq $0x28
popq %r15
movq 0x40(%rbx), %rcx
cmpq %rcx, %r12
je 0x569b
movq (%r12), %rax
movzbl (%rax), %edx
cmpl $0x63, %edx
je 0x555f
cmpl $0x64, %edx
jne 0x5624
cmpb $0x65, 0x1(%rax)
jne 0x5624
cmpb $0x66, 0x2(%rax)
jne 0x5624
movl 0x20(%r12), %esi
movq %r12, %rcx
movq -0x38(%rbp), %rax
subq (%rax), %rcx
movq %rcx, %rax
cqto
idivq %r15
movq %rax, %r13
movq %r12, %rax
addq $0x28, %r12
addq $0x28, %rcx
cmpl %esi, 0x48(%rax)
jg 0x54e9
movq %rcx, %rax
cqto
idivq %r15
movq %rax, %r14
decl %r14d
movq 0x7aca(%rip), %rdi      # 0xcfd8
leaq 0x3cea(%rip), %rsi      # 0x91ff
callq 0x21a0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2310
movq %rax, %rdi
leaq 0x3cdd(%rip), %rsi      # 0x920c
callq 0x21a0
movq %rax, %rdi
movl %r14d, %esi
callq 0x2310
movq %rax, %rdi
leaq 0x3cb4(%rip), %rsi      # 0x91fd
callq 0x21a0
movl %r13d, -0x70(%rbp)
movl %r14d, -0x6c(%rbp)
movq -0x48(%rbp), %rdi
jmp 0x5612
cmpb $0x6c, 0x1(%rax)
jne 0x5624
cmpb $0x61, 0x2(%rax)
jne 0x5624
cmpb $0x73, 0x3(%rax)
jne 0x5624
cmpb $0x73, 0x4(%rax)
jne 0x5624
movl 0x20(%r12), %esi
movq %r12, %rcx
movq -0x38(%rbp), %rax
subq (%rax), %rcx
movq %rcx, %rax
cqto
idivq %r15
movq %rax, %r13
movq %r12, %rax
addq $0x28, %r12
addq $0x28, %rcx
cmpl %esi, 0x48(%rax)
jg 0x55a1
movq %rcx, %rax
cqto
idivq %r15
movq %rax, %r14
decl %r14d
movq 0x7a12(%rip), %rdi      # 0xcfd8
leaq 0x3c43(%rip), %rsi      # 0x9210
callq 0x21a0
movq %rax, %rdi
movl %r13d, %esi
callq 0x2310
movq %rax, %rdi
leaq 0x3c25(%rip), %rsi      # 0x920c
callq 0x21a0
movq %rax, %rdi
movl %r14d, %esi
callq 0x2310
movq %rax, %rdi
leaq 0x3bfc(%rip), %rsi      # 0x91fd
callq 0x21a0
movl %r13d, -0x70(%rbp)
movl %r14d, -0x6c(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5afc
movq -0x30(%rbp), %rbx
jmp 0x5495
movb $0x0, 0x28(%rbx)
movq 0x38(%rbx), %rsi
movq 0x50(%rbx), %rdi
subq %rsi, %r12
movq %r12, %rax
cqto
idivq %r15
movq %rax, %r14
subq %rsi, %rcx
movq %rcx, %rax
cqto
idivq %r15
leal -0x1(%rax), %r15d
movl %r14d, (%rdi)
movl %r15d, 0x4(%rdi)
movq 0x797d(%rip), %rdi      # 0xcfd8
leaq 0x3bba(%rip), %rsi      # 0x921c
callq 0x21a0
movq %rax, %rdi
movl %r14d, %esi
callq 0x2310
leaq 0x3b93(%rip), %rsi      # 0x920c
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x2310
leaq 0x3b6a(%rip), %rsi      # 0x91fd
movq %rax, %rdi
callq 0x21a0
movq 0x58(%rbx), %rax
subq 0x50(%rbx), %rax
sarq $0x3, %rax
movzbl 0x28(%rbx), %ecx
xorq $0x1, %rcx
subq %rcx, %rax
movq %rax, 0x20(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20e0
jmp 0x56d8
jmp 0x56d5
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2320