// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %r14
movl $0x11b8, %edi           # imm = 0x11B8
callq 0x8040
movq %rax, %rbx
xorl %r15d, %r15d
movl $0x8dc, %edi            # imm = 0x8DC
callq 0x8040
movq %rax, (%rbx,%r15,8)
incq %r15
cmpq $0x237, %r15            # imm = 0x237
jne 0xbf68
leaq 0x1218(%r14), %rax
xorl %ecx, %ecx
movq (%rbx,%rcx,8), %rdx
xorl %esi, %esi
movl $0x3fffffff, (%rdx,%rsi,4) # imm = 0x3FFFFFFF
movl $0xffffffff, (%rax,%rsi,4) # imm = 0xFFFFFFFF
incq %rsi
cmpq $0x237, %rsi            # imm = 0x237
jne 0xbf91
incq %rcx
addq $0x8dc, %rax            # imm = 0x8DC
cmpq $0x237, %rcx            # imm = 0x237
jne 0xbf8b
leaq 0x1218(%r14), %rdx
xorl %ecx, %ecx
movq %r14, -0x38(%rbp)
movq %r14, %rsi
xorl %edi, %edi
movq %rbx, %r8
movq %rdx, %r9
movq %rdx, %r10
xorl %r15d, %r15d
leaq (%r15,%r15,4), %rax
leaq (%r15,%rax,4), %r11
movq %r11, -0x30(%rbp)
leaq (%r15,%rax,4), %r11
addq $0x14, %r11
movq %r11, -0x60(%rbp)
leaq 0x1(%r15), %r11
movq %r11, -0x40(%rbp)
leaq -0x15(%r15,%rax,4), %rax
movq %rax, -0x68(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
movq %rdx, %rax
movq %r9, -0x48(%rbp)
xorl %r13d, %r13d
movq %r10, -0x70(%rbp)
movq (%r8,%r13,8), %r11
leaq (%r11,%rdi), %r12
movl $0x0, (%r12,%r13,4)
leal (%rcx,%r13), %edx
movl %edx, (%rax)
cmpl $0x1, 0x8(%rsi)
je 0xc155
cmpq $0x14, %r13
je 0xc072
cmpl $0x1, 0x74(%rsi)
je 0xc072
movl $0x1, %r14d
movl %r14d, 0x4(%r12,%r13,4)
movq 0x8(%r8,%r13,8), %rdx
addq %rdi, %rdx
movl %r14d, (%rdx,%r13,4)
leal (%rcx,%r13), %edx
leal (%rcx,%r13), %r14d
incl %r14d
movl %r14d, 0x4(%rax)
movl %edx, 0x8dc(%rax)
testq %r13, %r13
je 0xc08f
cmpl $0x1, -0x64(%rsi)
je 0xc0c5
leaq (%rcx,%r13), %rdx
decq %rdx
movl $0x1, -0x4(%r12,%r13,4)
jmp 0xc0a0
movq -0x30(%rbp), %rdx
movl $0x1, 0x50(%r11,%rdx,4)
movq -0x60(%rbp), %rdx
movq (%rbx,%rdx,8), %r14
addq %rdi, %r14
movl $0x1, (%r14,%r13,4)
movl %edx, (%r9,%rdx,4)
imulq $0x8dc, %rdx, %rdx      # imm = 0x8DC
addq %r10, %rdx
leal (%rcx,%r13), %r14d
movl %r14d, (%rdx,%r13,4)
cmpq $0x1a, %r15
je 0xc106
cmpl $0x1, 0xc(%rsi)
je 0xc101
movl $0x1, %r14d
movl %r14d, 0x54(%r12,%r13,4)
movq 0xa8(%r8,%r13,8), %rdx
addq %rdi, %rdx
movl %r14d, (%rdx,%r13,4)
leal (%rcx,%r13), %edx
leal (%rcx,%r13), %r14d
addl $0x15, %r14d
movl %r14d, 0x54(%rax)
movl %edx, 0xba0c(%rax)
testq %r15, %r15
je 0xc11a
cmpl $0x1, 0x4(%rsi)
je 0xc155
movq -0x30(%rbp), %rdx
leaq (%rdx,%r13), %r12
movq -0x68(%rbp), %rdx
jmp 0xc122
movl $0x222, %edx            # imm = 0x222
movq %r13, %r12
leaq (%rdx,%r13), %r14
movl $0x1, %r10d
movl %r10d, (%r11,%r14,4)
movq (%rbx,%r14,8), %r11
addq %rdi, %r11
movl %r10d, (%r11,%r13,4)
leaq (%r9,%rdx,4), %rdx
movl %r14d, (%rdx,%r13,4)
imulq $0x8dc, %r14, %rdx      # imm = 0x8DC
movq -0x70(%rbp), %r10
addq %r10, %rdx
movl %r12d, (%rdx,%r13,4)
incq %r13
addq $0x8dc, %r9             # imm = 0x8DC
addq $0x8e0, %rax            # imm = 0x8E0
addq $0x6c, %rsi
cmpq $0x15, %r13
jne 0xc01a
addq $0x54, %r10
movq -0x48(%rbp), %r9
addq $0xba0c, %r9            # imm = 0xBA0C
addq $0xa8, %r8
addq $0x54, %rdi
movq -0x58(%rbp), %rdx
addq $0xba60, %rdx           # imm = 0xBA60
addq $0x15, %rcx
movq -0x50(%rbp), %rsi
addq $0x4, %rsi
movq -0x40(%rbp), %rax
movq %rax, %r15
cmpq $0x1b, %rax
jne 0xbfdb
movq -0x38(%rbp), %r11
addq $0x1218, %r11           # imm = 0x1218
xorl %eax, %eax
movq (%rbx,%rax,8), %rcx
movq %r11, %rdx
xorl %esi, %esi
movq (%rbx,%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 0xc1f9
movl %r10d, (%rdi,%r9,4)
movl (%r8), %r10d
movl %r10d, (%rdx,%r9,4)
incq %r9
cmpq $0x237, %r9             # imm = 0x237
jne 0xc1e0
incq %rsi
addq $0x8dc, %rdx            # imm = 0x8DC
cmpq $0x237, %rsi            # imm = 0x237
jne 0xc1cb
incq %rax
cmpq $0x237, %rax            # imm = 0x237
jne 0xc1c2
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0x89d0
incq %r14
cmpq $0x237, %r14            # imm = 0x237
jne 0xc226
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x89d0
nop