// File: 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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x23d0
movq -0xf8(%rbp), %rdx
leaq 0x5247(%rip), %rsi      # 0xb08f
leaq -0x30(%rbp), %rdi
callq 0x34f0
jmp 0x5e53
movq -0x100(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5c30
movl %eax, -0x104(%rbp)
jmp 0x5e6b
leaq -0x30(%rbp), %rdi
callq 0x2170
leaq -0x31(%rbp), %rdi
callq 0x2280
movl -0x104(%rbp), %eax
movl %eax, -0xc(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x23d0
movq -0x110(%rbp), %rdx
leaq 0x51f1(%rip), %rsi      # 0xb095
leaq -0x68(%rbp), %rdi
callq 0x34f0
jmp 0x5eaf
movq -0x100(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x5c30
movl %eax, -0x114(%rbp)
jmp 0x5ec7
leaq -0x68(%rbp), %rdi
callq 0x2170
leaq -0x69(%rbp), %rdi
callq 0x2280
movl -0x114(%rbp), %ecx
movq -0x100(%rbp), %rax
movl %ecx, -0x48(%rbp)
movl (%rax), %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, -0x78(%rbp)
movl (%rax), %eax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x100(%rbp), %rcx
movl -0x84(%rbp), %eax
cmpl (%rcx), %eax
jae 0x5ff5
movq -0x78(%rbp), %rax
movl -0x84(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movq -0x80(%rbp), %rax
movl -0x84(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x5f4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5fb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2170
leaq -0x31(%rbp), %rdi
callq 0x2280
jmp 0x639e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5fe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2170
leaq -0x69(%rbp), %rdi
callq 0x2280
jmp 0x639e
movq -0x100(%rbp), %rdi
addq $0x90, %rdi
callq 0x33b0
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x33e0
movq -0x100(%rbp), %rdi
addq $0x90, %rdi
callq 0x3460
movq %rax, -0xa0(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3420
testb $0x1, %al
jne 0x6058
jmp 0x629e
leaq -0x90(%rbp), %rdi
callq 0x3490
movl 0x4(%rax), %eax
cmpl -0xc(%rbp), %eax
je 0x6282
leaq -0x90(%rbp), %rdi
callq 0x3490
movl 0x4(%rax), %eax
cmpl -0x48(%rbp), %eax
je 0x6282
leaq -0x90(%rbp), %rdi
callq 0x3490
movl 0x4(%rax), %eax
movl %eax, -0x70(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3490
movq %rax, %rdi
addq $0x10, %rdi
callq 0x6730
movq %rax, -0xa8(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3490
movq %rax, %rdi
addq $0x10, %rdi
callq 0x6790
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x6760
testb $0x1, %al
jne 0x60f4
jmp 0x6280
movq -0x100(%rbp), %rax
addq $0xa8, %rax
movq %rax, -0x120(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x67e0
movq -0x120(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x67c0
movq %rax, %rdi
addq $0x10, %rdi
callq 0x6810
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x6840
movq -0x100(%rbp), %rax
addq $0xa8, %rax
movq %rax, -0x128(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x67e0
movq -0x128(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x67c0
movq %rax, %rdi
addq $0x10, %rdi
callq 0x6860
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x6840
leaq -0xb8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6760
testb $0x1, %al
jne 0x61bc
jmp 0x6264
movq -0x100(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x130(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x67e0
movq -0x130(%rbp), %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x6890
movl 0x4(%rax), %eax
cmpl -0x70(%rbp), %eax
jne 0x6248
movq -0x80(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3490
movq %rax, %rcx
movq -0x140(%rbp), %rax
movl (%rcx), %ecx
movl $0x1, (%rax,%rcx,4)
movq -0x78(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x67e0
movq %rax, %rcx
movq -0x138(%rbp), %rax
movl (%rcx), %ecx
movl $0x1, (%rax,%rcx,4)
jmp 0x624a
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
callq 0x68b0
movq %rax, -0xd8(%rbp)
jmp 0x614a
jmp 0x6266
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
callq 0x68b0
movq %rax, -0xe0(%rbp)
jmp 0x60b9
jmp 0x6282
jmp 0x6284
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
callq 0x34b0
movq %rax, -0xe8(%rbp)
jmp 0x6022
movl $0x0, -0xec(%rbp)
movq -0x100(%rbp), %rcx
movl -0xec(%rbp), %eax
cmpl (%rcx), %eax
jae 0x6359
movq -0x80(%rbp), %rax
movl -0xec(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jne 0x6300
movq -0x100(%rbp), %rdi
addq $0x90, %rdi
movl -0xec(%rbp), %eax
movl %eax, %esi
callq 0x6890
movq %rax, %rcx
movq -0x100(%rbp), %rax
movl 0x4(%rcx), %ecx
movl 0x44(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x44(%rax,%rcx,4)
movq -0x78(%rbp), %rax
movl -0xec(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jne 0x6343
movq -0x100(%rbp), %rdi
addq $0x90, %rdi
movl -0xec(%rbp), %eax
movl %eax, %esi
callq 0x6890
movq %rax, %rcx
movq -0x100(%rbp), %rax
movl 0x4(%rcx), %ecx
movl 0x68(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x68(%rax,%rcx,4)
jmp 0x6345
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x62a8
movq -0x78(%rbp), %rax
movq %rax, -0x148(%rbp)
cmpq $0x0, %rax
je 0x6376
movq -0x148(%rbp), %rdi
callq 0x2300
movq -0x80(%rbp), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, %rax
je 0x6393
movq -0x150(%rbp), %rdi
callq 0x2300
xorl %eax, %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x23c0
nopw (%rax,%rax)