// File: /workspace/github_cpp_makefile_star2_O2/searsm8[P]FM_Partitioning/fmpart.cpp
// Function: readNetsFile()
void readNetsFile()
{	
	FILE *nets_file;			
	char cells_file_path[100];
	strcpy(cells_file_path, file_path);
	nets_file = fopen(strcat(cells_file_path, "design.nets"), "r");			
	if (nets_file == NULL) { fprintf(stderr, "Can't open nets_file!\n");	exit(1); }
	
	printf("Reading nets file...\n");	
			
	while(!feof(nets_file))
	{
		//read in the net name and number of pins
		NET* current_net;
		current_net = new NET;
			
		char net_name[100];
		fscanf(nets_file, "%*s %s %d", &net_name, &current_net->num_pins);
		if(feof(nets_file)) break;
		
		strcpy(current_net->name, net_name);
		current_net->cutstate = false; //assume not cut
		current_net->critical = false;									
	
		//read each cell in the net, add to net_list and cell_list per FM paper
		for(int c = 0; c < current_net->num_pins; c++)
		{
			char cell_name [100];
			char pin_name [100];	

			fscanf(nets_file, "%s %s", &cell_name, &pin_name);
						
			//avoid adding duplicates
			if(cells_map[cell_name]->net_list.empty() ||
			   cells_map[cell_name]->net_list.back() != current_net )
			{
				//add net to cell's net_list.				
				cells_map[cell_name]->net_list.push_back(current_net);

				//add the new cell to the net's cell_list
				current_net->cell_list.push_back(cells_map[cell_name]);	
			}					
		}
		
		nets.push_back(current_net);			
		fscanf(nets_file, "%*s"); //scan in the "endnet" line				
	}

	fclose(nets_file);
	printf("done!\n");
	return;			
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
leaq 0x5771(%rip), %rsi      # 0x8160
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
callq 0x2150
movq %rbx, %rdi
callq 0x20a0
movabsq $0x6e2e6e6769736564, %rcx # imm = 0x6E2E6E6769736564
movq %rcx, -0xe0(%rbp,%rax)
movl $0x737465, -0xd8(%rbp,%rax) # imm = 0x737465
leaq 0x2628(%rip), %rsi      # 0x5052
movq %rbx, %rdi
callq 0x21b0
testq %rax, %rax
je 0x2c4b
movq %rax, %r12
leaq 0x2987(%rip), %rdi      # 0x53cc
callq 0x2210
leaq -0x1c0(%rbp), %rbx
leaq -0x150(%rbp), %r13
leaq -0x78(%rbp), %r15
leaq 0x57c5(%rip), %r14      # 0x8228
movq %r12, %rdi
callq 0x2220
testl %eax, %eax
jne 0x2c25
movl $0x90, %edi
callq 0x2180
andq $0x0, 0x88(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x78(%rax)
movq %rax, -0x30(%rbp)
leaq 0x64(%rax), %rcx
movq %r12, %rdi
leaq 0x2643(%rip), %rsi      # 0x50e1
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2280
movq %r12, %rdi
callq 0x2220
testl %eax, %eax
jne 0x2c25
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x2150
movq -0x30(%rbp), %rax
andw $0x0, 0x68(%rax)
xorl %ecx, %ecx
movl %ecx, -0x38(%rbp)
cmpl 0x64(%rax), %ecx
jge 0x2bf8
movq %r12, %rdi
leaq 0x2587(%rip), %rsi      # 0x506c
movq %r13, %rdx
leaq -0x230(%rbp), %rcx
xorl %eax, %eax
callq 0x2280
movq %r15, %rdi
movq %r13, %rsi
leaq -0x32(%rbp), %rdx
callq 0x3722
movq %r14, %rdi
movq %r15, %rsi
callq 0x3856
movq (%rax), %rax
movq 0x98(%rax), %rcx
cmpq 0xa0(%rax), %rcx
je 0x2b77
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
leaq -0x31(%rbp), %rdx
callq 0x3722
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3856
movq %rbx, %rdi
movq (%rax), %rax
movq 0xa0(%rax), %rax
movq -0x8(%rax), %rbx
movq %r12, %r13
movq -0x30(%rbp), %r12
callq 0x20b0
movq %r15, %rdi
callq 0x20b0
cmpq %r12, %rbx
movq %r13, %r12
leaq -0x150(%rbp), %r13
jne 0x2b7f
jmp 0x2bea
movq %r15, %rdi
callq 0x20b0
movq %r15, %rdi
movq %r13, %rsi
leaq -0x58(%rbp), %rdx
callq 0x3722
movq %r14, %rdi
movq %r15, %rsi
callq 0x3856
movq (%rax), %rdi
movl $0x98, %eax
addq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x38c0
movq %r15, %rdi
callq 0x20b0
movq -0x30(%rbp), %rbx
movq %r15, %rdi
movq %r13, %rsi
leaq -0x58(%rbp), %rdx
callq 0x3722
movq %r14, %rdi
movq %r15, %rsi
callq 0x3856
addq $0x78, %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3832
movq %r15, %rdi
callq 0x20b0
movl -0x38(%rbp), %ecx
incl %ecx
movq -0x30(%rbp), %rax
jmp 0x2acf
leaq 0x5669(%rip), %rdi      # 0x8268
leaq -0x30(%rbp), %rsi
callq 0x38c0
movq %r12, %rdi
leaq 0x24d9(%rip), %rsi      # 0x50eb
xorl %eax, %eax
callq 0x2280
leaq -0x1c0(%rbp), %rbx
jmp 0x2a63
movq %r12, %rdi
callq 0x2170
leaq 0x27ad(%rip), %rdi      # 0x53e1
callq 0x2210
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5386(%rip), %rax      # 0x7fd8
movq (%rax), %rcx
leaq 0x246e(%rip), %rdi      # 0x50ca
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x2290
pushq $0x1
popq %rdi
callq 0x21c0
jmp 0x2c8c
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x20b0
jmp 0x2c8f
jmp 0x2c83
jmp 0x2c83
movq %rax, %rbx
jmp 0x2c98
jmp 0x2c8c
jmp 0x2c8c
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2250