// File: 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
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x220(%rbp), %rax
movq %rax, %rcx
addq $0x210, %rcx            # imm = 0x210
movq %rcx, -0x2c8(%rbp)
movq %rax, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0xa700
movq -0x2d8(%rbp), %rax
movq -0x2c8(%rbp), %rcx
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, -0x2c0(%rbp)
jne 0x8fdd
movl $0x0, -0x224(%rbp)
cmpl $0xb, -0x224(%rbp)
jge 0x90e0
movq -0x2d0(%rbp), %rsi
movl -0x224(%rbp), %edx
movq -0x10(%rbp), %rcx
leaq -0x258(%rbp), %rdi
callq 0x8ad0
jmp 0x9044
movslq -0x224(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x220(%rbp,%rax), %rdi
leaq -0x258(%rbp), %rsi
movq %rsi, -0x2e0(%rbp)
callq 0xac80
movq -0x2e0(%rbp), %rdi
callq 0xac50
movslq -0x224(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x135d0
jmp 0x9098
jmp 0x909a
movl -0x224(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x224(%rbp)
jmp 0x9018
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x260(%rbp)
movl %eax, -0x264(%rbp)
leaq -0x220(%rbp), %rax
movq %rax, -0x2f0(%rbp)
addq $0x210, %rax            # imm = 0x210
movq %rax, -0x2e8(%rbp)
jmp 0x96d3
movq 0x2fee1(%rip), %rdi     # 0x38fc8
leaq 0x1c2dd(%rip), %rsi     # 0x253cb
callq 0x3290
movq %rax, -0x2f8(%rbp)
jmp 0x90fc
movq -0x2f8(%rbp), %rdi
movq 0x2fe96(%rip), %rsi     # 0x38fa0
callq 0x32f0
jmp 0x9111
movq $0x0, -0x270(%rbp)
movq -0x2d0(%rbp), %rdi
movq -0x270(%rbp), %rax
movq %rax, -0x300(%rbp)
callq 0x5710
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
jae 0x93fd
movb $0x0, -0x271(%rbp)
movq 0x2fe71(%rip), %rdi     # 0x38fc8
leaq 0x1c281(%rip), %rsi     # 0x253df
callq 0x3290
movq %rax, -0x308(%rbp)
jmp 0x916c
movq -0x308(%rbp), %rdi
movq -0x270(%rbp), %rsi
callq 0x30a0
movq %rax, -0x310(%rbp)
jmp 0x9188
movq -0x310(%rbp), %rdi
leaq 0x1c24b(%rip), %rsi     # 0x253e1
callq 0x3290
jmp 0x919d
movq -0x2d0(%rbp), %rdi
movq -0x270(%rbp), %rsi
callq 0x9bf0
addq $0x20, %rax
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rdi
callq 0xacc0
movq %rax, -0x288(%rbp)
movq -0x280(%rbp), %rdi
callq 0x9c70
movq %rax, -0x290(%rbp)
leaq -0x288(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x9c10
testb $0x1, %al
jne 0x91fd
jmp 0x937e
leaq -0x288(%rbp), %rdi
callq 0xacf0
movq -0x2d0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x294(%rbp)
movslq -0x294(%rbp), %rcx
leaq -0x220(%rbp), %rax
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x318(%rbp)
addq $0x48, %rdi
movslq -0x294(%rbp), %rsi
callq 0xa6e0
movq %rax, %rdi
movq -0x270(%rbp), %rsi
callq 0xa990
movq -0x318(%rbp), %rdi
movq (%rax), %rsi
callq 0xabe0
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x9297
movq -0x2a0(%rbp), %rcx
xorl %eax, %eax
subl 0x4(%rcx), %eax
movq -0x2a0(%rbp), %rdx
xorl %ecx, %ecx
subl (%rdx), %ecx
cmpl %ecx, %eax
jge 0x9297
movb $0x1, -0x271(%rbp)
movq -0x2a0(%rbp), %rax
cmpl $0x0, (%rax)
je 0x936b
leaq 0x30062(%rip), %rdi     # 0x39310
leaq -0x294(%rbp), %rsi
callq 0xad10
movq %rax, -0x320(%rbp)
jmp 0x92c3
movq -0x320(%rbp), %rsi
movq 0x2fcf7(%rip), %rdi     # 0x38fc8
callq 0x3280
movq %rax, -0x328(%rbp)
jmp 0x92df
movq -0x328(%rbp), %rdi
leaq 0x1c56e(%rip), %rsi     # 0x2585b
callq 0x3290
movq %rax, -0x330(%rbp)
jmp 0x92fb
movq -0x330(%rbp), %rdi
movq -0x2a0(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x34e0
movq %rax, -0x338(%rbp)
jmp 0x931a
movq -0x338(%rbp), %rdi
leaq 0x1c0c3(%rip), %rsi     # 0x253eb
callq 0x3290
movq %rax, -0x340(%rbp)
jmp 0x9336
movq -0x340(%rbp), %rdi
movq -0x2a0(%rbp), %rax
movl (%rax), %esi
callq 0x34e0
movq %rax, -0x348(%rbp)
jmp 0x9354
movq -0x348(%rbp), %rdi
leaq 0x1c28f(%rip), %rsi     # 0x255f1
callq 0x3290
jmp 0x9369
jmp 0x936b
jmp 0x936d
leaq -0x288(%rbp), %rdi
callq 0xadb0
jmp 0x91e1
movq 0x2fc43(%rip), %rdi     # 0x38fc8
leaq 0x1c275(%rip), %rsi     # 0x25601
callq 0x3290
jmp 0x9393
testb $0x1, -0x271(%rbp)
je 0x93b3
movq 0x2fc25(%rip), %rdi     # 0x38fc8
leaq 0x1c043(%rip), %rsi     # 0x253ed
callq 0x3290
jmp 0x93b1
jmp 0x93b3
movq 0x2fc0e(%rip), %rdi     # 0x38fc8
leaq 0x1c03e(%rip), %rsi     # 0x253ff
callq 0x3290
movq %rax, -0x350(%rbp)
jmp 0x93cf
movq -0x350(%rbp), %rdi
movq 0x2fbc3(%rip), %rsi     # 0x38fa0
callq 0x32f0
jmp 0x93e4
jmp 0x93e6
movq -0x270(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x270(%rbp)
jmp 0x911c
movq 0x2fbc4(%rip), %rdi     # 0x38fc8
movq 0x2fb95(%rip), %rsi     # 0x38fa0
callq 0x32f0
jmp 0x9412
movq $0x0, -0x2a8(%rbp)
movq -0x2d0(%rbp), %rdi
movq -0x2a8(%rbp), %rax
movq %rax, -0x358(%rbp)
addq $0x18, %rdi
callq 0x5770
movq %rax, %rcx
movq -0x358(%rbp), %rax
cmpq %rcx, %rax
jae 0x964d
movq -0x2d0(%rbp), %rdi
addq $0x18, %rdi
movq -0x2a8(%rbp), %rsi
callq 0xab20
movq -0x2d0(%rbp), %rdi
movq %rax, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rax
movslq (%rax), %rsi
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
leaq -0x208(%rbp,%rax), %rax
movq %rax, -0x368(%rbp)
addq $0x78, %rdi
callq 0xa6e0
movq %rax, %rdi
movq -0x2a8(%rbp), %rsi
callq 0xa990
movq -0x368(%rbp), %rdi
movq (%rax), %rsi
callq 0xac30
movq %rax, -0x2b8(%rbp)
movq 0x2faff(%rip), %rdi     # 0x38fc8
leaq 0x1bf0f(%rip), %rsi     # 0x253df
callq 0x3290
movq %rax, -0x360(%rbp)
jmp 0x94de
movq -0x360(%rbp), %rdi
movq -0x2b0(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x30a0
movq %rax, -0x370(%rbp)
jmp 0x94fe
movq -0x370(%rbp), %rdi
leaq 0x1beed(%rip), %rsi     # 0x253f9
callq 0x3290
movq %rax, -0x378(%rbp)
jmp 0x951a
movq -0x378(%rbp), %rdi
movq -0x2b0(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x30a0
movq %rax, -0x380(%rbp)
jmp 0x953a
movq -0x380(%rbp), %rdi
leaq 0x1be99(%rip), %rsi     # 0x253e1
callq 0x3290
movq %rax, -0x388(%rbp)
jmp 0x9556
movq -0x2b0(%rbp), %rsi
leaq 0x2fdac(%rip), %rdi     # 0x39310
callq 0xad10
movq %rax, -0x390(%rbp)
jmp 0x9572
movq -0x390(%rbp), %rsi
movq -0x388(%rbp), %rdi
callq 0x3280
movq %rax, -0x398(%rbp)
jmp 0x958e
movq -0x398(%rbp), %rdi
leaq 0x1bab8(%rip), %rsi     # 0x25054
callq 0x3290
movq %rax, -0x3a0(%rbp)
jmp 0x95aa
movq -0x3a0(%rbp), %rdi
movq -0x2b8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x34e0
movq %rax, -0x3a8(%rbp)
jmp 0x95c9
movq -0x3a8(%rbp), %rdi
leaq 0x1be14(%rip), %rsi     # 0x253eb
callq 0x3290
movq %rax, -0x3b0(%rbp)
jmp 0x95e5
movq -0x3b0(%rbp), %rdi
movq -0x2b8(%rbp), %rax
movl (%rax), %esi
callq 0x34e0
movq %rax, -0x3b8(%rbp)
jmp 0x9603
movq -0x3b8(%rbp), %rdi
leaq 0x1bded(%rip), %rsi     # 0x253fe
callq 0x3290
movq %rax, -0x3c0(%rbp)
jmp 0x961f
movq -0x3c0(%rbp), %rdi
movq 0x2f973(%rip), %rsi     # 0x38fa0
callq 0x32f0
jmp 0x9634
jmp 0x9636
movq -0x2a8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2a8(%rbp)
jmp 0x941d
movq 0x2f974(%rip), %rdi     # 0x38fc8
leaq 0x1bda7(%rip), %rsi     # 0x25402
callq 0x3290
movq %rax, -0x3c8(%rbp)
jmp 0x9669
movq -0x3c8(%rbp), %rdi
movq 0x2f929(%rip), %rsi     # 0x38fa0
callq 0x32f0
jmp 0x967e
leaq -0x220(%rbp), %rax
movq %rax, -0x3d8(%rbp)
addq $0x210, %rax            # imm = 0x210
movq %rax, -0x3d0(%rbp)
movq -0x3d0(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x3e0(%rbp)
callq 0xac50
movq -0x3d8(%rbp), %rcx
movq -0x3e0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x3d0(%rbp)
jne 0x9699
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
movq -0x2e8(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x3e8(%rbp)
callq 0xac50
movq -0x2f0(%rbp), %rcx
movq -0x3e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x2e8(%rbp)
jne 0x96d3
jmp 0x9706
movq -0x260(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)
nopl (%rax)