// File: /workspace/github_cpp_makefile_star2_O1/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 0x4b3b
movq 0x8(%rbx), %rsi
leaq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x4c1a
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xb034
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 0x5272
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0xe0(%rsp), %rax
cmpq 0xd8(%rsp), %rax
je 0x45b2
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 0x4587
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x4592
movq %r14, %rdi
movq %r15, %rdx
callq 0x5008
movq 0xe0(%rsp), %rax
subq 0xd8(%rsp), %rax
incq %r12
sarq $0x4, %rax
imulq %r13, %rax
cmpq %rax, %r12
jb 0x4560
movq 0xf8(%rsp), %rax
cmpq 0xf0(%rsp), %rax
je 0x462d
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 0x4602
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x30(%rsp)
jmp 0x460d
movq %r14, %rdi
movq %r15, %rdx
callq 0x5008
movq 0xf8(%rsp), %rax
subq 0xf0(%rsp), %rax
incq %r12
sarq $0x4, %rax
imulq %r13, %rax
cmpq %rax, %r12
jb 0x45db
movq %rbx, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4cf2
leaq 0xa0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4cf2
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0xa522
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x468a
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x46a7
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x10922(%rip), %rdi     # 0x14fd0
movq (%rdi), %rax
addq -0x18(%rax), %rdi
movl $0xa, %esi
callq 0x3220
movsbl %al, %esi
movq 0x10907(%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 0x10875(%rip), %rbx     # 0x14fd0
leaq 0xa902(%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 0x10843(%rip), %rbx     # 0x14fd0
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq $0x0, 0x8(%rsp)
leaq 0xa9b6(%rip), %rbp      # 0xf163
leaq 0xae25(%rip), %r15      # 0xf5d9
movl $0x5, %edx
movq %rbx, %rdi
leaq 0xab87(%rip), %rsi      # 0xf34a
callq 0x3290
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x33f0
movl $0xd, %edx
movq %rax, %rdi
leaq 0xa971(%rip), %rsi      # 0xf155
callq 0x3290
movq 0x108(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rcx,2), %r14
movq 0x8(%rax,%r14,8), %rcx
cmpq (%rax,%r14,8), %rcx
je 0x486b
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x33f0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
movq 0x108(%rsp), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r12,8), %rsi
movq %r13, %rdi
callq 0x3190
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3290
incq %r12
movq 0x108(%rsp), %rax
movq 0x8(%rax,%r14,8), %rcx
subq (%rax,%r14,8), %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0x4808
movl $0x10, %edx
movq %rbx, %rdi
leaq 0xa8ec(%rip), %rsi      # 0xf166
callq 0x3290
movq 0x138(%rsp), %rax
movq 0x8(%rax,%r14,8), %rcx
cmpq (%rax,%r14,8), %rcx
je 0x48f8
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x33f0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3290
movq 0x138(%rsp), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%r12,8), %rsi
movq %r13, %rdi
callq 0x3190
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x3290
incq %r12
movq 0x138(%rsp), %rax
movq 0x8(%rax,%r14,8), %rcx
subq (%rax,%r14,8), %rcx
sarq $0x3, %rcx
cmpq %r12, %rcx
ja 0x4895
movq (%rbx), %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 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq $0xb, %rcx
jne 0x47b4
movq 0x1090b(%rip), %rsi     # 0x15248
movq 0x1090c(%rip), %rdx     # 0x15250
movq 0x10685(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x10679(%rip), %rbx     # 0x14fd0
leaq 0xa819(%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 0x10647(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x5b5c
movq 0x10899(%rip), %rsi     # 0x15248
movq 0x1089a(%rip), %rdx     # 0x15250
movq 0x10613(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x10607(%rip), %rbx     # 0x14fd0
leaq 0xa7dd(%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 0x105d5(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
leaq 0xd8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x5b5c
movq 0x10827(%rip), %rsi     # 0x15248
movq 0x10828(%rip), %rdx     # 0x15250
movq 0x105a1(%rip), %rdi     # 0x14fd0
callq 0x3290
movq 0x10595(%rip), %rbx     # 0x14fd0
leaq 0xa7a0(%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 0x10563(%rip), %rdi     # 0x14fd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x4a91
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x4aa8
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x4abf
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4ad6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
leaq 0xf0(%rsp), %rbx
leaq 0x150(%rsp), %rdi
callq 0x4d98
leaq 0x138(%rsp), %rdi
callq 0x4d98
leaq 0x120(%rsp), %rdi
callq 0x4d98
leaq 0x108(%rsp), %rdi
callq 0x4d98
movq %rbx, %rdi
callq 0x4de6
leaq 0xd8(%rsp), %rdi
callq 0x4e34
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1048e(%rip), %rdi     # 0x14fd0
leaq 0xa506(%rip), %rsi      # 0xf04f
callq 0x3230
movq (%rbx), %rsi
movq %rax, %rdi
callq 0x3230
leaq 0xa4f7(%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 0x4c58
jmp 0x4bfa
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x4bfa
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x3250
jmp 0x4bfa
jmp 0x4be2
movq %rax, %rbx
jmp 0x4c04
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4c11
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3250
jmp 0x4c11
movq %rax, %rbx
jmp 0x4c11
jmp 0x4be2
movq %rax, %rbx
jmp 0x4bfa
jmp 0x4bed
jmp 0x4bed
jmp 0x4bed
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x4c88
leaq 0x10(%rsp), %rdi
callq 0x4c58
leaq 0xd8(%rsp), %rdi
callq 0x4cb8
movq %rbx, %rdi
callq 0x3400
nop