// File: /workspace/github_cpp_makefile_star2_O1/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 $0x278, %rsp            # imm = 0x278
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x60(%rsp), %r15
xorl %r12d, %r12d
movl $0x210, %edx            # imm = 0x210
movq %r15, %rdi
xorl %esi, %esi
callq 0x3150
leaq 0x30(%rsp), %rbp
leaq 0x10(%rsp), %r13
movq %rbp, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movq %r14, %rcx
callq 0x588a
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r15), %rax
movups 0x8(%r15), %xmm0
movq 0x30(%rsp), %rcx
movq %rcx, (%r15)
movq 0x38(%rsp), %rcx
movq %rcx, 0x8(%r15)
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%r15)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq %rax, 0x10(%rsp)
movups %xmm0, 0x18(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, 0x40(%rsp)
movq %r13, %rdi
callq 0x6742
leaq 0x18(%r15), %rdi
leaq 0x48(%rsp), %rsi
callq 0x67bc
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x5c2d
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbp, %rdi
callq 0x6742
movq %r15, %rdi
callq 0x7c4c
incq %r12
addq $0x30, %r15
cmpq $0xb, %r12
jne 0x5b94
movq 0xf37b(%rip), %r14      # 0x14fd0
leaq 0x9763(%rip), %rsi      # 0xf3bf
movl $0x13, %edx
movq %r14, %rdi
callq 0x3290
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf349(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
movq %rbx, 0x8(%rsp)
je 0x5ea7
movq $0x0, (%rsp)
movl $0x1, %edx
movq 0xf316(%rip), %rdi      # 0x14fd0
leaq 0x9712(%rip), %rsi      # 0xf3d3
callq 0x3290
movq 0xf303(%rip), %rdi      # 0x14fd0
movq (%rsp), %rsi
callq 0x3190
movl $0x9, %edx
movq %rax, %rdi
leaq 0x96f0(%rip), %rsi      # 0xf3d5
callq 0x3290
movq (%rbx), %rax
movq (%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rbx
addq $0x28, %rbx
movq 0x10(%rbx), %r12
xorl %ebp, %ebp
cmpq %rbx, %r12
je 0x5df5
movslq 0x20(%r12), %rax
movl %eax, 0x30(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x8(%rsp), %rcx
movq 0x48(%rcx), %rcx
movq (%rcx,%rax,8), %rcx
shlq $0x4, %rax
movq (%rsp), %rdx
movq (%rcx,%rdx,8), %r15
movq 0x60(%rsp,%rax), %r14
shlq $0x6, %r15
movl (%r14,%r15), %eax
cmpl 0x4(%r14,%r15), %eax
movzbl %bpl, %ecx
movl %ecx, %ebp
movl $0x1, %edx
cmovll %edx, %ebp
testl %eax, %eax
cmovnsl %ecx, %ebp
je 0x5de1
leaq 0xf508(%rip), %rdi      # 0x15270
leaq 0x30(%rsp), %rsi
callq 0x6610
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0xf250(%rip), %rdi      # 0x14fd0
callq 0x3290
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9aa7(%rip), %rsi      # 0xf83e
callq 0x3290
addq %r15, %r14
movl 0x4(%r14), %esi
movq %r13, %rdi
callq 0x33f0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9622(%rip), %rsi      # 0xf3df
callq 0x3290
movl (%r14), %esi
movq %r13, %rdi
callq 0x33f0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x97fd(%rip), %rsi      # 0xf5d9
callq 0x3290
movq %r12, %rdi
callq 0x32a0
movq %rax, %r12
cmpq %rbx, %rax
jne 0x5d10
movl $0x1, %edx
movq 0xf1cf(%rip), %rdi      # 0x14fd0
leaq 0x97dc(%rip), %rsi      # 0xf5e4
callq 0x3290
movq 0x8(%rsp), %rbx
testb $0x1, %bpl
je 0x5e30
movl $0xb, %edx
movq 0xf1ac(%rip), %rdi      # 0x14fd0
leaq 0x95b6(%rip), %rsi      # 0xf3e1
callq 0x3290
movl $0x2, %edx
movq 0xf194(%rip), %rdi      # 0x14fd0
leaq 0x95b0(%rip), %rsi      # 0xf3f3
callq 0x3290
movq 0xf181(%rip), %rcx      # 0x14fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf163(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq (%rsp), %rdx
incq %rdx
sarq $0x4, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
movq %rdx, (%rsp)
cmpq %rax, %rdx
jb 0x5cae
movq 0xf122(%rip), %rdi      # 0x14fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf107(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x18(%rbx), %rbp
cmpq %rbp, 0x20(%rbx)
je 0x6047
xorl %r12d, %r12d
movq 0xf0e2(%rip), %r14      # 0x14fd0
xorl %r13d, %r13d
movslq (%rbp,%r12), %rax
leaq (%rax,%rax,2), %rax
movq 0x78(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shlq $0x4, %rax
movq (%rcx,%r13,8), %rcx
leaq (%rcx,%rcx,2), %rbx
shlq $0x2, %rbx
addq 0x78(%rsp,%rax), %rbx
movl $0x1, %edx
movq %r14, %rdi
leaq 0x94ad(%rip), %rsi      # 0xf3d3
callq 0x3290
movq 0x8(%rbp,%r12), %rsi
movq %r14, %rdi
callq 0x3190
movq %rax, %r15
movl $0x4, %edx
movq %rax, %rdi
leaq 0x94a3(%rip), %rsi      # 0xf3ed
callq 0x3290
movq 0x10(%rbp,%r12), %rsi
movq %r15, %rdi
callq 0x3190
movq %rax, %r15
movl $0x9, %edx
movq %rax, %rdi
leaq 0x9467(%rip), %rsi      # 0xf3d5
callq 0x3290
addq %r12, %rbp
leaq 0xf2f3(%rip), %rdi      # 0x15270
movq %rbp, %rsi
callq 0x6610
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x3290
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x90ae(%rip), %rsi      # 0xf054
callq 0x3290
movl 0x8(%rbx), %esi
movq %r15, %rdi
callq 0x33f0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9417(%rip), %rsi      # 0xf3df
callq 0x3290
movl (%rbx), %esi
movq %r15, %rdi
callq 0x33f0
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x9409(%rip), %rsi      # 0xf3f2
callq 0x3290
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
incq %r13
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rbp
movq 0x20(%rbx), %rax
subq %rbp, %rax
sarq $0x4, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x30, %r12
cmpq %rax, %r13
jb 0x5ef1
movq 0xef82(%rip), %rbx      # 0x14fd0
leaq 0x93a1(%rip), %rsi      # 0xf3f6
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3290
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xef50(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq $-0x210, %r14           # imm = 0xFDF0
leaq 0x240(%rsp), %rbx
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x60b1
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x6742
addq $-0x30, %rbx
addq $0x30, %r14
jne 0x609c
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x60df
jmp 0x60df
jmp 0x60df
jmp 0x60df
jmp 0x60df
movq %rax, %rbx
movq $-0x210, %r15           # imm = 0xFDF0
leaq 0x240(%rsp), %r14
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x6106
movq 0x28(%r14), %rsi
subq %rdi, %rsi
callq 0x3250
movq %r14, %rdi
callq 0x6742
addq $-0x30, %r14
addq $0x30, %r15
jne 0x60f1
movq %rbx, %rdi
callq 0x3400