// File: 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
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x138(%rbp)
movl $0xa, %esi
callq 0x31c0
movq -0x138(%rbp), %rdi
callq 0xa9c0
movq -0x138(%rbp), %rsi
movq 0x140ba(%rip), %rdi     # 0x1efd8
callq 0x31f0
movq %rax, %rdi
leaq 0xb2de(%rip), %rsi      # 0x1620b
callq 0x3220
movq -0x138(%rbp), %rdi
callq 0x31d0
movq %rax, -0x10(%rbp)
movq -0x138(%rbp), %rdi
callq 0x3140
movq %rax, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x7190
testb $0x1, %al
jne 0xaf68
jmp 0xb1a0
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0xaf98
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7150
movq %rax, -0x28(%rbp)
jmp 0xaf42
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0xafcf
jmp 0xafab
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %eax
cmpl $0xa, %eax
je 0xafcd
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7150
movq %rax, -0x30(%rbp)
jmp 0xafab
jmp 0xafcf
jmp 0xafd1
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x139(%rbp)
je 0xb002
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x139(%rbp)
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0xb00e
jmp 0xb047
leaq -0x10(%rbp), %rdi
callq 0x6f70
movb $0x20, (%rax)
movb $0x1, %al
testb $0x1, %al
jne 0xb022
jmp 0xb02d
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xb036
movl -0x20(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x20(%rbp)
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7150
movq %rax, -0x38(%rbp)
jmp 0xafd1
movl $0x0, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3360
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0xa, %ecx
movb %al, -0x13a(%rbp)
je 0xb0ac
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x23, %ecx
movb %al, -0x13b(%rbp)
jne 0xb0a0
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
sete %al
movb %al, -0x13b(%rbp)
movb -0x13b(%rbp), %al
movb %al, -0x13a(%rbp)
movb -0x13a(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xb0ba
jmp 0xb110
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %eax
cmpl $0x22, %eax
jne 0xb0d4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x6f70
movsbl (%rax), %esi
leaq -0x60(%rbp), %rdi
callq 0x31c0
jmp 0xb0eb
leaq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x7150
movq %rax, -0x78(%rbp)
jmp 0xb057
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xb192
leaq -0x60(%rbp), %rdi
callq 0x31a0
cmpq $0x0, %rax
je 0xb184
movq -0x138(%rbp), %rax
addq $0x38, %rax
movq %rax, -0x148(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x20(%rbp), %rdx
callq 0xb750
jmp 0xb147
movq -0x148(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xb720
jmp 0xb15c
leaq -0xa0(%rbp), %rdi
callq 0xb790
jmp 0xb184
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0xb790
jmp 0xb192
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0xaf42
leaq -0x60(%rbp), %rdi
callq 0x3170
jmp 0xb6c7
movq -0x138(%rbp), %rdi
addq $0x50, %rdi
movl $0x1, %esi
callq 0xb7b0
movq -0x138(%rbp), %rdi
movb $0x1, 0x28(%rdi)
addq $0x38, %rdi
callq 0xb840
movq %rax, -0xa8(%rbp)
movq -0x138(%rbp), %rdi
addq $0x38, %rdi
callq 0xb8b0
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0xb870
testb $0x1, %al
jne 0xb203
jmp 0xb660
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x64, %eax
jne 0xb39c
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x1, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x65, %eax
jne 0xb39c
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x2, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x66, %eax
jne 0xb39c
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq -0x138(%rbp), %rdi
movl 0x20(%rax), %eax
movl %eax, -0xb4(%rbp)
addq $0x38, %rdi
callq 0xb840
movq %rax, -0xc0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xb900
movl %eax, -0xb8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xb950
movq %rax, %rdi
callq 0xb8e0
movl 0x20(%rax), %eax
cmpl -0xb4(%rbp), %eax
jle 0xb2d7
jmp 0xb2b6
movq -0x138(%rbp), %rdi
addq $0x38, %rdi
callq 0xb840
movq %rax, -0xd0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xb900
subq $0x1, %rax
movl %eax, -0xc4(%rbp)
movq 0x13cc6(%rip), %rdi     # 0x1efd8
leaq 0xaef6(%rip), %rsi      # 0x1620f
callq 0x3220
movq %rax, %rdi
movl -0xb8(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xaee6(%rip), %rsi      # 0x1621c
callq 0x3220
movq %rax, %rdi
movl -0xc4(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xaeba(%rip), %rsi      # 0x1620d
callq 0x3220
movq -0x138(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x150(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0xc4(%rbp), %rdx
callq 0xb9a0
movq -0x150(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xb970
jmp 0xb65b
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x63, %eax
jne 0xb57f
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x1, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x6c, %eax
jne 0xb57f
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x2, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x61, %eax
jne 0xb57f
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x3, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0xb57f
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq %rax, %rdi
movl $0x4, %esi
callq 0x3450
movsbl (%rax), %eax
cmpl $0x73, %eax
jne 0xb57f
leaq -0xa8(%rbp), %rdi
callq 0xb8e0
movq -0x138(%rbp), %rdi
movl 0x20(%rax), %eax
movl %eax, -0xdc(%rbp)
addq $0x38, %rdi
callq 0xb840
movq %rax, -0xf0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xb900
movl %eax, -0xe0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xb950
movq %rax, %rdi
callq 0xb8e0
movl 0x20(%rax), %eax
cmpl -0xdc(%rbp), %eax
jle 0xb4ba
jmp 0xb499
movq -0x138(%rbp), %rdi
addq $0x38, %rdi
callq 0xb840
movq %rax, -0xf8(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xb900
subq $0x1, %rax
movl %eax, -0xe4(%rbp)
movq 0x13ae3(%rip), %rdi     # 0x1efd8
leaq 0xad24(%rip), %rsi      # 0x16220
callq 0x3220
movq %rax, %rdi
movl -0xe0(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xad03(%rip), %rsi      # 0x1621c
callq 0x3220
movq %rax, %rdi
movl -0xe4(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xacd7(%rip), %rsi      # 0x1620d
callq 0x3220
movq -0x138(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x158(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0xe4(%rbp), %rdx
callq 0xb9a0
movq -0x158(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xb970
jmp 0xb659
movq -0x138(%rbp), %rdi
movb $0x0, 0x28(%rdi)
addq $0x38, %rdi
callq 0xb840
movq %rax, -0x110(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xb900
movq -0x138(%rbp), %rdi
movl %eax, -0x104(%rbp)
addq $0x38, %rdi
callq 0xb9d0
subq $0x1, %rax
movl %eax, -0x114(%rbp)
leaq -0x11c(%rbp), %rdi
leaq -0x104(%rbp), %rsi
leaq -0x114(%rbp), %rdx
callq 0xb9a0
movq -0x138(%rbp), %rdi
addq $0x50, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xba00
movq %rax, %rdi
leaq -0x11c(%rbp), %rsi
callq 0xba20
movq 0x139c7(%rip), %rdi     # 0x1efd8
leaq 0xac14(%rip), %rsi      # 0x1622c
callq 0x3220
movq %rax, %rdi
movl -0x104(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xabe7(%rip), %rsi      # 0x1621c
callq 0x3220
movq %rax, %rdi
movl -0x114(%rbp), %esi
callq 0x33e0
movq %rax, %rdi
leaq 0xabbb(%rip), %rsi      # 0x1620d
callq 0x3220
jmp 0xb660
jmp 0xb65b
jmp 0xb1d0
movq -0x138(%rbp), %rdi
addq $0x50, %rdi
callq 0xba90
movq -0x138(%rbp), %rdi
movq %rax, -0x128(%rbp)
addq $0x50, %rdi
callq 0xbac0
movq %rax, -0x130(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xba50
movq %rax, %rcx
movq -0x138(%rbp), %rax
movb 0x28(%rax), %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %edx
subq %rdx, %rcx
movq %rcx, 0x20(%rax)
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x33f0