// File: /workspace/github_c_makefile_star2_O0/j4r0g[P]Projet_Labyrinthe/fonctions/deplacement.c
// Function: pluscourte_dist
int pluscourte_dist(t_lab labyrinthe[X][Y], int xdep, int ydep, int xarr, int yarr, int* xdir, int *ydir)  {
	int matr_dist[X][Y];
	int i, j;
	int xcur, ycur;
	int dist = 0;
	int parcouru=0;
	for(i=0; i<X; i++){				/*initialisation de la matrice*/
		for(j=0; j<Y; j++){
			matr_dist[i][j]=-2;
		}
	}

	matr_dist[xdep][ydep]=0;

	while (parcouru==0){
		//printf("dist : %i\n", dist);
		dist++;
		parcouru=1;
		for (i=0; i<X; i++){
			for(j=0; j<Y; j++){

				if (labyrinthe[i][j].etat==mur){
					matr_dist[i][j]=-1;
				}
				if (i==xdep && j==ydep && dist==1) {		/*si on est au début, on fixe la distance à 0*/
					if (matr_dist[i-1][j]==-2){
						matr_dist[i-1][j]=dist;
					}if (matr_dist[i][j-1]==-2){
						matr_dist[i][j-1]=dist;
					}if (matr_dist[i][j+1]==-2){
						matr_dist[i][j+1]=dist;
					}if (matr_dist[i+1][j]==-2) {
						matr_dist[i+1][j]=dist;
					}
				}
				else if (matr_dist[i][j]==dist-1 && dist>1){		/*sinon on indique la distance en cercles concentriques*/
					if (matr_dist[i-1][j]==-2 && i-1>=0){
						matr_dist[i-1][j]=dist;
					}if (matr_dist[i][j-1]==-2 && j-1>=0){
						matr_dist[i][j-1]=dist;
					}if (matr_dist[i][j+1]==-2 && j+1<Y){
						matr_dist[i][j+1]=dist;
					}if (matr_dist[i+1][j]==-2 && i+1<X) {
						matr_dist[i+1][j]=dist;
					}
				}
				if (matr_dist[i][j]==-2){							//si on a parcouru toute la matrice, on sort de la boucle
					parcouru=0;
				}
			}
		}
	}

	xcur = xarr; ycur=yarr;
	i = 0;
	while(matr_dist[xcur][ycur] != 1 && i<100){								/*On parcourt le chemin en sens inverse pour trouver le prochain déplacement*/
		if(coord_correctes(xcur-1,ycur) && (matr_dist[xcur-1][ycur] == matr_dist[xcur][ycur]-1)){
			xcur--;
		}else if(coord_correctes(xcur+1,ycur) && (matr_dist[xcur+1][ycur] == matr_dist[xcur][ycur]-1)){
			xcur++;
		}else if(coord_correctes(xcur,ycur-1) && (matr_dist[xcur][ycur-1] == matr_dist[xcur][ycur]-1)){
			ycur--;
		}else if(coord_correctes(xcur,ycur+1) && (matr_dist[xcur][ycur+1] == matr_dist[xcur][ycur]-1)){
			ycur++;
		}
		i++;
		/*if(i>20){
			break;
		}*/
	}
	*xdir = xcur; *ydir=ycur;
	return matr_dist[xarr][yarr];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c60, %rsp           # imm = 0x1C60
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movl $0x0, -0x1c54(%rbp)
movl $0x0, -0x1c58(%rbp)
movl $0x0, -0x1c44(%rbp)
cmpl $0x1e, -0x1c44(%rbp)
jge 0x3d68
movl $0x0, -0x1c48(%rbp)
cmpl $0x3c, -0x1c48(%rbp)
jge 0x3d55
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl $0xfffffffe, (%rax,%rcx,4) # imm = 0xFFFFFFFE
movl -0x1c48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c48(%rbp)
jmp 0x3d15
jmp 0x3d57
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c44(%rbp)
jmp 0x3d02
movslq -0xc(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
cmpl $0x0, -0x1c58(%rbp)
jne 0x41ef
movl -0x1c54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c54(%rbp)
movl $0x1, -0x1c58(%rbp)
movl $0x0, -0x1c44(%rbp)
cmpl $0x1e, -0x1c44(%rbp)
jge 0x41ea
movl $0x0, -0x1c48(%rbp)
cmpl $0x3c, -0x1c48(%rbp)
jge 0x41d4
movq -0x8(%rbp), %rax
movslq -0x1c44(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x23, 0x4(%rax)
jne 0x3e2b
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x1c44(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0x3fb7
movl -0x1c48(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x3fb7
cmpl $0x1, -0x1c54(%rbp)
jne 0x3fb7
movl -0x1c44(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x3ead
movl -0x1c54(%rbp), %edx
movl -0x1c44(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x3f04
movl -0x1c54(%rbp), %edx
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x3f5b
movl -0x1c54(%rbp), %edx
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x3fb2
movl -0x1c54(%rbp), %edx
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x418f
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x1c54(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x418d
cmpl $0x1, -0x1c54(%rbp)
jle 0x418d
movl -0x1c44(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x405c
movl -0x1c44(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x405c
movl -0x1c54(%rbp), %edx
movl -0x1c44(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x40c1
movl -0x1c48(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jl 0x40c1
movl -0x1c54(%rbp), %edx
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x4126
movl -0x1c48(%rbp), %eax
addl $0x1, %eax
cmpl $0x3c, %eax
jge 0x4126
movl -0x1c54(%rbp), %edx
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c48(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x418b
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
cmpl $0x1e, %eax
jge 0x418b
movl -0x1c54(%rbp), %edx
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x418d
jmp 0x418f
movslq -0x1c44(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c48(%rbp), %rcx
cmpl $-0x2, (%rax,%rcx,4)
jne 0x41be
movl $0x0, -0x1c58(%rbp)
jmp 0x41c0
movl -0x1c48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c48(%rbp)
jmp 0x3dcf
jmp 0x41d6
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c44(%rbp)
jmp 0x3db8
jmp 0x3d88
movl -0x14(%rbp), %eax
movl %eax, -0x1c4c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x1c50(%rbp)
movl $0x0, -0x1c44(%rbp)
movslq -0x1c4c(%rbp), %rax
leaq -0x1c40(%rbp), %rcx
imulq $0xf0, %rax, %rax
addq %rax, %rcx
movslq -0x1c50(%rbp), %rdx
xorl %eax, %eax
cmpl $0x1, (%rcx,%rdx,4)
movb %al, -0x1c59(%rbp)
je 0x4248
cmpl $0x64, -0x1c44(%rbp)
setl %al
movb %al, -0x1c59(%rbp)
movb -0x1c59(%rbp), %al
testb $0x1, %al
jne 0x4257
jmp 0x445d
movl -0x1c4c(%rbp), %edi
subl $0x1, %edi
movl -0x1c50(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x42d4
movl -0x1c4c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movslq -0x1c4c(%rbp), %rdx
leaq -0x1c40(%rbp), %rcx
imulq $0xf0, %rdx, %rdx
addq %rdx, %rcx
movslq -0x1c50(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x42d4
movl -0x1c4c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c4c(%rbp)
jmp 0x4449
movl -0x1c4c(%rbp), %edi
addl $0x1, %edi
movl -0x1c50(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x4351
movl -0x1c4c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x1c50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movslq -0x1c4c(%rbp), %rdx
leaq -0x1c40(%rbp), %rcx
imulq $0xf0, %rdx, %rdx
addq %rdx, %rcx
movslq -0x1c50(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4351
movl -0x1c4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c4c(%rbp)
jmp 0x4447
movl -0x1c4c(%rbp), %edi
movl -0x1c50(%rbp), %esi
subl $0x1, %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x43cb
movslq -0x1c4c(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c50(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movslq -0x1c4c(%rbp), %rdx
leaq -0x1c40(%rbp), %rcx
imulq $0xf0, %rdx, %rdx
addq %rdx, %rcx
movslq -0x1c50(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x43cb
movl -0x1c50(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c50(%rbp)
jmp 0x4445
movl -0x1c4c(%rbp), %edi
movl -0x1c50(%rbp), %esi
addl $0x1, %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x4443
movslq -0x1c4c(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movl -0x1c50(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movslq -0x1c4c(%rbp), %rdx
leaq -0x1c40(%rbp), %rcx
imulq $0xf0, %rdx, %rdx
addq %rdx, %rcx
movslq -0x1c50(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x4443
movl -0x1c50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c50(%rbp)
jmp 0x4445
jmp 0x4447
jmp 0x4449
movl -0x1c44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c44(%rbp)
jmp 0x420b
movl -0x1c4c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x1c50(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movslq -0x14(%rbp), %rcx
leaq -0x1c40(%rbp), %rax
imulq $0xf0, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addq $0x1c60, %rsp           # imm = 0x1C60
popq %rbp
retq
nopw (%rax,%rax)