// File: /workspace/github_cpp_makefile_star2_O3/rilutham[P]gotojakarta/go-to-jakarta.cpp
// Function: main
int main( int argc, char *argv[] )
{
  // Creating Map of West Java
  for(int i=0; i<MAX_CITIES; i++)
    for(int j=0; j<MAX_CITIES; j++)
      WestJavaMap[i][j]=-1.0;

  // Define distance between two cities 
  // From Plat Z
  WestJavaMap[Pangandaran][Banjar]=63;
  WestJavaMap[Banjar][Ciamis]=26;
  WestJavaMap[Banjar][Kuningan]=83;
  WestJavaMap[Ciamis][Tasikmalaya]=19;
  WestJavaMap[Ciamis][Kuningan]=68;
  WestJavaMap[Tasikmalaya][Garut]=56;
  WestJavaMap[Tasikmalaya][Bandung]=93;
  WestJavaMap[Garut][Bandung]=51;
  WestJavaMap[Sumedang][Bandung]=33;

  // From Plat E
  WestJavaMap[Kuningan][Cirebon]=32;
  WestJavaMap[Kuningan][Majalengka]=58;
  WestJavaMap[Cirebon][Indramayu]=55;
  WestJavaMap[Cirebon][Majalengka]=43;
  WestJavaMap[Majalengka][Sumedang]=47;
  WestJavaMap[Majalengka][Subang]=85;
  WestJavaMap[Indramayu][Karawang]=115;

  // From Plat D
  WestJavaMap[Bandung][Subang]=60;
  WestJavaMap[Bandung][Cimahi]=35;
  WestJavaMap[Cimahi][Purwakarta]=55;
  WestJavaMap[Cimahi][Cianjur]=56;

  // From Plat T
  WestJavaMap[Subang][Purwakarta]=45;
  WestJavaMap[Purwakarta][Karawang]=30;
  WestJavaMap[Karawang][Bekasi]=45;

  // From Plat F
  WestJavaMap[Cianjur][Sukabumi]=30;
  WestJavaMap[Cianjur][Bogor]=69;
  WestJavaMap[Sukabumi][Bogor]=72;
  WestJavaMap[Bogor][Depok]=22;

  // From Plat B
  WestJavaMap[Depok][Jakarta]=26;
  WestJavaMap[Bekasi][Jakarta]=27;

  // City names
  CityNames[Garut].assign("Garut");
  CityNames[Jakarta].assign("Jakarta");
  CityNames[Tasikmalaya].assign("Tasikmalaya");
  CityNames[Ciamis].assign("Ciamis");
  CityNames[Banjar].assign("Banjar");
  CityNames[Pangandaran].assign("Pangandaran");
  CityNames[Sumedang].assign("Sumedang");
  CityNames[Bandung].assign("Bandung");
  CityNames[Cimahi].assign("Cimahi");
  CityNames[Kuningan].assign("Kuningan");
  CityNames[Majalengka].assign("Majalengka");
  CityNames[Cirebon].assign("Cirebon");
  CityNames[Indramayu].assign("Indramayu");
  CityNames[Subang].assign("Subang");
  CityNames[Karawang].assign("Karawang");
  CityNames[Purwakarta].assign("Purwakarta");
  CityNames[Cianjur].assign("Cianjur");
  CityNames[Sukabumi].assign("Sukabumi");
  CityNames[Bogor].assign("Bogor");
  CityNames[Depok].assign("Depok");
  CityNames[Bekasi].assign("Bekasi");

  ENUM_CITIES initCity = Garut;
  if(argc == 2)
  {
    bool found = false;
    for(size_t i=0; i<CityNames.size(); i++)
      if(CityNames[i].compare(argv[1])==0)
      {
        initCity = (ENUM_CITIES)i;
        found = true;
        break;
      }
    if(not found)
    {
      cout << "Kota "<<argv[1]<<" tidak ditemukan pada peta Jawa Barat, silahkan ulangi!\n";
      cout << "Gunakan kapital pada huruf pertama nama kota. Contoh: Garut, Pangandaran.\n";
      return(1);
    }
  }

  // An instance of A* search class
	AStarSearch<PathSearchNode> astarsearch;

	unsigned int SearchCount = 0;
	const unsigned int NumSearches = 1;

	while(SearchCount < NumSearches)
	{
		// Create a start state
		PathSearchNode nodeStart;
		nodeStart.city = initCity;

		// Define the goal state, always Jakarta!
		PathSearchNode nodeEnd;
		nodeEnd.city = Jakarta;

		// Set Start and goal states
		astarsearch.SetStartAndGoalStates( nodeStart, nodeEnd );

		unsigned int SearchState;
		unsigned int SearchSteps = 0;

		do
		{
			SearchState = astarsearch.SearchStep();
			SearchSteps++;

	#if DEBUG_LISTS

			cout << "Steps:" << SearchSteps << "\n";

			int len = 0;

			cout << "Open:\n";
			PathSearchNode *p = astarsearch.GetOpenListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY
				((PathSearchNode *)p)->PrintNodeInfo();
	#endif
				p = astarsearch.GetOpenListNext();

			}
			cout << "Open list has " << len << " nodes\n";

			len = 0;

			cout << "Closed:\n";
			p = astarsearch.GetClosedListStart();
			while( p )
			{
				len++;
	#if !DEBUG_LIST_LENGTHS_ONLY
				p->PrintNodeInfo();
	#endif
				p = astarsearch.GetClosedListNext();
			}

			cout << "Closed list has " << len << " nodes\n";
	#endif

		}
		while( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_SEARCHING );

		if( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_SUCCEEDED )
		{
			cout << "Pencarian rute terpendek menuju Jakarta ditemukan!\n";
      PathSearchNode *node = astarsearch.GetSolutionStart();
      cout << "Berikut kota-kota yang harus dilalui:\n";
      int steps = 0;
      node->PrintNodeInfo();
      for( ;; )
      {
        node = astarsearch.GetSolutionNext();
        if( !node ) break;
        node->PrintNodeInfo();
        steps ++;
      };
      cout << "Langkah Solusi : " << steps << endl;
      // Once you're done with the solution you can free the nodes up
			astarsearch.FreeSolutionNodes();
		}
		else if( SearchState == AStarSearch<PathSearchNode>::SEARCH_STATE_FAILED )
		{
			cout << "Search terminated. Did not find goal state\n";
		}
		// Display the number of loops the search went through
		cout << "Jumlah langkah pencarian : " << SearchSteps << "\n";
		SearchCount ++;
		astarsearch.EnsureMemoryFreed();
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x3c16(%rip), %rax      # 0x5120
xorl %ecx, %ecx
xorl %edx, %edx
movl $0xbf800000, (%rax,%rdx,4) # imm = 0xBF800000
incq %rdx
cmpq $0x15, %rdx
jne 0x150e
incq %rcx
addq $0x54, %rax
cmpq $0x15, %rcx
jne 0x150c
movl $0x427c0000, 0x3d9f(%rip) # imm = 0x427C0000
movl $0x41d00000, %eax       # imm = 0x41D00000
movl %eax, 0x3d3c(%rip)      # 0x527c
movl $0x42a60000, 0x3d4a(%rip) # imm = 0x42A60000
movl $0x41980000, 0x3cd0(%rip) # imm = 0x41980000
movl $0x42880000, 0x3ce2(%rip) # imm = 0x42880000
movl $0x42600000, 0x3c60(%rip) # imm = 0x42600000
movl $0x42ba0000, 0x3c72(%rip) # imm = 0x42BA0000
movl $0x424c0000, 0x3bc0(%rip) # imm = 0x424C0000
movl $0x42040000, 0x3dae(%rip) # imm = 0x42040000
movabsq $0x4200000042680000, %rcx # imm = 0x4200000042680000
movq %rcx, 0x3ea5(%rip)      # 0x543c
movl $0x425c0000, 0x3f4b(%rip) # imm = 0x425C0000
movl $0x422c0000, 0x3f39(%rip) # imm = 0x422C0000
movl $0x423c0000, 0x3ecb(%rip) # imm = 0x423C0000
movl $0x42aa0000, 0x3edd(%rip) # imm = 0x42AA0000
movl $0x42e60000, 0x3f7f(%rip) # imm = 0x42E60000
movl $0x42700000, 0x3dcd(%rip) # imm = 0x42700000
movl $0x420c0000, 0x3daf(%rip) # imm = 0x420C0000
movabsq $0x42600000425c0000, %rcx # imm = 0x42600000425C0000
movq %rcx, 0x3e0e(%rip)      # 0x53fc
movl $0x42340000, %ecx       # imm = 0x42340000
movl %ecx, 0x3fa7(%rip)      # 0x55a0
movl $0x41f00000, 0x4041(%rip) # imm = 0x41F00000
movl %ecx, 0x3fff(%rip)      # 0x5608
movabsq $0x428a000041f00000, %rcx # imm = 0x428A000041F00000
movq %rcx, 0x408a(%rip)      # 0x56a4
movl $0x42900000, 0x40d8(%rip) # imm = 0x42900000
movl $0x41b00000, 0x4126(%rip) # imm = 0x41B00000
movl %eax, 0x412c(%rip)      # 0x5760
movl $0x41d80000, 0x4176(%rip) # imm = 0x41D80000
movq 0x3ac3(%rip), %rdi      # 0x5108
movq 0x8(%rdi), %rdx
leaq 0x19e0(%rip), %rcx      # 0x3030
xorl %r15d, %r15d
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3aa1(%rip), %rdi      # 0x5108
movq 0x28(%rdi), %rdx
addq $0x20, %rdi
leaq 0x19c0(%rip), %rcx      # 0x3036
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a7e(%rip), %rdi      # 0x5108
movq 0x48(%rdi), %rdx
addq $0x40, %rdi
leaq 0x19a5(%rip), %rcx      # 0x303e
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a5b(%rip), %rdi      # 0x5108
movq 0x68(%rdi), %rdx
addq $0x60, %rdi
leaq 0x198e(%rip), %rcx      # 0x304a
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a38(%rip), %rdi      # 0x5108
movq 0x88(%rdi), %rdx
subq $-0x80, %rdi
leaq 0x196f(%rip), %rcx      # 0x3051
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3a12(%rip), %rdi      # 0x5108
movq 0xa8(%rdi), %rdx
addq $0xa0, %rdi
leaq 0x194d(%rip), %rcx      # 0x3058
movl $0xb, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x39e9(%rip), %rdi      # 0x5108
movq 0xc8(%rdi), %rdx
addq $0xc0, %rdi
leaq 0x1930(%rip), %rcx      # 0x3064
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x39c0(%rip), %rdi      # 0x5108
movq 0xe8(%rdi), %rdx
addq $0xe0, %rdi
leaq 0x1910(%rip), %rcx      # 0x306d
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3997(%rip), %rdi      # 0x5108
movq 0x108(%rdi), %rdx
addq $0x100, %rdi            # imm = 0x100
leaq 0x18ef(%rip), %rcx      # 0x3075
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x396e(%rip), %rdi      # 0x5108
movq 0x128(%rdi), %rdx
addq $0x120, %rdi            # imm = 0x120
leaq 0x18cd(%rip), %rcx      # 0x307c
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3945(%rip), %rdi      # 0x5108
movq 0x148(%rdi), %rdx
addq $0x140, %rdi            # imm = 0x140
leaq 0x18ad(%rip), %rcx      # 0x3085
movl $0xa, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x391c(%rip), %rdi      # 0x5108
movq 0x168(%rdi), %rdx
addq $0x160, %rdi            # imm = 0x160
leaq 0x188f(%rip), %rcx      # 0x3090
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x38f3(%rip), %rdi      # 0x5108
movq 0x188(%rdi), %rdx
addq $0x180, %rdi            # imm = 0x180
leaq 0x186e(%rip), %rcx      # 0x3098
movl $0x9, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x38ca(%rip), %rdi      # 0x5108
movq 0x1a8(%rdi), %rdx
addq $0x1a0, %rdi            # imm = 0x1A0
leaq 0x184f(%rip), %rcx      # 0x30a2
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x38a1(%rip), %rdi      # 0x5108
movq 0x1c8(%rdi), %rdx
addq $0x1c0, %rdi            # imm = 0x1C0
leaq 0x182d(%rip), %rcx      # 0x30a9
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3878(%rip), %rdi      # 0x5108
movq 0x1e8(%rdi), %rdx
addq $0x1e0, %rdi            # imm = 0x1E0
leaq 0x180d(%rip), %rcx      # 0x30b2
movl $0xa, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x384f(%rip), %rdi      # 0x5108
movq 0x208(%rdi), %rdx
addq $0x200, %rdi            # imm = 0x200
leaq 0x17ef(%rip), %rcx      # 0x30bd
movl $0x7, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x3826(%rip), %rdi      # 0x5108
movq 0x228(%rdi), %rdx
addq $0x220, %rdi            # imm = 0x220
leaq 0x17ce(%rip), %rcx      # 0x30c5
movl $0x8, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37fd(%rip), %rdi      # 0x5108
movq 0x248(%rdi), %rdx
addq $0x240, %rdi            # imm = 0x240
leaq 0x17ae(%rip), %rcx      # 0x30ce
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37d4(%rip), %rdi      # 0x5108
movq 0x268(%rdi), %rdx
addq $0x260, %rdi            # imm = 0x260
leaq 0x178b(%rip), %rcx      # 0x30d4
movl $0x5, %r8d
xorl %esi, %esi
callq 0x1150
movq 0x37ab(%rip), %rdi      # 0x5108
movq 0x288(%rdi), %rdx
addq $0x280, %rdi            # imm = 0x280
leaq 0x1768(%rip), %rcx      # 0x30da
movl $0x6, %r8d
xorl %esi, %esi
callq 0x1150
cmpl $0x2, %r14d
jne 0x1a17
movq 0x3778(%rip), %rdi      # 0x5108
cmpq %rdi, 0x3779(%rip)      # 0x5110
je 0x19d0
xorl %r14d, %r14d
xorl %r15d, %r15d
addq %r14, %rdi
movq 0x8(%rbx), %rsi
callq 0x1050
testl %eax, %eax
je 0x1a17
incq %r15
movq 0x3757(%rip), %rax      # 0x5110
movq 0x3748(%rip), %rdi      # 0x5108
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r14
cmpq %rax, %r15
jb 0x199f
movq 0x35f9(%rip), %r14      # 0x4fd0
leaq 0x1703(%rip), %rsi      # 0x30e1
movl $0x5, %edx
movq %r14, %rdi
callq 0x1120
movq 0x8(%rbx), %rbx
testq %rbx, %rbx
je 0x1bec
movq %rbx, %rdi
callq 0x1070
movq 0x35c9(%rip), %rdi      # 0x4fd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x1120
jmp 0x1c04
leaq -0xc0(%rbp), %rbx
movq %rbx, %rdi
callq 0x1ddc
leaq -0x20(%rbp), %rsi
movl %r15d, (%rsi)
leaq -0x1c(%rbp), %rdx
movl $0x1, (%rdx)
movq %rbx, %rdi
callq 0x1e64
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1f90
incl %r14d
cmpl $0x1, %eax
je 0x1a42
cmpl $0x3, %eax
je 0x1ad1
cmpl $0x2, %eax
jne 0x1b47
movq 0x3569(%rip), %rdi      # 0x4fd0
leaq 0x16fd(%rip), %rsi      # 0x316b
movl $0x33, %edx
callq 0x1120
movq -0x70(%rbp), %rbx
movq %rbx, -0x60(%rbp)
movq 0x3549(%rip), %rdi      # 0x4fd0
leaq 0x1711(%rip), %rsi      # 0x319f
movl $0x26, %edx
callq 0x1120
leaq 0x1c(%rbx), %rdi
testq %rbx, %rbx
cmoveq %rbx, %rdi
callq 0x1492
movq -0x60(%rbp), %rax
xorl %ebx, %ebx
testq %rax, %rax
je 0x1aeb
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x1aeb
movq %rdi, -0x60(%rbp)
addq $0x1c, %rdi
callq 0x1492
incl %ebx
movq -0x60(%rbp), %rax
jmp 0x1aae
movq 0x34f8(%rip), %rdi      # 0x4fd0
leaq 0x16f9(%rip), %rsi      # 0x31d8
movl $0x2b, %edx
callq 0x1120
jmp 0x1b47
movq 0x34de(%rip), %rdi      # 0x4fd0
leaq 0x16cd(%rip), %rsi      # 0x31c6
movl $0x11, %edx
callq 0x1120
movq 0x34c6(%rip), %rdi      # 0x4fd0
movl %ebx, %esi
callq 0x1180
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
leaq -0xc0(%rbp), %rdi
callq 0x22e4
movq 0x3482(%rip), %rdi      # 0x4fd0
leaq 0x16af(%rip), %rsi      # 0x3204
movl $0x1b, %edx
callq 0x1120
movl %r14d, %esi
movq 0x3467(%rip), %rdi      # 0x4fd0
callq 0x10b0
leaq 0x15a9(%rip), %rsi      # 0x311e
movl $0x1, %edx
movq %rax, %rdi
callq 0x1120
cmpl $0x0, -0x28(%rbp)
jne 0x1c46
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x1b9a
callq 0x1130
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x1bb2
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0x1bcd
movq -0x98(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x1be8
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
callq 0x1110
xorl %eax, %eax
jmp 0x1c38
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x1170
movq 0x33c5(%rip), %rbx      # 0x4fd0
leaq 0x14d5(%rip), %rsi      # 0x30e7
movl $0x38, %edx
movq %rbx, %rdi
callq 0x1120
leaq 0x14fa(%rip), %rsi      # 0x3120
movl $0x4a, %edx
movq %rbx, %rdi
callq 0x1120
movl $0x1, %eax
addq $0xa8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x175f(%rip), %rdi      # 0x33ac
leaq 0x163b(%rip), %rsi      # 0x328f
leaq 0x176a(%rip), %rcx      # 0x33c5
movl $0x274, %edx            # imm = 0x274
callq 0x10a0
jmp 0x1c6f
jmp 0x1c6f
jmp 0x1c6f
jmp 0x1c6f
jmp 0x1c6f
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x232c
movq %rbx, %rdi
callq 0x1190