// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xa, %esi
callq 0x21a0
movq %rbx, %rdi
callq 0x5b04
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x8f28(%rip), %rdi      # 0xefd8
callq 0x2250
leaq 0x515f(%rip), %rsi      # 0xb21b
movl $0x3, %edx
movq %rax, %rdi
callq 0x2250
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x6201
movq (%rbx), %rcx
leaq 0x38(%rbx), %rdx
movq %rdx, -0x30(%rbp)
leaq -0x58(%rbp), %r15
movq %rcx, %r12
movq %rbx, -0x60(%rbp)
movzbl (%r12), %edx
cmpl $0xa, %edx
je 0x61d3
cmpl $0x23, %edx
jne 0x610e
cmpb $0xa, 0x1(%r12)
leaq 0x1(%r12), %r12
jne 0x60ff
movb $0xa, %dl
xorl %r14d, %r14d
cmpb $0x20, %dl
je 0x611e
movzbl %dl, %eax
cmpl $0x9, %eax
jne 0x612d
movb $0x20, (%r12,%r14)
movb 0x1(%r12,%r14), %dl
incq %r14
jmp 0x6111
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movb $0x0, -0x70(%rbp)
movb (%r12,%r14), %r13b
addq %r14, %r12
cmpb $0xa, %r13b
je 0x61ed
xorl %ebx, %ebx
cmpb $0x23, %r13b
jne 0x6161
movl %ebx, %eax
andl $0x1, %eax
je 0x6187
movsbl %r13b, %esi
leaq -0x80(%rbp), %rdi
callq 0x21a0
xorl %eax, %eax
cmpb $0x22, %r13b
sete %al
addl %eax, %ebx
movb 0x1(%r12), %r13b
incq %r12
cmpb $0xa, %r13b
jne 0x6154
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
testq %rdx, %rdx
je 0x61d8
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4d94
movq -0x60(%rbp), %rbx
movl %r14d, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x6554
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x61cd
callq 0x21c0
movq -0x80(%rbp), %rsi
jmp 0x61dc
incq %r12
jmp 0x61f4
movq -0x60(%rbp), %rbx
leaq -0x70(%rbp), %rax
cmpq %rax, %rsi
je 0x61ed
movq %rsi, %rdi
callq 0x21c0
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
leaq (%rcx,%rax), %rdx
cmpq %rdx, %r12
jne 0x60ec
leaq 0x50(%rbx), %rdi
movl $0x1, %esi
movq %rdi, -0x30(%rbp)
callq 0x651c
movb $0x1, 0x28(%rbx)
movq 0x38(%rbx), %r12
movq 0x40(%rbx), %rax
cmpq %rax, %r12
je 0x64bb
leaq 0x68(%rbx), %rcx
movq %rcx, -0x88(%rbp)
movq (%r12), %rcx
movzbl (%rcx), %edx
cmpl $0x63, %edx
je 0x6322
cmpl $0x64, %edx
jne 0x642d
cmpb $0x65, 0x1(%rcx)
jne 0x642d
cmpb $0x66, 0x2(%rcx)
jne 0x642d
movq %r12, %rax
subq 0x38(%rbx), %rax
movl 0x20(%r12), %ecx
movq %rax, %r13
sarq $0x3, %r13
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %r13
movq %r12, %rdx
addq $0x28, %r12
addq $0x28, %rax
cmpl %ecx, 0x48(%rdx)
jg 0x6281
shrq $0x3, %rax
imull $0xcccccccd, %eax, %r15d # imm = 0xCCCCCCCD
decl %r15d
movl $0xc, %edx
movq 0x8d2d(%rip), %r14      # 0xefd8
movq %r14, %rdi
leaq 0x4f6a(%rip), %rsi      # 0xb21f
callq 0x2250
movq %r14, %rdi
movl %r13d, %esi
callq 0x2350
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x4f55(%rip), %rsi      # 0xb22c
callq 0x2250
movq %r14, %rdi
movl %r15d, %esi
callq 0x2350
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4f27(%rip), %rsi      # 0xb21d
callq 0x2250
movl %r13d, -0x58(%rbp)
movl %r15d, -0x54(%rbp)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0x6405
movq -0x58(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x58(%rbx)
jmp 0x641b
cmpb $0x6c, 0x1(%rcx)
jne 0x642d
cmpb $0x61, 0x2(%rcx)
jne 0x642d
cmpb $0x73, 0x3(%rcx)
jne 0x642d
cmpb $0x73, 0x4(%rcx)
jne 0x642d
movq %r12, %rax
subq 0x38(%rbx), %rax
movl 0x20(%r12), %ecx
movq %rax, %r13
sarq $0x3, %r13
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %r13
movq %r12, %rdx
addq $0x28, %r12
addq $0x28, %rax
cmpl %ecx, 0x48(%rdx)
jg 0x636b
shrq $0x3, %rax
imull $0xcccccccd, %eax, %r15d # imm = 0xCCCCCCCD
decl %r15d
movl $0xb, %edx
movq 0x8c43(%rip), %r14      # 0xefd8
movq %r14, %rdi
leaq 0x4e91(%rip), %rsi      # 0xb230
callq 0x2250
movq %r14, %rdi
movl %r13d, %esi
callq 0x2350
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x4e6b(%rip), %rsi      # 0xb22c
callq 0x2250
movq %r14, %rdi
movl %r15d, %esi
callq 0x2350
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4e3d(%rip), %rsi      # 0xb21d
callq 0x2250
movl %r13d, -0x58(%rbp)
movl %r15d, -0x54(%rbp)
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x640b
movq -0x58(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x641b
movq -0x30(%rbp), %rdi
jmp 0x6412
movq -0x88(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x6972
movq 0x40(%rbx), %rax
cmpq %rax, %r12
jne 0x6233
jmp 0x64bb
movb $0x0, 0x28(%rbx)
movq 0x38(%rbx), %rcx
movq 0x50(%rbx), %rdx
subq %rcx, %r12
shrq $0x3, %r12
imull $0xcccccccd, %r12d, %r15d # imm = 0xCCCCCCCD
subq %rcx, %rax
shrq $0x3, %rax
imull $0xcccccccd, %eax, %r14d # imm = 0xCCCCCCCD
decl %r14d
movl %r15d, (%rdx)
movl %r14d, 0x4(%rdx)
movq 0x8b72(%rip), %r12      # 0xefd8
leaq 0x4dcf(%rip), %rsi      # 0xb23c
movl $0x8, %edx
movq %r12, %rdi
callq 0x2250
movq %r12, %rdi
movl %r15d, %esi
callq 0x2350
movq %rax, %r15
leaq 0x4d9d(%rip), %rsi      # 0xb22c
movl $0x3, %edx
movq %rax, %rdi
callq 0x2250
movq %r15, %rdi
movl %r14d, %esi
callq 0x2350
leaq 0x4d6f(%rip), %rsi      # 0xb21d
movl $0x1, %edx
movq %rax, %rdi
callq 0x2250
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
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6501
callq 0x21c0
jmp 0x6501
jmp 0x64fe
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x6513
callq 0x21c0
movq %rbx, %rdi
callq 0x2370
nop