// File: /workspace/github_cpp_makefile_star2_O3/gauravtewari[P]netlist/netlist.cpp
// Function: circuit::update_same_faninout()
int circuit::update_same_faninout(){
	u32 input_type = get_gate_type("INPUT");
	u32 output_type = get_gate_type("OUTPUT");
	u32 gtype;
	u32 *fin = new u32[num_gates];
	u32 *fout = new u32[num_gates];
	for(u32 i=0; i<num_gates; i++){ fin[i]=0; fout[i]=0;}
	for(vector<struct gate>::const_iterator i = gate_list.begin(); i != gate_list.end(); i++){
		/* For each gate (except input and output gates )find the edges that are driven by this gate */
		if((i->type != input_type) && (i->type != output_type)){
			gtype = i->type;	/* Note the gate type for comparison */
			for(list<u32>::const_iterator j = i->nets.begin(); j != i->nets.end(); j++){ /* For each edge driven by this gate */
				/* For each edge find the gate it drives */
				for(list<u32>::const_iterator k = net_list[*j].gates.begin(); k != net_list[*j].gates.end(); k++){ /* For each gate driven by this edge */
					if(gate_list[*k].type == gtype){
						fout[i->id]=1;
						fin[*k]=1;
					}
					
				}
			}
		}
	}
	for(u32 i = 0; i < num_gates; i++){
		if(fout[i] == 1){
			same_fanout[gate_list[i].type]++;
		}
		if(fin[i] == 1){
			same_fanin[gate_list[i].type]++;
		}
	}
	delete []fin;
	delete []fout;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x13e1(%rip), %rsi      # 0x508a
leaq 0x13df(%rip), %rdx      # 0x508f
leaq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x2faa
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b76
movl %eax, 0xc(%rsp)
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x3ce3
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2210
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x139d(%rip), %rsi      # 0x5090
leaq 0x139c(%rip), %rdx      # 0x5096
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2faa
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b76
movl %eax, 0x8(%rsp)
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x3d2d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2210
movl (%rbx), %r13d
leaq (,%r13,4), %r12
movq %r12, %rdi
callq 0x2030
movq %rax, %r14
movq %r12, %rdi
callq 0x2030
movq %rax, %r15
testq %r13, %r13
je 0x3d6d
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2150
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2150
movq 0x90(%rbx), %rax
movq %rbx, 0x10(%rsp)
movq 0x98(%rbx), %rcx
cmpq %rcx, %rax
je 0x3dfe
movq 0x10(%rsp), %rdx
movq 0xa8(%rdx), %rdx
movl $0x1, %esi
movq %rax, %rdi
movl 0x4(%rdi), %r8d
cmpl 0xc(%rsp), %r8d
je 0x3df5
cmpl 0x8(%rsp), %r8d
je 0x3df5
leaq 0x10(%rdi), %r9
movq 0x10(%rdi), %r10
cmpq %r9, %r10
je 0x3df5
movl 0x10(%r10), %r11d
leaq (%r11,%r11,4), %r11
leaq (%rdx,%r11,8), %r11
addq $0x10, %r11
movq (%r11), %r12
cmpq %r11, %r12
je 0x3df0
movl 0x10(%r12), %ebx
leaq (%rbx,%rbx,4), %rbp
cmpl %r8d, 0x4(%rax,%rbp,8)
jne 0x3dea
movl (%rdi), %ebp
movl %esi, (%r15,%rbp,4)
movl %esi, (%r14,%rbx,4)
movq (%r12), %r12
jmp 0x3dcb
movq (%r10), %r10
jmp 0x3db3
addq $0x28, %rdi
cmpq %rcx, %rdi
jne 0x3d99
testq %r13, %r13
movq 0x10(%rsp), %rsi
je 0x3e34
addq $0x4, %rax
xorl %ecx, %ecx
cmpl $0x1, (%r15,%rcx,4)
jne 0x3e1b
movl (%rax), %edx
incl 0x44(%rsi,%rdx,4)
cmpl $0x1, (%r14,%rcx,4)
jne 0x3e28
movl (%rax), %edx
incl 0x68(%rsi,%rdx,4)
incq %rcx
addq $0x28, %rax
cmpq %rcx, %r13
jne 0x3e0e
movq %r14, %rdi
callq 0x2270
movq %r15, %rdi
callq 0x2270
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x3e67
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x3e77
movq (%r15), %rsi
incq %rsi
callq 0x2210
movq %rbx, %rdi
callq 0x2300
nop