// File: /workspace/github_cpp_makefile_star2_O2/Windfisch[P]production-flow/factory.cpp
// Function: Factory::simulate_debug(Factory::FactoryConfiguration const&) const
void Factory::simulate_debug(const FactoryConfiguration& conf) const
{
	FlowGraph flowgraphs[MAX_ITEM];
	for (int i = 0; i < MAX_ITEM; i++)
	{
		flowgraphs[i] = build_flowgraph(item_t(i), conf);
		flowgraphs[i].calculate();
	}

	cout << "digraph \"factory\" {" << endl;

	for (size_t i = 0; i < facilities.size(); i++)
	{
		bool unsatisfied = false;

		cout << "\t" << i << " [label=\"";
		for (item_t item : facilities[i].items)
		{
			const auto& node = flowgraphs[item].nodes[facility_toposort_inv[item][i]];
			// if it's a consumer which is getting not enough input
			if (node.max_production < 0 && -node.actual_production < -node.max_production)
				unsatisfied = true;

			if (node.max_production != 0)
				cout << item_name.at(item) << ":" << node.actual_production << "/" << node.max_production << ", ";
		}
		cout << "\"";

		if (unsatisfied)
			cout << ", color=red";

		cout << "];" << endl;
	}

	cout << endl;

	for (size_t i = 0; i < transport_lines.size(); i++)
	{
		const auto& tl = transport_lines[i];
		const auto& edge = flowgraphs[tl.item_type].edges[edge_table_per_item_inv[tl.item_type][i]];
		cout << "\t" << tl.from << " -> " << tl.to << " [label=\"" << item_name.at(tl.item_type) << ": " << edge.actual_flow << "/" << edge.capacity << "\"];"<<endl;
	}
	cout << "}" << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x50(%rsp), %r15
xorl %r12d, %r12d
movl $0x210, %edx            # imm = 0x210
movq %r15, %rdi
xorl %esi, %esi
callq 0x3140
leaq 0x20(%rsp), %r13
cmpq $0xb, %r12
je 0x555e
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movq %r14, %rcx
callq 0x5248
movq %r15, %rdi
movq %r13, %rsi
callq 0x5d10
movq %r13, %rdi
callq 0x5cfa
movq %r15, %rdi
callq 0x7726
incq %r12
addq $0x30, %r15
jmp 0x5523
movq 0xfa63(%rip), %rdi      # 0x14fc8
leaq 0x7e5a(%rip), %rsi      # 0xd3c6
callq 0x3200
movq %rax, %rdi
callq 0x3110
xorl %r14d, %r14d
movq %rbx, 0x8(%rsp)
movq 0x8(%rbx), %rax
subq (%rbx), %rax
cqto
pushq $0x50
popq %rcx
idivq %rcx
cmpq %rax, %r14
jae 0x5702
movq 0xfa28(%rip), %rdi      # 0x14fc8
leaq 0x7e33(%rip), %rsi      # 0xd3da
callq 0x3200
movq %rax, %rdi
movq %r14, %rsi
callq 0x3180
movq %rax, %rdi
leaq 0x7e1b(%rip), %rsi      # 0xd3dc
callq 0x3200
movq (%rbx), %rax
imulq $0x50, %r14, %rcx
addq %rcx, %rax
addq $0x28, %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rax), %r12
xorl %r13d, %r13d
movq %r14, 0x10(%rsp)
cmpq 0x18(%rsp), %r12
je 0x56b3
movslq 0x20(%r12), %rax
movl %eax, 0x20(%rsp)
imulq $0x30, %rax, %rcx
movq 0x48(%rbx), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
movq (%rax,%r14,8), %rbp
movq 0x50(%rsp,%rcx), %r14
shlq $0x6, %rbp
movl (%r14,%rbp), %eax
testl %eax, %eax
sets %r15b
cmpl 0x4(%r14,%rbp), %eax
setl %bl
testl %eax, %eax
je 0x5693
leaq 0xfc25(%rip), %rdi      # 0x15258
leaq 0x20(%rsp), %rsi
callq 0x5d3a
movq 0xf984(%rip), %rdi      # 0x14fc8
movq %rax, %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x8205(%rip), %rsi      # 0xd85b
callq 0x3200
addq %rbp, %r14
movl 0x4(%r14), %esi
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
leaq 0x7d72(%rip), %rsi      # 0xd3e6
callq 0x3200
movl (%r14), %esi
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
leaq 0x7f63(%rip), %rsi      # 0xd5f1
callq 0x3200
andb %bl, %r15b
orb %r15b, %r13b
movq %r12, %rdi
callq 0x3250
movq %rax, %r12
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r14
jmp 0x55e5
movq 0xf90e(%rip), %rdi      # 0x14fc8
leaq 0x7f40(%rip), %rsi      # 0xd601
callq 0x3200
testb $0x1, %r13b
je 0x56df
movq 0xf8f5(%rip), %rdi      # 0x14fc8
leaq 0x7d0e(%rip), %rsi      # 0xd3e8
callq 0x3200
movq 0xf8e2(%rip), %rdi      # 0x14fc8
leaq 0x7d0d(%rip), %rsi      # 0xd3fa
callq 0x3200
movq %rax, %rdi
callq 0x3110
incq %r14
jmp 0x5581
movq 0xf8bf(%rip), %rdi      # 0x14fc8
callq 0x3110
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x18(%rbx), %r13
movq 0x20(%rbx), %rax
subq %r13, %rax
cqto
pushq $0x30
popq %rcx
idivq %rcx
cmpq %rax, %r15
jae 0x5814
movslq (%r13,%r14), %rax
imulq $0x30, %rax, %rcx
movq 0x78(%rbx), %rdx
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rax
imulq $0xc, (%rax,%r15,8), %r12
addq 0x68(%rsp,%rcx), %r12
movq 0xf872(%rip), %rdi      # 0x14fc8
leaq 0x7c7d(%rip), %rsi      # 0xd3da
callq 0x3200
movq 0x8(%r13,%r14), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
leaq 0x7c7b(%rip), %rsi      # 0xd3f4
callq 0x3200
movq 0x10(%r13,%r14), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
leaq 0x7c47(%rip), %rsi      # 0xd3dc
callq 0x3200
movq %rax, %rbp
addq %r14, %r13
leaq 0xfab1(%rip), %rdi      # 0x15258
movq %r13, %rsi
callq 0x5d3a
movq %rbp, %rdi
movq %rax, %rsi
callq 0x31f0
movq %rax, %rdi
leaq 0x7890(%rip), %rsi      # 0xd054
callq 0x3200
movl 0x8(%r12), %esi
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
leaq 0x7c06(%rip), %rsi      # 0xd3e6
callq 0x3200
movl (%r12), %esi
movq %rax, %rdi
callq 0x33b0
movq %rax, %rdi
leaq 0x7bfe(%rip), %rsi      # 0xd3f9
callq 0x3200
movq %rax, %rdi
callq 0x3110
incq %r15
addq $0x30, %r14
jmp 0x5714
movq 0xf7ad(%rip), %rdi      # 0x14fc8
leaq 0x7bdb(%rip), %rsi      # 0xd3fd
callq 0x3200
movq %rax, %rdi
callq 0x3110
movl $0x1e0, %ebx            # imm = 0x1E0
leaq (%rsp,%rbx), %rdi
addq $0x50, %rdi
callq 0x5cfa
addq $-0x30, %rbx
cmpq $-0x30, %rbx
jne 0x5834
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5867
jmp 0x5867
jmp 0x5867
jmp 0x5867
jmp 0x5867
movq %rax, %rbx
movl $0x1e0, %r14d           # imm = 0x1E0
leaq (%rsp,%r14), %rdi
addq $0x50, %rdi
callq 0x5cfa
addq $-0x30, %r14
cmpq $-0x30, %r14
jne 0x5870
movq %rbx, %rdi
callq 0x33c0
nop