// File: /workspace/github_cpp_makefile_star2_O3/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 $0x168, %rsp            # imm = 0x168
movq %rsi, %rbx
cmpl $0x2, %edi
jne 0x4b47
movq 0x8(%rbx), %rsi
leaq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x4c26
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xaf14
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4515
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3250
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0x5290
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0xd8(%rsp), %rax
movq 0xe0(%rsp), %rcx
cmpq %rax, %rcx
je 0x45bb
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
leaq 0x50(%rsp), %r15
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
movq $0x0, 0x50(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x458a
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x45a5
movq %r14, %rdi
movq %r15, %rdx
callq 0x502c
movq 0xd8(%rsp), %rax
movq 0xe0(%rsp), %rcx
incq %r12
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r13, %rdx
cmpq %rdx, %r12
jb 0x4563
movq 0xf0(%rsp), %rax
movq 0xf8(%rsp), %rcx
cmpq %rax, %rcx
je 0x463f
leaq 0x28(%rsp), %r14
xorl %r12d, %r12d
leaq 0x50(%rsp), %r15
movabsq $-0x5555555555555555, %r13 # imm = 0xAAAAAAAAAAAAAAAB
movq $0x0, 0x50(%rsp)
movq 0x30(%rsp), %rsi
cmpq 0x38(%rsp), %rsi
je 0x460e
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x30(%rsp)
jmp 0x4629
movq %r14, %rdi
movq %r15, %rdx
callq 0x502c
movq 0xf0(%rsp), %rax
movq 0xf8(%rsp), %rcx
incq %r12
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x4, %rdx
imulq %r13, %rdx
cmpq %rdx, %r12
jb 0x45e7
movq %rbx, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4cfe
leaq 0xa0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4cfe
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0xa40c
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x469c
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x46b9
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x10910(%rip), %rdi     # 0x14fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x108f5(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x10863(%rip), %rbx     # 0x14fd0
leaq 0xa8f0(%rip), %rsi      # 0xf064
movl $0xf0, %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 0x10831(%rip), %r12     # 0x14fd0
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq $0x0, 0x8(%rsp)
leaq 0xa9a4(%rip), %r15      # 0xf163
leaq 0xae13(%rip), %rbp      # 0xf5d9
movl $0x5, %edx
movq %r12, %rdi
leaq 0xab75(%rip), %rsi      # 0xf34a
callq 0x3290
movq %r12, %rdi
movq 0x8(%rsp), %rsi
callq 0x33f0
movl $0xd, %edx
movq %rax, %rdi
leaq 0xa95f(%rip), %rsi      # 0xf155
callq 0x3290
movq 0x108(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %r13
movq 0x8(%rax,%r13,8), %rcx
cmpq (%rax,%r13,8), %rcx
je 0x487b
xorl %ebx, %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0x33f0
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3290
movq 0x108(%rsp), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3190
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
incq %rbx
movq 0x108(%rsp), %rax
movq 0x8(%rax,%r13,8), %rcx
subq (%rax,%r13,8), %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x4819
movl $0x10, %edx
movq %r12, %rdi
leaq 0xa8dc(%rip), %rsi      # 0xf166
callq 0x3290
movq 0x138(%rsp), %rax
movq 0x8(%rax,%r13,8), %rcx
cmpq (%rax,%r13,8), %rcx
je 0x4906
xorl %ebx, %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0x33f0
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3290
movq 0x138(%rsp), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
callq 0x3190
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
incq %rbx
movq 0x138(%rsp), %rax
movq 0x8(%rax,%r13,8), %rcx
subq (%rax,%r13,8), %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x48a4
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq $0xb, %rcx
jne 0x47c6
movq 0x108fc(%rip), %rsi     # 0x15248
movq 0x108fd(%rip), %rdx     # 0x15250
movq 0x10676(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x1066a(%rip), %rbx     # 0x14fd0
leaq 0xa80a(%rip), %rsi      # 0xf177
movl $0x35, %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 0x10638(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x5b4a
movq 0x1088a(%rip), %rsi     # 0x15248
movq 0x1088b(%rip), %rdx     # 0x15250
movq 0x10604(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x105f8(%rip), %rbx     # 0x14fd0
leaq 0xa7ce(%rip), %rsi      # 0xf1ad
movl $0x34, %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 0x105c6(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5b4a
movq 0x10818(%rip), %rsi     # 0x15248
movq 0x10819(%rip), %rdx     # 0x15250
movq 0x10592(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x10586(%rip), %rbx     # 0x14fd0
leaq 0xa791(%rip), %rsi      # 0xf1e2
movl $0x4, %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 0x10554(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x4aa0
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4ab7
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4ace
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4ae5
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0x150(%rsp), %rdi
callq 0x4da4
leaq 0x138(%rsp), %rdi
callq 0x4da4
leaq 0x120(%rsp), %rdi
callq 0x4da4
leaq 0x108(%rsp), %rdi
callq 0x4da4
leaq 0xf0(%rsp), %rdi
callq 0x4df8
leaq 0xd8(%rsp), %rdi
callq 0x4e4c
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10482(%rip), %rdi     # 0x14fd0
leaq 0xa4fa(%rip), %rsi      # 0xf04f
callq 0x3230
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3230
leaq 0xa4eb(%rip), %rsi      # 0xf057
movq %rax, %rdi
callq 0x3230
movq %rax, %rdi
callq 0x3110
movl $0x1, %edi
callq 0x32c0
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4c64
jmp 0x4c06
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x4c06
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
jmp 0x4c06
jmp 0x4bee
movq %rax, %rbx
jmp 0x4c10
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4c1d
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3250
jmp 0x4c1d
movq %rax, %rbx
jmp 0x4c1d
jmp 0x4bee
movq %rax, %rbx
jmp 0x4c06
jmp 0x4bf9
jmp 0x4bf9
jmp 0x4bf9
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x4c94
leaq 0x10(%rsp), %rdi
callq 0x4c64
leaq 0xd8(%rsp), %rdi
callq 0x4cc4
movq %rbx, %rdi
callq 0x3400
nop