// File: /workspace/github_cpp_makefile_star2_O2/Windfisch[P]production-flow/main.cpp
// Function: main
int main(int argc, const char** argv)
{
	if (argc != 2)
	{
		cout << "Usage: " << argv[0] << " factory.tgf" << endl;
		exit(1);
	}
	
	Factory factory = read_factory(argv[1]);
	factory.initialize();

	Factory::FactoryConfiguration conf;
	for (size_t i=0; i<factory.facilities.size(); i++)
		conf.facility_levels.push_back(0);
	for (size_t i=0; i<factory.transport_lines.size(); i++)
		conf.transport_levels.push_back(0);

	ActionGraph actiongraph(&factory);
	auto result = actiongraph.dijkstra(conf);

	cout << endl << endl << endl << endl;
	
	cout << "it follows the node/edge map. for item i, a->b means that flowgraph-node/edge a\n"
	        "corresponds to factory-facility/transportline b. Note that b is given as zero\n"
		"indexed number, but the .tgf file is one-based-indexed. Add 1 before looking it up" << endl;
	for (int i=0; i<MAX_ITEM; i++)
	{
		cout << "item " << i << ": facilities ";
		for (int j=0; j<factory.facility_toposort[i].size(); j++)
			cout << j<<"->"<<factory.facility_toposort[i][j] << ", ";
		cout << "transport lines ";
		for (int j=0; j<factory.edge_table_per_item[i].size(); j++)
			cout << j<<"->"<<factory.edge_table_per_item[i][j] << ", ";
		cout << endl;
	}

	cout << delimiter;
	cout << "now simulating the entire factory in its before-state" << endl;
	factory.simulate_debug(conf);
	
	cout << delimiter;
	cout << "now simulating the entire factory in its after-state" << endl;
	factory.simulate_debug(result.first);
	cout << delimiter;
	cout << "bye." << endl;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %rbx
cmpl $0x2, %edi
jne 0x4597
movq 0x8(%rbx), %rsi
leaq 0x78(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x4636
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x9594
leaq 0x78(%rsp), %rdi
callq 0x3418
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x4db8
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r14
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
xorl %r12d, %r12d
pushq $0x50
popq %r13
leaq 0x8(%rsp), %r15
movq 0xa0(%rsp), %rax
subq 0x98(%rsp), %rax
cqto
idivq %r13
cmpq %rax, %r12
jae 0x42da
andq $0x0, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b8a
incq %r12
jmp 0x42aa
leaq 0x58(%rsp), %r14
xorl %r12d, %r12d
pushq $0x30
popq %r13
leaq 0x8(%rsp), %r15
movq 0xb8(%rsp), %rax
subq 0xb0(%rsp), %rax
cqto
idivq %r13
cmpq %rax, %r12
jae 0x431b
andq $0x0, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x4b8a
incq %r12
jmp 0x42eb
movq %rbx, (%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x4672
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
leaq 0x128(%rsp), %rdx
callq 0x8b92
leaq 0x128(%rsp), %rdi
callq 0x46ac
movq 0x10c6e(%rip), %rdi     # 0x14fc8
callq 0x3110
movq %rax, %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3110
movq %rax, %rdi
callq 0x3110
movq 0x10c4a(%rip), %rdi     # 0x14fc8
leaq 0x8cdf(%rip), %rsi      # 0xd064
callq 0x3200
movq %rax, %rdi
callq 0x3110
xorl %ebx, %ebx
movq 0x10c2d(%rip), %r14     # 0x14fc8
leaq 0x8dc1(%rip), %r13      # 0xd163
leaq 0x9248(%rip), %rbp      # 0xd5f1
cmpq $0xb, %rbx
je 0x44b4
movq %r14, %rdi
leaq 0x8f94(%rip), %rsi      # 0xd351
callq 0x3200
movq %rax, %rdi
movl %ebx, %esi
callq 0x33b0
movq %rax, %rdi
leaq 0x8d7f(%rip), %rsi      # 0xd155
callq 0x3200
imulq $0x18, %rbx, %r15
xorl %r12d, %r12d
movq 0xc8(%rsp), %rax
movq 0x8(%rax,%r15), %rcx
subq (%rax,%r15), %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x443a
movq %r14, %rdi
movl %r12d, %esi
callq 0x33b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3200
movq 0xc8(%rsp), %rcx
movq (%rcx,%r15), %rcx
movq (%rcx,%r12,8), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
incq %r12
jmp 0x43e2
movq %r14, %rdi
leaq 0x8d22(%rip), %rsi      # 0xd166
callq 0x3200
xorl %r12d, %r12d
movq 0xf8(%rsp), %rax
movq 0x8(%rax,%r15), %rcx
subq (%rax,%r15), %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
jbe 0x44a4
movq %r14, %rdi
movl %r12d, %esi
callq 0x33b0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3200
movq 0xf8(%rsp), %rcx
movq (%rcx,%r15), %rcx
movq (%rcx,%r12,8), %rsi
movq %rax, %rdi
callq 0x3180
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3200
incq %r12
jmp 0x444c
movq %r14, %rdi
callq 0x3110
incq %rbx
jmp 0x43a9
movq 0x10b0d(%rip), %rdi     # 0x14fc8
leaq 0x10d6e(%rip), %rsi     # 0x15230
callq 0x31f0
movq 0x10afa(%rip), %rdi     # 0x14fc8
leaq 0x8ca2(%rip), %rsi      # 0xd177
callq 0x3200
movq %rax, %rdi
callq 0x3110
leaq 0x98(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x54f0
movq 0x10acd(%rip), %rdi     # 0x14fc8
leaq 0x10d2e(%rip), %rsi     # 0x15230
callq 0x31f0
movq 0x10aba(%rip), %rdi     # 0x14fc8
leaq 0x8c98(%rip), %rsi      # 0xd1ad
callq 0x3200
movq %rax, %rdi
callq 0x3110
leaq 0x98(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x54f0
movq 0x10a8d(%rip), %rdi     # 0x14fc8
leaq 0x10cee(%rip), %rsi     # 0x15230
callq 0x31f0
movq 0x10a7a(%rip), %rdi     # 0x14fc8
leaq 0x8c8d(%rip), %rsi      # 0xd1e2
callq 0x3200
movq %rax, %rdi
callq 0x3110
leaq 0x8(%rsp), %rdi
callq 0x46ac
leaq 0x40(%rsp), %rdi
callq 0x46ac
leaq 0x98(%rsp), %rdi
callq 0x46c2
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10a2a(%rip), %rdi     # 0x14fc8
leaq 0x8aaa(%rip), %rsi      # 0xd04f
callq 0x3200
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3200
leaq 0x8a9b(%rip), %rsi      # 0xd057
movq %rax, %rdi
callq 0x3200
movq %rax, %rdi
callq 0x3110
pushq $0x1
popq %rdi
callq 0x3270
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x4611
jmp 0x4600
movq %rax, %rbx
jmp 0x4620
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3418
jmp 0x462d
movq %rax, %rbx
jmp 0x462d
jmp 0x4609
jmp 0x4600
movq %rax, %rbx
jmp 0x4616
jmp 0x4609
jmp 0x4609
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x46ac
leaq 0x40(%rsp), %rdi
callq 0x46ac
leaq 0x98(%rsp), %rdi
callq 0x46c2
movq %rbx, %rdi
callq 0x33c0
nop