// File: /workspace/github_cpp_makefile_star2_O2/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
cmpq $0x237, %rbx            # imm = 0x237
je 0xb954
movl $0x8dc, %edi            # imm = 0x8DC
callq 0x8040
movq %rax, (%r15,%rbx,8)
incq %rbx
jmp 0xb938
leaq 0x1218(%r14), %rcx
xorl %eax, %eax
movq %rcx, -0x60(%rbp)
cmpq $0x237, %rax            # imm = 0x237
je 0xb994
movq (%r15,%rax,8), %rdx
xorl %esi, %esi
cmpq $0x237, %rsi            # imm = 0x237
je 0xb988
movl $0x3fffffff, (%rdx,%rsi,4) # imm = 0x3FFFFFFF
orl $-0x1, (%rcx,%rsi,4)
incq %rsi
jmp 0xb96f
incq %rax
addq $0x8dc, %rcx            # imm = 0x8DC
jmp 0xb961
leaq 0x8(%r14), %rax
movq %rax, -0xa8(%rbp)
movl $0x1218, %r13d          # imm = 0x1218
pushq $0x8
popq %r11
movl $0x90c, %edi            # imm = 0x90C
movl $0x1aa0, %esi           # imm = 0x1AA0
xorl %ebx, %ebx
movq -0x60(%rbp), %rcx
movq %rcx, -0x48(%rbp)
movq $0x0, -0x30(%rbp)
movq %r15, -0x40(%rbp)
xorl %ecx, %ecx
movq %r15, -0x38(%rbp)
cmpq $0x1b, %rcx
je 0xbc44
imulq $0x15, %rcx, %rdx
movq %rdx, -0x98(%rbp)
leaq 0x14(%rdx), %rax
movq %rax, -0xa0(%rbp)
leaq 0x1(%rcx), %rax
movq %rax, -0x70(%rbp)
movq %rcx, -0x50(%rbp)
leal -0x1(%rcx), %eax
movl %eax, -0x54(%rbp)
movq %rsi, -0x80(%rbp)
movq %rdi, -0x88(%rbp)
pushq $0x8
popq %rcx
movq %r11, -0x78(%rbp)
movq %r13, -0x90(%rbp)
xorl %eax, %eax
movq %rbx, -0x68(%rbp)
cmpq $0x15, %rax
je 0xbbf2
movq -0x40(%rbp), %rdx
movq (%rdx,%rax,8), %r10
movq -0x30(%rbp), %rdx
leaq (%r10,%rdx), %r15
andl $0x0, (%r15,%rax,4)
leaq (%rbx,%rax), %r12
movl %r12d, (%r14,%r13)
cmpl $0x1, (%r14,%r11)
je 0xbbcf
pushq $0x13
popq %r8
movl %r8d, %r9d
cmpq $0x14, %rax
je 0xbaaf
cmpl $0x1, 0x6c(%r14,%r11)
je 0xba95
pushq $0x1
popq %r9
movl %r9d, 0x4(%r15,%rax,4)
movq -0x40(%rbp), %rdx
movq 0x8(%rdx,%rax,8), %r8
addq -0x30(%rbp), %r8
movl %r9d, (%r8,%rax,4)
leal (%rbx,%rax), %r8d
incl %r8d
movl %r8d, 0x4(%r14,%r13)
movl %r12d, 0x8dc(%r14,%r13)
movq %rax, %r9
movq -0xa0(%rbp), %rdx
movq %rdx, %rbx
movl %edx, %r8d
subq $0x1, %r9
jb 0xbad5
movq -0x68(%rbp), %rbx
movl %r9d, %r8d
imulq $0x6c, %r8, %r8
addq -0xa8(%rbp), %r8
movq -0x50(%rbp), %rdx
cmpl $0x1, (%r8,%rdx,4)
je 0xbb07
addl -0x98(%rbp), %r9d
movslq %r9d, %rbx
movl %r9d, %r8d
pushq $0x1
popq %rdx
movl %edx, (%r10,%rbx,4)
movq -0x38(%rbp), %r9
movq (%r9,%rbx,8), %r9
addq -0x30(%rbp), %r9
movl %edx, (%r9,%rax,4)
leaq (%r14,%rbx,4), %r9
movl %r8d, (%r9,%rdi,2)
imulq $0x8dc, %rbx, %r8       # imm = 0x8DC
addq -0x48(%rbp), %r8
movl %r12d, (%r8,%rax,4)
movq -0x68(%rbp), %rbx
pushq $0x19
popq %r9
cmpq $0x1a, -0x50(%rbp)
je 0xbb56
cmpl $0x1, 0x4(%r14,%r11)
je 0xbb4b
pushq $0x1
popq %rdx
movl %edx, 0x54(%r15,%rax,4)
movq -0x40(%rbp), %r8
movq 0xa8(%r8,%rax,8), %r8
addq -0x30(%rbp), %r8
movl %edx, (%r8,%rax,4)
leal (%rbx,%rax), %r8d
addl $0x15, %r8d
movl %r8d, 0x54(%r14,%r13)
movl %r12d, 0xba0c(%r14,%r13)
movl -0x54(%rbp), %r9d
cmpq $0x0, -0x50(%rbp)
je 0xbb96
movl %r9d, %r8d
leaq (%r14,%r8,4), %r8
cmpl $0x1, (%rcx,%r8)
je 0xbbcf
imull $0x15, %r9d, %r8d
leal (%rax,%r8), %r9d
movslq %r9d, %r9
pushq $0x1
popq %rdx
movl %edx, (%r10,%r9,4)
movq -0x38(%rbp), %r10
movq (%r10,%r9,8), %r10
addq -0x30(%rbp), %r10
movl %edx, (%r10,%rax,4)
addl %eax, %r8d
movslq %r8d, %r8
leaq (%r14,%r8,4), %r8
movl %r9d, (%r8,%rdi,2)
jmp 0xbbc0
leaq 0x222(%rax), %r9
pushq $0x1
popq %rdx
movl %edx, 0x888(%r10,%rax,4)
movq -0x38(%rbp), %r8
movq 0x1110(%r8,%rax,8), %r8
addq -0x30(%rbp), %r8
movl %edx, (%r8,%rax,4)
movl %r9d, (%r14,%rsi)
imulq $0x8dc, %r9, %r8        # imm = 0x8DC
addq -0x48(%rbp), %r8
movl %r12d, (%r8,%rax,4)
movl $0x8e0, %r8d            # imm = 0x8E0
addq %r8, %r13
addq $0x6c, %r11
addq $0x6c, %rcx
addq $0x46e, %rdi            # imm = 0x46E
addq %r8, %rsi
incq %rax
jmp 0xba20
addq $0xa8, -0x40(%rbp)
addq $0x54, -0x30(%rbp)
movq -0x90(%rbp), %r13
addq $0xba60, %r13           # imm = 0xBA60
addq $0x15, %rbx
movq -0x78(%rbp), %r11
addq $0x4, %r11
addq $0x54, -0x48(%rbp)
movq -0x88(%rbp), %rdi
addq $0x5d06, %rdi           # imm = 0x5D06
movq -0x80(%rbp), %rsi
addq $0xba0c, %rsi           # imm = 0xBA0C
movq -0x70(%rbp), %rcx
movq -0x38(%rbp), %r15
jmp 0xb9cf
xorl %eax, %eax
movq -0x60(%rbp), %r11
cmpq $0x237, %rax            # imm = 0x237
je 0xbcb1
movq (%r15,%rax,8), %rcx
movq %r11, %rdx
xorl %esi, %esi
cmpq $0x237, %rsi            # imm = 0x237
je 0xbcac
movq (%r15,%rsi,8), %rdi
imulq $0x8dc, %rsi, %r8       # imm = 0x8DC
addq %r11, %r8
leaq (%r8,%rax,4), %r8
xorl %r9d, %r9d
cmpq $0x237, %r9             # imm = 0x237
je 0xbca0
movl (%rcx,%r9,4), %r10d
addl (%rdi,%rax,4), %r10d
cmpl %r10d, (%rdi,%r9,4)
jle 0xbc9b
movl %r10d, (%rdi,%r9,4)
movl (%r8), %r10d
movl %r10d, (%rdx,%r9,4)
incq %r9
jmp 0xbc79
incq %rsi
addq $0x8dc, %rdx            # imm = 0x8DC
jmp 0xbc5b
incq %rax
jmp 0xbc4a
xorl %ebx, %ebx
cmpq $0x237, %rbx            # imm = 0x237
je 0xbcca
movq (%r15,%rbx,8), %rdi
callq 0x89d0
incq %rbx
jmp 0xbcb3
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x89d0
nop