// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]Register-Interval/main.cpp
// Function: split_abstract_basic_blocks(std::vector<basicBlock*, std::allocator<basicBlock*>>)
vector<basicBlock*> split_abstract_basic_blocks(vector<basicBlock*> ABBs){
	basicBlock *temp, *temp2;
	vector<basicBlock*> controling_basicBlocks;
	string q = "Controling_basicBlock";
	int p = 0;
        
        vector<basicBlock*> basic_blocks;

	//**********************Splitting Codes and Constructing new BBs***********************
	string str, str2;
	int found1 = 0;
	int found2 = 0;
	int foundtemp = 0;
	int foundExit = 0;
	for(int i = 0; i < ABBs.size(); i++){
		str = ABBs[i]->get_code();
		char tt = 'A';
		found1 = 0;
		found2 = str.find("<exit", found1);
		
		while(found2 != string::npos){
			str2.clear();
			for(int j = found1; j < found2; j++){
				str2 = str2 + str[j];
			}

			foundExit = str2.find("EXIT", 0);
			foundtemp = str2.find(";", 0);

			if(foundExit == string::npos){
				if(str2.find(";", foundtemp + 1) == string::npos && str2.find("@P0", 0) != string::npos){
					temp2 = new basicBlock();
					temp2->set_code(str2);
					temp2->set_name(q + std::to_string(p));
					p++;
					temp2->set_controling();
					controling_basicBlocks.push_back(temp2);

					temp->set_control_basicBlock(temp2);
				}
				else{
					temp = new basicBlock(ABBs[i]->getID());
					temp->set_code(str2);
					if(found1 == 0)
						temp->set_name(ABBs[i]->get_name());
					else{
						temp->set_name(ABBs[i]->get_name()+tt);
						tt++;
					}
					basic_blocks.push_back(temp);
				}
			}

			found1 = found2+1;
			found2 = str.find("<exit", found1);
		}

		str2.clear();
		for(int j = found1; j < str.size(); j++){
			str2 = str2 + str[j];
		}

		foundExit = str2.find("EXIT", 0);
		foundtemp = str2.find(";", 0);
		if(foundExit == string::npos){
			if(str2.find(";", foundtemp + 1) == string::npos && str2.find("@P0", 0) != string::npos){
				temp2 = new basicBlock();
				temp2->set_code(str2);
				temp2->set_name(q + std::to_string(p));
				p++;
				temp2->set_controling();
				controling_basicBlocks.push_back(temp2);

				temp->set_control_basicBlock(temp2);
			}
			else{
				temp = new basicBlock(ABBs[i]->getID());
				temp->set_code(str2);
				if(found1 == 0)
					temp->set_name(ABBs[i]->get_name());
				else{
					temp->set_name(ABBs[i]->get_name()+tt);
					tt++;
				}
				basic_blocks.push_back(temp);
			}
		}
	}
	//***********************************************************************************

	//*********************Setting Predecessors and Successors***************************
	vector<basicBlock*> P, S;
	bool isNextBB;
	int firstID;
	int lastID;
	string name;
	for(int i = 0; i < ABBs.size(); i++){
		P = ABBs[i]->get_predecessors();
		S = ABBs[i]->get_successors();

		int count = 0;
		for(int k = 0; k < basic_blocks.size(); k++){
			if(basic_blocks[k]->get_ABB() == ABBs[i]->getID()){
				if(count == 0)
					firstID = k;
				count++;
			}
		}
		lastID = firstID + count - 1;


		for(int j = 0; j < S.size(); j++){
			if(S[j]->getID() == ABBs[i]->getID()+1){
				basic_blocks[lastID]->add_successor(basic_blocks[lastID+1]);
				basic_blocks[lastID+1]->add_predecessor(basic_blocks[lastID]);
			}
		}

		for(int j = firstID; j < lastID; j++){
			basic_blocks[j]->add_successor(basic_blocks[j+1]);
			basic_blocks[j+1]->add_predecessor(basic_blocks[j]);
		}

		for(int j = firstID; j <= lastID; j++){
			if(basic_blocks[j]->get_controling_basicBlock() != nullptr){
				str = (basic_blocks[j]->get_controling_basicBlock())->get_code();
				for(int k = 0; k < basic_blocks.size(); k++){
					name = basic_blocks[k]->get_name();
					if(str.find(name, 0) != string::npos && name.size() != 0){
						basic_blocks[j]->add_successor(basic_blocks[k]);
						basic_blocks[k]->add_predecessor(basic_blocks[j]);
					}
				}
			}
		}
	}
        
        return basic_blocks;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rsi, -0x30(%rbp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, -0xf0(%rbp)
andq $0x0, -0xe0(%rbp)
leaq 0x3167(%rip), %rsi      # 0x903f
leaq -0x150(%rbp), %rdi
leaq -0x90(%rbp), %rdx
callq 0x20c0
andq $0x0, 0x10(%rbx)
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
xorl %esi, %esi
leaq -0x100(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %sil, (%rax)
movb %sil, (%rcx)
leaq -0xb0(%rbp), %r15
leaq -0x110(%rbp), %r13
movl $0x0, -0x3c(%rbp)
movq -0x30(%rbp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x64a0
movq %rsi, -0x48(%rbp)
movq (%rax,%rsi,8), %rsi
addq $0x28, %rsi
movq %r15, %rdi
callq 0x2270
leaq -0x90(%rbp), %rdi
movq %r15, %rsi
callq 0x2220
movq %r15, %rdi
callq 0x2100
movb $0x41, -0x58(%rbp)
xorl %edx, %edx
xorl %r12d, %r12d
leaq -0x90(%rbp), %rdi
leaq 0x30c5(%rip), %rsi      # 0x9055
callq 0x2390
andq $0x0, -0x108(%rbp)
movq -0x110(%rbp), %rcx
movb $0x0, (%rcx)
movslq %r12d, %r14
movsbl -0x58(%rbp), %ecx
movl %ecx, -0x68(%rbp)
cmpl $-0x1, %eax
movl %r12d, -0x60(%rbp)
je 0x6263
movq %rax, -0x70(%rbp)
movslq %eax, %r12
cmpq %r12, %r14
jge 0x5ff9
movq -0x90(%rbp), %rax
movsbl (%rax,%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6d0c
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movq %r15, %rdi
callq 0x2100
incq %r14
jmp 0x5fc5
movq %r13, %rdi
leaq 0x3058(%rip), %rsi      # 0x905b
xorl %edx, %edx
callq 0x2390
movq %rax, %r14
movq %r13, %rdi
leaq 0x3116(%rip), %r12      # 0x912d
movq %r12, %rsi
xorl %edx, %edx
callq 0x2390
cmpl $-0x1, %r14d
jne 0x6226
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2390
cmpq $-0x1, %rax
je 0x6110
movl $0xf8, %edi
callq 0x21c0
movq %rax, %r14
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq %r14, %rdi
callq 0x2b46
movq %r14, -0x50(%rbp)
leaq -0x1f0(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq %r14, %rdi
leaq -0x1f0(%rbp), %r14
movq %r14, %rsi
callq 0x2c08
movq %r14, %rdi
callq 0x2100
movq -0x50(%rbp), %r14
cmpl $0x0, -0x60(%rbp)
je 0x61dd
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
movq %r15, %rdi
callq 0x2270
leaq -0x270(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl -0x68(%rbp), %edx
callq 0x6da2
addq $0x8, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2130
movq %r12, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2100
incb -0x58(%rbp)
jmp 0x621a
movq %r13, %rdi
leaq 0x2f46(%rip), %rsi      # 0x9060
xorl %edx, %edx
callq 0x2390
cmpq $-0x1, %rax
je 0x6058
movl $0xf8, %edi
callq 0x21c0
movq %rax, %r14
movq %rax, %rdi
callq 0x291e
movq %r14, -0x38(%rbp)
leaq -0x210(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq %r14, %rdi
leaq -0x210(%rbp), %r14
movq %r14, %rsi
callq 0x2c08
movq %r14, %rdi
callq 0x2100
movq -0x38(%rbp), %r14
movq %r15, %rdi
movl -0x3c(%rbp), %esi
callq 0x6cac
leaq -0x290(%rbp), %r12
movq %r12, %rdi
leaq -0x150(%rbp), %rsi
movq %r15, %rdx
callq 0x6c5e
addq $0x8, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2130
movq %r12, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2100
movq -0x38(%rbp), %rax
movb $0x1, 0x50(%rax)
leaq -0xf0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x6ab2
incl -0x3c(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x58(%rax)
jmp 0x6226
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x2270
addq $0x8, %r14
movq %r14, %rdi
leaq -0x1d0(%rbp), %r14
movq %r14, %rsi
callq 0x2130
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0x6ab2
movq -0x70(%rbp), %rax
leal 0x1(%rax), %r12d
movslq %r12d, %rdx
jmp 0x5f82
movq -0x90(%rbp), %rax
movsbl (%rax,%r14), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6d0c
movq %r13, %rdi
movq %r15, %rsi
callq 0x2220
movq %r15, %rdi
callq 0x2100
incq %r14
cmpq %r14, -0x88(%rbp)
ja 0x6236
movq %r13, %rdi
leaq 0x2de5(%rip), %rsi      # 0x905b
xorl %edx, %edx
callq 0x2390
movq %rax, %r14
movq %r13, %rdi
leaq 0x2ea3(%rip), %r12      # 0x912d
movq %r12, %rsi
xorl %edx, %edx
callq 0x2390
cmpl $-0x1, %r14d
jne 0x6494
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2390
cmpq $-0x1, %rax
je 0x637e
movl $0xf8, %edi
callq 0x21c0
movq %rax, %r14
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq %r14, %rdi
callq 0x2b46
movq %r14, -0x50(%rbp)
leaq -0x190(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq %r14, %rdi
leaq -0x190(%rbp), %r14
movq %r14, %rsi
callq 0x2c08
movl -0x60(%rbp), %r12d
movq %r14, %rdi
callq 0x2100
movq -0x50(%rbp), %r14
testl %r12d, %r12d
je 0x644b
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
movq %r15, %rdi
callq 0x2270
leaq -0x230(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl -0x68(%rbp), %edx
callq 0x6da2
addq $0x8, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2130
movq %r12, %rdi
callq 0x2100
movq %r15, %rdi
jmp 0x6483
movq %r13, %rdi
leaq 0x2cd8(%rip), %rsi      # 0x9060
xorl %edx, %edx
callq 0x2390
cmpq $-0x1, %rax
je 0x62cb
movl $0xf8, %edi
callq 0x21c0
movq %rax, %r14
movq %rax, %rdi
callq 0x291e
movq %r14, -0x38(%rbp)
leaq -0x1b0(%rbp), %rdi
movq %r13, %rsi
callq 0x2270
movq %r14, %rdi
leaq -0x1b0(%rbp), %r14
movq %r14, %rsi
callq 0x2c08
movq %r14, %rdi
callq 0x2100
movq -0x38(%rbp), %r14
movq %r15, %rdi
movl -0x3c(%rbp), %esi
callq 0x6cac
leaq -0x250(%rbp), %r12
movq %r12, %rdi
leaq -0x150(%rbp), %rsi
movq %r15, %rdx
callq 0x6c5e
addq $0x8, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2130
movq %r12, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x2100
movq -0x38(%rbp), %rax
movb $0x1, 0x50(%rax)
leaq -0xf0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x6ab2
incl -0x3c(%rbp)
movq -0x50(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x58(%rax)
jmp 0x6494
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rsi
leaq -0x170(%rbp), %rdi
callq 0x2270
addq $0x8, %r14
movq %r14, %rdi
leaq -0x170(%rbp), %r14
movq %r14, %rsi
callq 0x2130
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0x6ab2
movq -0x48(%rbp), %rsi
incq %rsi
jmp 0x5f30
xorps %xmm0, %xmm0
leaq -0x130(%rbp), %rdx
andq $0x0, 0x10(%rdx)
leaq -0xd0(%rbp), %rsi
andq $0x0, 0x10(%rsi)
movaps %xmm0, (%rdx)
movaps %xmm0, (%rsi)
leaq -0xa0(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb $0x0, (%rdx)
xorl %r14d, %r14d
leaq -0x2b0(%rbp), %r13
leaq -0xb0(%rbp), %r12
movq %rdx, -0x58(%rbp)
movq -0x30(%rbp), %r15
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x6735
movq (%rax,%r14,8), %rsi
addq $0x60, %rsi
movq %r13, %rdi
callq 0x6bdc
leaq -0x130(%rbp), %rdi
movq %r13, %rsi
callq 0x8ee2
movq %r13, %rdi
callq 0x7ed2
movq (%r15), %rax
movq (%rax,%r14,8), %rsi
addq $0x78, %rsi
movq %r13, %rdi
callq 0x6bdc
leaq -0xd0(%rbp), %rdi
movq %r13, %rsi
callq 0x8ee2
movq %r13, %rdi
callq 0x7ed2
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %esi, %esi
xorl %edx, %edx
movq -0x58(%rbp), %r11
cmpq %rsi, %rcx
je 0x6597
movl %esi, %edi
testl %edx, %edx
je 0x6572
movl %r11d, %edi
movq (%rax,%rsi,8), %r8
movl 0x4c(%r8), %r8d
movq (%r15), %r9
movq (%r9,%r14,8), %r9
xorl %r10d, %r10d
cmpl (%r9), %r8d
sete %r10b
cmovel %edi, %r11d
addl %r10d, %edx
incq %rsi
jmp 0x6564
movq %r14, -0x68(%rbp)
movl %edx, %eax
addl %r11d, %eax
leal (%rdx,%r11), %ecx
decl %ecx
movslq %ecx, %rcx
movq %rcx, -0x70(%rbp)
cltq
movq %rax, -0x60(%rbp)
xorl %r14d, %r14d
movq %r11, -0x58(%rbp)
movq -0xd0(%rbp), %rax
movq -0xc8(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r14, %rcx
jbe 0x6624
movq (%rax,%r14,8), %rax
movq (%r15), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl (%rcx), %ecx
incl %ecx
cmpl %ecx, (%rax)
jne 0x661b
movq (%rbx), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2cc8
movq (%rbx), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x2c76
incq %r14
movq -0x58(%rbp), %r11
jmp 0x65ba
movslq %r11d, %r14
movq %r14, %r15
cmpq -0x70(%rbp), %r15
jge 0x6714
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
movq 0x8(%rax,%r15,8), %rsi
callq 0x2cc8
movq (%rbx), %rax
movq (%rax,%r15,8), %rsi
movq 0x8(%rax,%r15,8), %rdi
incq %r15
callq 0x2c76
jmp 0x662a
movq (%rbx), %rax
movq (%rax,%r14,8), %rax
movq 0x58(%rax), %rsi
testq %rsi, %rsi
je 0x6711
addq $0x28, %rsi
movq %r13, %rdi
callq 0x2270
leaq -0x90(%rbp), %rdi
movq %r13, %rsi
callq 0x2220
movq %r13, %rdi
callq 0x2100
xorl %r15d, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x6711
movq (%rax,%r15,8), %rsi
addq $0x8, %rsi
movq %r13, %rdi
callq 0x2270
movq %r12, %rdi
movq %r13, %rsi
callq 0x2220
movq %r13, %rdi
callq 0x2100
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x23a0
cmpq $-0x1, %rax
je 0x670c
cmpq $0x0, -0xa8(%rbp)
je 0x670c
movq (%rbx), %rax
movq (%rax,%r14,8), %rdi
movq (%rax,%r15,8), %rsi
callq 0x2cc8
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
movq (%rax,%r14,8), %rsi
callq 0x2c76
incq %r15
jmp 0x6695
incq %r14
cmpq -0x60(%rbp), %r14
jl 0x665b
movq -0x68(%rbp), %r14
incq %r14
movq -0x30(%rbp), %r15
movq (%r15), %rax
movq 0x8(%r15), %rcx
jmp 0x64ed
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x7ed2
leaq -0x130(%rbp), %rdi
callq 0x7ed2
leaq -0x110(%rbp), %rdi
callq 0x2100
leaq -0x90(%rbp), %rdi
callq 0x2100
leaq -0x150(%rbp), %rdi
callq 0x2100
leaq -0xf0(%rbp), %rdi
callq 0x7ed2
movq %rbx, %rax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x68c9
movq %rax, %r14
leaq -0x250(%rbp), %rdi
jmp 0x683f
jmp 0x6846
jmp 0x689a
movq %rax, %r14
leaq -0x1b0(%rbp), %rdi
jmp 0x685e
movq %rax, %r14
leaq -0x170(%rbp), %rdi
jmp 0x685e
movq %rax, %r14
leaq -0x230(%rbp), %rdi
jmp 0x683f
jmp 0x6846
jmp 0x689a
movq %rax, %r14
leaq -0x190(%rbp), %rdi
jmp 0x685e
jmp 0x6871
jmp 0x6871
jmp 0x689a
jmp 0x689a
jmp 0x689a
movq %rax, %r14
leaq -0x210(%rbp), %rdi
jmp 0x685e
movq %rax, %r14
leaq -0x290(%rbp), %rdi
jmp 0x683f
jmp 0x6846
movq %rax, %r14
leaq -0x1d0(%rbp), %rdi
jmp 0x685e
movq %rax, %r14
leaq -0x270(%rbp), %rdi
callq 0x2100
jmp 0x6849
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
jmp 0x685e
jmp 0x689a
movq %rax, %r14
leaq -0x1f0(%rbp), %rdi
callq 0x2100
jmp 0x689d
jmp 0x6871
jmp 0x6871
jmp 0x689a
jmp 0x689a
jmp 0x6871
jmp 0x6871
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x7ed2
leaq -0x130(%rbp), %rdi
callq 0x7ed2
jmp 0x689d
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0x2100
leaq -0x90(%rbp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x7ed2
leaq -0x150(%rbp), %rdi
callq 0x2100
leaq -0xf0(%rbp), %rdi
callq 0x7ed2
movq %r14, %rdi
callq 0x2340
nop