// File: /workspace/github_c_makefile_star2_O0/j4r0g[P]Projet_Labyrinthe/fonctions/deplacement.c
// Function: deplacement
void deplacement (t_lab lab[X][Y], int pos_x, int pos_y, t_fourmi fourmi[], int bouffe, int dureevie) {
	int i, j, xdir, ydir, dist;
	typedef struct {int dist; int x; int y;} nourr;
	int ins_adj = insecte_adjacent(pos_x, pos_y, lab, bouffe, dureevie, fourmi);	//ins_adj vaut 1 si il y a un insecte a coté, 0 sinon.
	if(nourriture_pres(lab)){
		int nb_nourr = 0;
		nourr plusproche;
		nourr interet[50];
		for (i=0; i<X; i++) {														//on parcourt la matrice pour trouver toutes les cases de nourriture ou les insectes proches
			for (j=0; j<Y; j++) {
				if (coord_correctes(i, j) && lab[i][j].etat==food){

					dist=pluscourte_dist(lab, pos_x, pos_y, i, j, &xdir, &ydir);

						interet[nb_nourr].dist=dist;
						interet[nb_nourr].x=xdir;
						interet[nb_nourr].y=ydir;
						nb_nourr++;

				}
			}
		}

		plusproche.dist=interet[0].dist;
		plusproche.x=interet[0].x;
		plusproche.y=interet[0].y;
		for (i=1; i<nb_nourr; i++){									/*on parcourt le tableau pour trouver la nourriture la plus proche*/
			if (interet[i].dist<plusproche.dist){
				plusproche.dist=interet[i].dist;
				plusproche.x=interet[i].x;
				plusproche.y=interet[i].y;

			}
		}
		dist=pluscourte_dist(lab, pos_x, pos_y, plusproche.x, plusproche.y, &xdir, &ydir);
		if (nourriture_pres(lab) && dist<20) {
			modif_pos(lab, fourmi, pos_x, pos_y, plusproche.x, plusproche.y, bouffe, dureevie);
		}
		else {
			prochain_deplacement(pos_x, pos_y, lab, bouffe, dureevie, fourmi);
		}
	}
	else {
		prochain_deplacement(pos_x, pos_y, lab, bouffe, dureevie, fourmi);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movq -0x18(%rbp), %r9
callq 0x3460
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x39c0
cmpl $0x0, %eax
je 0x3c9d
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1e, -0x24(%rbp)
jge 0x3b85
movl $0x0, -0x28(%rbp)
cmpl $0x3c, -0x28(%rbp)
jge 0x3b75
movl -0x24(%rbp), %edi
movl -0x28(%rbp), %esi
callq 0x13c0
cmpl $0x0, %eax
je 0x3b65
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2a, 0x4(%rax)
jne 0x3b65
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %r8d
leaq -0x2c(%rbp), %r9
leaq -0x30(%rbp), %rax
movq %rax, (%rsp)
callq 0x3cc0
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movslq -0x3c(%rbp), %rdx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movslq -0x3c(%rbp), %rdx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x30(%rbp), %ecx
movslq -0x3c(%rbp), %rdx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3b67
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3aaf
jmp 0x3b77
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3a9e
movl -0x2a0(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x29c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x298(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x3c1c
movslq -0x24(%rbp), %rcx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x48(%rbp), %eax
jge 0x3c0f
movslq -0x24(%rbp), %rcx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movslq -0x24(%rbp), %rcx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movslq -0x24(%rbp), %rcx
leaq -0x2a0(%rbp), %rax
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0x3c11
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3ba7
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x44(%rbp), %ecx
movl -0x40(%rbp), %r8d
leaq -0x2c(%rbp), %r9
leaq -0x30(%rbp), %rax
movq %rax, (%rsp)
callq 0x3cc0
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
callq 0x39c0
cmpl $0x0, %eax
je 0x3c81
cmpl $0x14, -0x34(%rbp)
jge 0x3c81
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0xc(%rbp), %edx
movl -0x10(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x40(%rbp), %r9d
movl -0x1c(%rbp), %r10d
movl -0x20(%rbp), %eax
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x4d40
jmp 0x3c9b
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movq -0x18(%rbp), %r9
callq 0x3600
jmp 0x3cb7
movl -0xc(%rbp), %edi
movl -0x10(%rbp), %esi
movq -0x8(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
movq -0x18(%rbp), %r9
callq 0x3600
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq