// File: mxy161610207[P]codesim/src/MyPaser.cpp
// Function: MyPaser::MaxWeightFlow(MyPaser::Program&, MyPaser::Program&)
double MyPaser::MaxWeightFlow(Program& A, Program& B) {
	int na = A.funcName_.size();
	int nb = B.funcName_.size();
	int N = na + nb + 2;

	Graph G;

	double alpha = 2.0;
	double beta = 1.0 / 2.0;

	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 cap1 = FuncCompare(a_op, b_op);
			int cap2 = FuncCompare(b_op, a_op);
			double fac = (double)max(cap1, cap2) / (double)min(a_op.size(), b_op.size());
			double w = 1.0 / (1 + exp(-alpha * fac + beta));

			G.addedge(i + 1, j + na + 1, cap1, -w);
			//cout << i + 1 << " " << j + na + 1 << " " << cap1 << " " << -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);

	cost = -cost;
	//cout << "cost:" << cost << endl;

	double ans = (double)cost / (double)fa;
	ans = ans / 0.82;
	//cout << flow << "/" << fa << endl;
	return ans;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x274210, %rsp         # imm = 0x274210
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)
movsd 0x68e9(%rip), %xmm0     # 0xa008
movsd %xmm0, -0x274150(%rbp)
movsd 0x68e9(%rip), %xmm0     # 0xa018
movsd %xmm0, -0x274158(%rbp)
movl -0x1c(%rbp), %esi
leaq -0x274148(%rbp), %rdi
callq 0x49b0
movl $0x0, -0x27415c(%rbp)
movl -0x27415c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3970
movl $0x0, -0x274160(%rbp)
movl -0x274160(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x395a
movq -0x8(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x2741e0(%rbp)
movslq -0x27415c(%rbp), %rsi
callq 0x48d0
movq -0x2741e0(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, -0x274168(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, %rax
addq $0x18, %rax
movq %rax, -0x2741d8(%rbp)
movslq -0x274160(%rbp), %rsi
callq 0x48d0
movq -0x2741d8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, -0x274170(%rbp)
movq -0x274168(%rbp), %rdi
movq -0x274170(%rbp), %rsi
callq 0x34c0
movl %eax, -0x274174(%rbp)
movq -0x274170(%rbp), %rdi
movq -0x274168(%rbp), %rsi
callq 0x34c0
movl %eax, -0x274178(%rbp)
leaq -0x274174(%rbp), %rdi
leaq -0x274178(%rbp), %rsi
callq 0x48f0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0x2741d0(%rbp)
movq -0x274168(%rbp), %rdi
callq 0x45c0
movq %rax, -0x274188(%rbp)
movq -0x274170(%rbp), %rdi
callq 0x45c0
movq %rax, -0x274190(%rbp)
leaq -0x274188(%rbp), %rdi
leaq -0x274190(%rbp), %rsi
callq 0x49f0
movsd -0x2741d0(%rbp), %xmm0
movq (%rax), %xmm1
movaps 0x67c3(%rip), %xmm2     # 0xa040
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x67c7(%rip), %xmm2     # 0xa050
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x274180(%rbp)
movsd -0x274150(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd -0x274180(%rbp), %xmm2
movsd -0x274158(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x2410
movsd 0x6740(%rip), %xmm1     # 0xa028
addsd %xmm0, %xmm1
movsd 0x6734(%rip), %xmm0     # 0xa028
divsd %xmm1, %xmm0
movsd %xmm0, -0x274198(%rbp)
movl -0x27415c(%rbp), %esi
addl $0x1, %esi
movl -0x274160(%rbp), %edx
addl -0x14(%rbp), %edx
addl $0x1, %edx
movl -0x274174(%rbp), %ecx
movsd -0x274198(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
xorq %rdi, %rax
movq %rax, %xmm0
leaq -0x274148(%rbp), %rdi
callq 0x4a30
movl -0x274160(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274160(%rbp)
jmp 0x3769
jmp 0x395c
movl -0x27415c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x27415c(%rbp)
jmp 0x3750
movl $0x0, -0x27419c(%rbp)
movl -0x14(%rbp), %eax
addl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741a0(%rbp)
movl $0x0, -0x2741a4(%rbp)
movl $0x0, -0x2741a8(%rbp)
movl -0x2741a8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3a77
movl -0x27419c(%rbp), %eax
movl %eax, -0x2741f0(%rbp)
movl -0x2741a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741ec(%rbp)
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741f8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x2741a8(%rbp), %rsi
callq 0x48d0
movq -0x2741f8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movl -0x2741f0(%rbp), %esi
movl -0x2741ec(%rbp), %edx
movl %eax, %ecx
leaq -0x274148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x4a30
movq -0x8(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x2741e8(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x2741a8(%rbp), %rsi
callq 0x48d0
movq -0x2741e8(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movq %rax, %rcx
movslq -0x2741a4(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x2741a4(%rbp)
movl -0x2741a8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741a8(%rbp)
jmp 0x399d
movl $0x0, -0x2741ac(%rbp)
movl -0x2741ac(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3b15
movl -0x2741ac(%rbp), %eax
addl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x274200(%rbp)
movl -0x2741a0(%rbp), %eax
movl %eax, -0x2741fc(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x274208(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x2741ac(%rbp), %rsi
callq 0x48d0
movq -0x274208(%rbp), %rdi
movq %rax, %rsi
callq 0x4760
movq %rax, %rdi
callq 0x45c0
movl -0x274200(%rbp), %esi
movl -0x2741fc(%rbp), %edx
movl %eax, %ecx
leaq -0x274148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x4a30
movl -0x2741ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2741ac(%rbp)
jmp 0x3a81
xorps %xmm0, %xmm0
movsd %xmm0, -0x2741b8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x2741c0(%rbp)
movl -0x27419c(%rbp), %esi
movl -0x2741a0(%rbp), %edx
leaq -0x274148(%rbp), %rdi
leaq -0x2741b8(%rbp), %rcx
callq 0x4ba0
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x2741c0(%rbp)
movsd -0x2741b8(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x2741b8(%rbp)
movsd -0x2741b8(%rbp), %xmm0
cvtsi2sdl -0x2741a4(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x2741c8(%rbp)
movsd -0x2741c8(%rbp), %xmm0
movsd 0x6477(%rip), %xmm1     # 0xa020
divsd %xmm1, %xmm0
movsd %xmm0, -0x2741c8(%rbp)
movsd -0x2741c8(%rbp), %xmm0
addq $0x274210, %rsp         # imm = 0x274210
popq %rbp
retq
nopw %cs:(%rax,%rax)