// File: mxy161610207[P]codesim/src/MyPaser.cpp
// Function: MyPaser::MaxFlow(MyPaser::Program&, MyPaser::Program&)
double MyPaser::MaxFlow(Program& A, Program& B) {
	int na = A.funcName_.size();
	int nb = B.funcName_.size();
	int N = na + nb + 2;
	
	Graph G;

	G.init(N);
	for (int i = 0; i < na; i++) {
		for (int j = 0; j < nb; j++) {
			vector<string>& a_op = A.functOp_[A.funcName_[i]];
			vector<string>& b_op = B.functOp_[B.funcName_[j]];
			int w = FuncCompare(a_op, b_op);
			G.addedge(i + 1, j + na + 1, w, 0);
			//cout << i + 1 << " " << j + na + 1 << " " << w << endl;
		}
	}
	int st = 0;
	int ed = na + nb + 1;

	int fa = 0;

	for (int i = 0; i < na; i++) {
		G.addedge(st, i + 1, A.functOp_[A.funcName_[i]].size(), 0);
		fa += A.functOp_[A.funcName_[i]].size();
	}
	for (int i = 0; i < nb; i++) {
		G.addedge(i + na + 1, ed, B.functOp_[B.funcName_[i]].size(), 0);
	}
	double cost = 0, flow = 0;
	flow = G.minCostMaxflow(st, ed, cost);
	//cout << cost << endl;
	cost = -cost;
	//TODO change MaxFlow to MaxCostMaxflow

	double ans = (double)flow / (double)fa;
	//cout << flow << "/" << fa << endl;
	return ans;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2741d0, %rsp         # imm = 0x2741D0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x45c0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x45c0
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %esi
leaq -0x274148(%rbp), %rdi
callq 0x49b0
movl $0x0, -0x27414c(%rbp)
movl -0x27414c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3d1f
movl $0x0, -0x274150(%rbp)
movl -0x274150(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3d09
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741a0(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x27414c(%rbp), %rsi
callq 0x48d0
movq -0x2741a0(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, -0x274158(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x274198(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x274150(%rbp), %rsi
callq 0x48d0
movq -0x274198(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, -0x274160(%rbp)
movq -0x274158(%rbp), %rdi
movq -0x274160(%rbp), %rsi
callq 0x34c0
movl %eax, -0x274164(%rbp)
movl -0x27414c(%rbp), %esi
addl $0x1, %esi
movl -0x274150(%rbp), %edx
addl -0x14(%rbp), %edx
addl $0x1, %edx
movl -0x274164(%rbp), %ecx
leaq -0x274148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x4a30
movl -0x274150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274150(%rbp)
jmp 0x3c39
jmp 0x3d0b
movl -0x27414c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27414c(%rbp)
jmp 0x3c20
movl $0x0, -0x274168(%rbp)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27416c(%rbp)
movl $0x0, -0x274170(%rbp)
movl $0x0, -0x274174(%rbp)
movl -0x274174(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3e26
movl -0x274168(%rbp), %eax
movl %eax, -0x2741b0(%rbp)
movl -0x274174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741ac(%rbp)
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741b8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x274174(%rbp), %rsi
callq 0x48d0
movq -0x2741b8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movl -0x2741b0(%rbp), %esi
movl -0x2741ac(%rbp), %edx
movl %eax, %ecx
leaq -0x274148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x4a30
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741a8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x274174(%rbp), %rsi
callq 0x48d0
movq -0x2741a8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movq %rax, %rcx
movslq -0x274170(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x274170(%rbp)
movl -0x274174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274174(%rbp)
jmp 0x3d4c
movl $0x0, -0x274178(%rbp)
movl -0x274178(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3ec4
movl -0x274178(%rbp), %eax
addl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741c0(%rbp)
movl -0x27416c(%rbp), %eax
movl %eax, -0x2741bc(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741c8(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x274178(%rbp), %rsi
callq 0x48d0
movq -0x2741c8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movl -0x2741c0(%rbp), %esi
movl -0x2741bc(%rbp), %edx
movl %eax, %ecx
leaq -0x274148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x4a30
movl -0x274178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274178(%rbp)
jmp 0x3e30
xorps %xmm0, %xmm0
movsd %xmm0, -0x274180(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x274188(%rbp)
movl -0x274168(%rbp), %esi
movl -0x27416c(%rbp), %edx
leaq -0x274148(%rbp), %rdi
leaq -0x274180(%rbp), %rcx
callq 0x4ba0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x274188(%rbp)
movsd -0x274180(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x274180(%rbp)
movsd -0x274188(%rbp), %xmm0
cvtsi2sdl -0x274170(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x274190(%rbp)
movsd -0x274190(%rbp), %xmm0
addq $0x2741d0, %rsp         # imm = 0x2741D0
popq %rbp
retq
nopl (%rax)