// File: /workspace/github_cpp_makefile_star2_O3/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 $0x298, %rsp            # imm = 0x298
movq %rsi, %r14
movq %rdi, 0x18(%rsp)
leaq 0x80(%rsp), %r15
xorl %ebx, %ebx
movl $0x210, %edx            # imm = 0x210
movq %r15, %rdi
xorl %esi, %esi
callq 0x3150
leaq 0x38(%rsp), %r13
leaq 0x20(%rsp), %r12
xorl %ebp, %ebp
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x5890
movq 0x10(%r15), %rax
movaps 0x20(%rsp), %xmm0
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%r15)
movaps (%r15), %xmm1
movaps %xmm0, (%r15)
movaps %xmm1, 0x60(%rsp)
movq %rax, 0x70(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6740
movq 0x18(%r15), %rdi
movq 0x28(%r15), %rsi
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x18(%r15)
movq 0x48(%rsp), %rax
movq %rax, 0x28(%r15)
movq %rbx, 0x10(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
testq %rdi, %rdi
je 0x5c20
subq %rdi, %rsi
callq 0x3250
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5c20
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq %r12, %rdi
callq 0x6740
movq %r15, %rdi
callq 0x7bfc
incq %rbp
addq $0x30, %r15
cmpq $0xb, %rbp
jne 0x5b88
movq 0xf388(%rip), %r14      # 0x14fd0
leaq 0x9770(%rip), %rsi      # 0xf3bf
movl $0x13, %edx
movq %r14, %rdi
callq 0x3290
movq 0x18(%rsp), %rbx
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf351(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0x5ea0
movq $0x0, 0x10(%rsp)
movl $0x1, %edx
movq 0xf322(%rip), %rdi      # 0x14fd0
leaq 0x971e(%rip), %rsi      # 0xf3d3
callq 0x3290
movq 0xf30f(%rip), %rdi      # 0x14fd0
movq 0x10(%rsp), %rsi
callq 0x3190
movl $0x9, %edx
movq %rax, %rdi
leaq 0x96fb(%rip), %rsi      # 0xf3d5
callq 0x3290
movq (%rbx), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $0x28, %rax
movq 0x10(%rax), %r12
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
cmpq %rax, %r12
je 0x5df1
movslq 0x20(%r12), %rax
movl %eax, 0x20(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x48(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
shlq $0x4, %rax
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %r15
movq 0x80(%rsp,%rax), %rbx
shlq $0x6, %r15
movl (%rbx,%r15), %eax
testl %eax, %eax
sets %r14b
cmpl 0x4(%rbx,%r15), %eax
setl 0xf(%rsp)
testl %eax, %eax
je 0x5dce
leaq 0xf519(%rip), %rdi      # 0x15270
leaq 0x20(%rsp), %rsi
callq 0x6614
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0xf261(%rip), %rdi      # 0x14fd0
callq 0x3290
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9ab8(%rip), %rsi      # 0xf83e
callq 0x3290
addq %r15, %rbx
movl 0x4(%rbx), %esi
movq %r13, %rdi
callq 0x33f0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x9634(%rip), %rsi      # 0xf3df
callq 0x3290
movl (%rbx), %esi
movq %r13, %rdi
callq 0x33f0
movl $0x2, %edx
movq %rax, %rdi
leaq 0x9810(%rip), %rsi      # 0xf5d9
callq 0x3290
andb 0xf(%rsp), %r14b
orb %r14b, %bpl
movq %r12, %rdi
callq 0x32a0
movq %rax, %r12
cmpq 0x58(%rsp), %rax
movq 0x18(%rsp), %rbx
jne 0x5d0a
movl $0x1, %edx
movq 0xf1d3(%rip), %rdi      # 0x14fd0
leaq 0x97e0(%rip), %rsi      # 0xf5e4
callq 0x3290
testb $0x1, %bpl
je 0x5e27
movl $0xb, %edx
movq 0xf1b5(%rip), %rdi      # 0x14fd0
leaq 0x95bf(%rip), %rsi      # 0xf3e1
callq 0x3290
movl $0x2, %edx
movq 0xf19d(%rip), %rdi      # 0x14fd0
leaq 0x95b9(%rip), %rsi      # 0xf3f3
callq 0x3290
movq 0xf18a(%rip), %rcx      # 0x14fd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf16c(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x8(%rbx), %rax
subq (%rbx), %rax
movq 0x10(%rsp), %rdx
incq %rdx
sarq $0x4, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
movq %rdx, 0x10(%rsp)
cmpq %rax, %rdx
jb 0x5ca2
movq 0xf129(%rip), %rdi      # 0x14fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0xf10e(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x18(%rbx), %rbp
cmpq %rbp, 0x20(%rbx)
je 0x6043
xorl %r12d, %r12d
movq 0xf0e9(%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 0x98(%rsp,%rax), %rbx
movl $0x1, %edx
movq %r14, %rdi
leaq 0x94b1(%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 0x94a7(%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 0x946b(%rip), %rsi      # 0xf3d5
callq 0x3290
addq %r12, %rbp
leaq 0xf2f7(%rip), %rdi      # 0x15270
movq %rbp, %rsi
callq 0x6614
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r15, %rdi
callq 0x3290
movq %rax, %r15
movl $0x2, %edx
movq %rax, %rdi
leaq 0x90b2(%rip), %rsi      # 0xf054
callq 0x3290
movl 0x8(%rbx), %esi
movq %r15, %rdi
callq 0x33f0
movq %rax, %r15
movl $0x1, %edx
movq %rax, %rdi
leaq 0x941b(%rip), %rsi      # 0xf3df
callq 0x3290
movl (%rbx), %esi
movq %r15, %rdi
callq 0x33f0
movq %rax, %r15
movl $0x3, %edx
movq %rax, %rdi
leaq 0x940d(%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 0x18(%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 0x5eea
movq 0xef86(%rip), %rbx      # 0x14fd0
leaq 0x93a5(%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 0xef54(%rip), %rdi      # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq $-0x210, %r14           # imm = 0xFDF0
leaq 0x260(%rsp), %rbx
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x60ad
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x3250
movq %rbx, %rdi
callq 0x6740
addq $-0x30, %rbx
addq $0x30, %r14
jne 0x6098
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x60db
jmp 0x60db
jmp 0x60db
jmp 0x60db
jmp 0x60db
movq %rax, %rbx
movq $-0x210, %r15           # imm = 0xFDF0
leaq 0x260(%rsp), %r14
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x6102
movq 0x28(%r14), %rsi
subq %rdi, %rsi
callq 0x3250
movq %r14, %rdi
callq 0x6740
addq $-0x30, %r14
addq $0x30, %r15
jne 0x60ed
movq %rbx, %rdi
callq 0x3400