// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
movl $0xa, %esi
callq 0x21a0
movq %rbx, %rdi
callq 0x5b8c
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x8ea8(%rip), %rdi      # 0xefd8
callq 0x2250
leaq 0x50df(%rip), %rsi      # 0xb21b
movl $0x3, %edx
movq %rax, %rdi
callq 0x2250
cmpq $0x0, 0x8(%rbx)
je 0x6268
movq (%rbx), %r15
leaq -0x68(%rbp), %r13
leaq 0x38(%rbx), %rax
movq %rax, -0x30(%rbp)
movzbl (%r15), %eax
cmpl $0xa, %eax
je 0x6255
cmpl $0x23, %eax
jne 0x6188
decq %r15
movq %r15, %rax
leaq 0x1(%rax), %r15
cmpb $0xa, 0x1(%rax)
movq %r15, %rax
jne 0x617b
xorl %r14d, %r14d
movzbl (%r15,%r14), %eax
cmpl $0x20, %eax
je 0x619a
cmpl $0x9, %eax
jne 0x61a4
movb $0x20, (%r15,%r14)
incq %r14
jmp 0x618b
movq %rbx, %r12
movq %r13, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movb $0x0, -0x68(%rbp)
movb (%r15,%r14), %r13b
addq %r14, %r15
cmpb $0xa, %r13b
je 0x61f8
xorl %ebx, %ebx
cmpb $0x23, %r13b
jne 0x61d3
movl %ebx, %eax
andl $0x1, %eax
je 0x61f8
movsbl %r13b, %esi
leaq -0x78(%rbp), %rdi
callq 0x21a0
xorl %eax, %eax
cmpb $0x22, %r13b
sete %al
addl %eax, %ebx
movb 0x1(%r15), %r13b
incq %r15
cmpb $0xa, %r13b
jne 0x61c6
movq -0x70(%rbp), %rdx
testq %rdx, %rdx
movq %r12, %rbx
leaq -0x68(%rbp), %r13
leaq -0x58(%rbp), %r12
je 0x6245
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x78(%rbp), %rsi
addq %rsi, %rdx
movq %r12, %rdi
callq 0x4df8
movl %r14d, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x65be
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6245
callq 0x21c0
movq -0x78(%rbp), %rdi
cmpq %r13, %rdi
je 0x6258
callq 0x21c0
jmp 0x6258
incq %r15
movq (%rbx), %rax
addq 0x8(%rbx), %rax
cmpq %rax, %r15
jne 0x6163
leaq 0x50(%rbx), %rdi
movl $0x1, %esi
movq %rdi, -0x80(%rbp)
callq 0x6586
movb $0x1, 0x28(%rbx)
movq 0x38(%rbx), %r12
movq 0x40(%rbx), %rax
cmpq %rax, %r12
je 0x6525
leaq 0x68(%rbx), %rcx
movq %rcx, -0x30(%rbp)
movq (%r12), %rcx
movzbl (%rcx), %edx
cmpl $0x63, %edx
je 0x638f
cmpl $0x64, %edx
jne 0x6497
cmpb $0x65, 0x1(%rcx)
jne 0x6386
cmpb $0x66, 0x2(%rcx)
jne 0x6386
movq %r12, %rax
subq 0x38(%rbx), %rax
movl 0x20(%r12), %ecx
movq %rax, %r14
sarq $0x3, %r14
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %r14
movq %r12, %rdx
addq $0x28, %r12
addq $0x28, %rax
cmpl %ecx, 0x48(%rdx)
jg 0x62e5
shrq $0x3, %rax
imull $0xcccccccd, %eax, %r15d # imm = 0xCCCCCCCD
decl %r15d
movl $0xc, %edx
movq 0x8cc9(%rip), %r13      # 0xefd8
movq %r13, %rdi
leaq 0x4f06(%rip), %rsi      # 0xb21f
callq 0x2250
movq %r13, %rdi
movl %r14d, %esi
callq 0x2360
movq %rax, %r13
movl $0x3, %edx
movq %rax, %rdi
leaq 0x4ef1(%rip), %rsi      # 0xb22c
callq 0x2250
movq %r13, %rdi
movl %r15d, %esi
callq 0x2360
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4ec3(%rip), %rsi      # 0xb21d
callq 0x2250
movl %r14d, -0x58(%rbp)
movl %r15d, -0x54(%rbp)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0x6491
movq -0x58(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x58(%rbx)
jmp 0x647f
cmpb $0x63, %dl
jne 0x6497
cmpb $0x6c, 0x1(%rcx)
jne 0x6497
cmpb $0x61, 0x2(%rcx)
jne 0x6497
cmpb $0x73, 0x3(%rcx)
jne 0x6497
cmpb $0x73, 0x4(%rcx)
jne 0x6497
movq %r12, %rax
subq 0x38(%rbx), %rax
movl 0x20(%r12), %ecx
movq %rax, %r14
sarq $0x3, %r14
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %r14
movq %r12, %rdx
addq $0x28, %r12
addq $0x28, %rax
cmpl %ecx, 0x48(%rdx)
jg 0x63d8
shrq $0x3, %rax
imull $0xcccccccd, %eax, %r15d # imm = 0xCCCCCCCD
decl %r15d
movl $0xb, %edx
movq 0x8bd6(%rip), %r13      # 0xefd8
movq %r13, %rdi
leaq 0x4e24(%rip), %rsi      # 0xb230
callq 0x2250
movq %r13, %rdi
movl %r14d, %esi
callq 0x2360
movq %rax, %r13
movl $0x3, %edx
movq %rax, %rdi
leaq 0x4dfe(%rip), %rsi      # 0xb22c
callq 0x2250
movq %r13, %rdi
movl %r15d, %esi
callq 0x2360
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4dd0(%rip), %rsi      # 0xb21d
callq 0x2250
movl %r14d, -0x58(%rbp)
movl %r15d, -0x54(%rbp)
movq 0x70(%rbx), %rsi
cmpq 0x78(%rbx), %rsi
je 0x6472
movq -0x58(%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x70(%rbx)
jmp 0x647f
movq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x69dc
movq 0x40(%rbx), %rax
cmpq %rax, %r12
jne 0x6297
jmp 0x6525
movq -0x80(%rbp), %rdi
jmp 0x6476
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 0x8b08(%rip), %r12      # 0xefd8
leaq 0x4d65(%rip), %rsi      # 0xb23c
movl $0x8, %edx
movq %r12, %rdi
callq 0x2250
movq %r12, %rdi
movl %r15d, %esi
callq 0x2360
movq %rax, %r15
leaq 0x4d33(%rip), %rsi      # 0xb22c
movl $0x3, %edx
movq %rax, %rdi
callq 0x2250
movq %r15, %rdi
movl %r14d, %esi
callq 0x2360
leaq 0x4d05(%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 $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6568
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x656b
callq 0x21c0
jmp 0x656b
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x657d
callq 0x21c0
movq %rbx, %rdi
callq 0x2380
nop