// File: /workspace/github_cpp_makefile_star2_O3/KellerMartins[P]PDS2-Pacman/source/game/mapa.cpp
// Function: Mapa::GerarCaminho()
void Mapa::GerarCaminho(){
	//Criando a matriz geradora de caminhos
	int** caminhos = new int*[LARGURA*ALTURA];
	for(int i = 0; i < LARGURA*ALTURA; i++){
		caminhos[i] = new int[LARGURA*ALTURA];
	}
	//Inicializando
	for(int i = 0; i < LARGURA*ALTURA; i++){
		for(int j = 0; j < LARGURA*ALTURA; j++){
			caminhos[i][j] = INT_MAX/2;
			_proximo[i][j] = -1;
		}
	}

	for(int y = 0; y < ALTURA; y++){
		for(int x = 0; x < LARGURA; x++){
			int i = x+(y*LARGURA);
			caminhos[i][i] = 0;
			_proximo[i][i] = i;

			//Define a distancia entre vizinhos e o atual como 1
			if(_mapa[x][y] != Parede){
				if(x+1 < LARGURA && _mapa[x+1][y]!=Parede){
					int iv = (x+1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(x == LARGURA){
					int iv = 0+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(x-1 >= 0 && _mapa[x-1][y]!=Parede){
					int iv = (x-1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(x == 0){
					int iv = (LARGURA-1)+(y*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(y+1 < ALTURA && _mapa[x][y+1]!=Parede){
					int iv = x +((y+1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(y == ALTURA){
					int iv = x+(0*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}

				if(y-1 >= 0 && _mapa[x][y-1]!=Parede){
					int iv = x +((y-1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}else if(y == 0){
					int iv = x+((ALTURA-1)*LARGURA);
					caminhos[i][iv] = 1;
					caminhos[iv][i] = 1;
					_proximo[i][iv] = iv;
					_proximo[iv][i] = i;
				}
			}			
		}
	}

	for(int k = 0; k < LARGURA*ALTURA; k++){
		for(int i = 0; i < LARGURA*ALTURA; i++){
			for(int j = 0; j < LARGURA*ALTURA; j++){
				if(caminhos[i][j] > caminhos[i][k] + caminhos[k][j]){
					caminhos[i][j] = caminhos[i][k] + caminhos[k][j];
					_proximo[i][j] = _proximo[i][k];
				}
			}
		}
	}

	for(int i = 0; i < LARGURA*ALTURA; i++){
		free(caminhos[i]);
	}
	free(caminhos);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
movl $0x11b8, %edi           # imm = 0x11B8
callq 0x8040
movq %rax, %r15
xorl %ebx, %ebx
movl $0x8dc, %edi            # imm = 0x8DC
callq 0x8040
movq %rax, (%r15,%rbx,8)
incq %rbx
cmpq $0x237, %rbx            # imm = 0x237
jne 0xbf56
leaq 0x1218(%r14), %rdi
xorl %eax, %eax
movq %rdi, %rcx
movq (%r15,%rax,8), %rdx
xorl %esi, %esi
movl $0x3fffffff, (%rdx,%rsi,4) # imm = 0x3FFFFFFF
movl $0xffffffff, (%rcx,%rsi,4) # imm = 0xFFFFFFFF
incq %rsi
cmpq $0x237, %rsi            # imm = 0x237
jne 0xbf82
incq %rax
addq $0x8dc, %rcx            # imm = 0x8DC
cmpq $0x237, %rax            # imm = 0x237
jne 0xbf7c
leaq 0x8(%r14), %rax
movq %rax, -0xa8(%rbp)
movl $0x1218, %edx           # imm = 0x1218
movl $0x8, %r9d
movl $0x1aa0, %ecx           # imm = 0x1AA0
movl $0x90c, %r8d            # imm = 0x90C
xorl %r12d, %r12d
movq %rdi, -0x68(%rbp)
movq %rdi, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movq %r15, -0x40(%rbp)
xorl %esi, %esi
leaq (%rsi,%rsi,4), %rax
leaq (%rsi,%rax,4), %rdi
movq %rdi, -0x98(%rbp)
leaq (%rsi,%rax,4), %rax
addq $0x14, %rax
movq %rax, -0xa0(%rbp)
leaq 0x1(%rsi), %rax
movq %rax, -0x70(%rbp)
movq %rsi, -0x50(%rbp)
leal -0x1(%rsi), %eax
movl %eax, -0x54(%rbp)
movl $0x8, %esi
movq %r8, -0x78(%rbp)
movq %rcx, -0x80(%rbp)
movq %r9, -0x88(%rbp)
movq %r9, %rdi
movq %rdx, -0x90(%rbp)
movq %rdx, %rax
xorl %r15d, %r15d
movq %r12, -0x60(%rbp)
movq -0x40(%rbp), %rdx
movq (%rdx,%r15,8), %r10
movq -0x30(%rbp), %rdx
leaq (%r10,%rdx), %rbx
movl $0x0, (%rbx,%r15,4)
leaq (%r12,%r15), %r11
movl %r11d, (%r14,%rax)
cmpl $0x1, (%r14,%rdi)
je 0xc1ff
movl $0x13, %r9d
cmpq $0x14, %r15
je 0xc0c9
cmpl $0x1, 0x6c(%r14,%rdi)
je 0xc0b2
movl $0x1, %r9d
movl %r9d, 0x4(%rbx,%r15,4)
movq -0x40(%rbp), %rdx
movq 0x8(%rdx,%r15,8), %rdx
addq -0x30(%rbp), %rdx
movl %r9d, (%rdx,%r15,4)
leal (%r12,%r15), %edx
incl %edx
movl %edx, 0x4(%r14,%rax)
movl %r11d, 0x8dc(%r14,%rax)
movq %r15, %r9
movq -0xa0(%rbp), %rdx
movq %rdx, %r13
subq $0x1, %r9
jb 0xc0ef
movq -0x60(%rbp), %r12
movl %r9d, %edx
imulq $0x6c, %rdx, %rdx
addq -0xa8(%rbp), %rdx
movq -0x50(%rbp), %r13
cmpl $0x1, (%rdx,%r13,4)
je 0xc12b
addl -0x98(%rbp), %r9d
movslq %r9d, %r13
movl %r9d, %edx
movl $0x1, %r12d
movl %r12d, (%r10,%r13,4)
movq -0x38(%rbp), %r9
movq (%r9,%r13,8), %r9
addq -0x30(%rbp), %r9
movl %r12d, (%r9,%r15,4)
movq -0x48(%rbp), %r12
leaq (%r14,%r13,4), %r9
movl %edx, (%r9,%r8,2)
imulq $0x8dc, %r13, %rdx      # imm = 0x8DC
addq %r12, %rdx
movl %r11d, (%rdx,%r15,4)
movq -0x60(%rbp), %r12
movq -0x50(%rbp), %r13
movl $0x19, %r9d
cmpq $0x1a, %r13
je 0xc17f
cmpl $0x1, 0x4(%r14,%rdi)
je 0xc176
movl $0x1, %r9d
movl %r9d, 0x54(%rbx,%r15,4)
movq -0x40(%rbp), %rdx
movq 0xa8(%rdx,%r15,8), %rdx
addq -0x30(%rbp), %rdx
movl %r9d, (%rdx,%r15,4)
leal (%r12,%r15), %edx
addl $0x15, %edx
movl %edx, 0x54(%r14,%rax)
movq -0x50(%rbp), %r13
movl %r11d, 0xba0c(%r14,%rax)
movl -0x54(%rbp), %r9d
testq %r13, %r13
je 0xc1c4
movl %r9d, %edx
leaq (%r14,%rdx,4), %rdx
cmpl $0x1, (%rsi,%rdx)
je 0xc1ff
leal (%r9,%r9,4), %edx
leal (%r9,%rdx,4), %edx
leal (%r15,%rdx), %r9d
movslq %r9d, %r9
movl $0x1, %ebx
movl %ebx, (%r10,%r9,4)
movq -0x38(%rbp), %r10
movq (%r10,%r9,8), %r10
addq -0x30(%rbp), %r10
movl %ebx, (%r10,%r15,4)
addl %r15d, %edx
movslq %edx, %rdx
leaq (%r14,%rdx,4), %rdx
movl %r9d, (%rdx,%r8,2)
jmp 0xc1f0
leaq 0x222(%r15), %r9
movl $0x1, %ebx
movl %ebx, 0x888(%r10,%r15,4)
movq -0x38(%rbp), %rdx
movq 0x1110(%rdx,%r15,8), %rdx
addq -0x30(%rbp), %rdx
movl %ebx, (%rdx,%r15,4)
movl %r9d, (%r14,%rcx)
imulq $0x8dc, %r9, %rdx       # imm = 0x8DC
addq -0x48(%rbp), %rdx
movl %r11d, (%rdx,%r15,4)
incq %r15
movl $0x8e0, %edx            # imm = 0x8E0
addq %rdx, %rax
addq $0x6c, %rdi
addq %rdx, %rcx
addq $0x46e, %r8             # imm = 0x46E
addq $0x6c, %rsi
cmpq $0x15, %r15
jne 0xc044
addq $0xa8, -0x40(%rbp)
addq $0x54, -0x30(%rbp)
movq -0x90(%rbp), %rdx
addq $0xba60, %rdx           # imm = 0xBA60
addq $0x15, %r12
movq -0x88(%rbp), %r9
addq $0x4, %r9
movq -0x80(%rbp), %rcx
addq $0xba0c, %rcx           # imm = 0xBA0C
addq $0x54, -0x48(%rbp)
movq -0x78(%rbp), %r8
addq $0x5d06, %r8            # imm = 0x5D06
movq -0x70(%rbp), %rax
movq %rax, %rsi
cmpq $0x1b, %rax
jne 0xbfec
xorl %eax, %eax
movq -0x38(%rbp), %r14
movq -0x68(%rbp), %r11
movq (%r14,%rax,8), %rcx
movq %r11, %rdx
xorl %esi, %esi
movq (%r14,%rsi,8), %rdi
imulq $0x8dc, %rsi, %r8       # imm = 0x8DC
addq %r11, %r8
leaq (%r8,%rax,4), %r8
xorl %r9d, %r9d
movl (%rcx,%r9,4), %r10d
addl (%rdi,%rax,4), %r10d
cmpl %r10d, (%rdi,%r9,4)
jle 0xc2bd
movl %r10d, (%rdi,%r9,4)
movl (%r8), %r10d
movl %r10d, (%rdx,%r9,4)
incq %r9
cmpq $0x237, %r9             # imm = 0x237
jne 0xc2a4
incq %rsi
addq $0x8dc, %rdx            # imm = 0x8DC
cmpq $0x237, %rsi            # imm = 0x237
jne 0xc28f
incq %rax
cmpq $0x237, %rax            # imm = 0x237
jne 0xc286
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
callq 0x89d0
incq %rbx
cmpq $0x237, %rbx            # imm = 0x237
jne 0xc2e9
movq %r14, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x89d0
nop