// File: /workspace/github_c_makefile_star2_O1/j4r0g[P]Projet_Labyrinthe/fonctions/deplacement.c
// Function: prochain_deplacement
int prochain_deplacement (int pos_x, int pos_y, t_lab lab[X][Y], int bouffe, int dureevie, t_fourmi fourmi[]) {
	printf("prochian_deplacement\n");
	int ins_adj = insecte_adjacent(pos_x, pos_y, lab, bouffe, dureevie, fourmi);
	int depl=0;
	time_t t;
	srand((unsigned) time(&t));
	int random = rand()%100;
	if (lab[pos_x-1][pos_y].etat != mur || lab[pos_x][pos_y-1].etat != mur || lab[pos_x][pos_y+1].etat != mur || (lab[pos_x+1][pos_y].etat != mur && ins_adj==0)) {
		while(depl==0) {
			if (random >= 0 && random < 25 && lab[pos_x-1][pos_y].etat!=mur && lab[pos_x-1][pos_y].etat!=insecte) {
				modif_pos(lab, fourmi, pos_x, pos_y, pos_x-1, pos_y, bouffe, dureevie);
				depl=1;
			}
			else if (random >= 25 && random < 50 && lab[pos_x][pos_y-1].etat!=mur && lab[pos_x][pos_y-1].etat!=insecte) {
				modif_pos(lab, fourmi, pos_x, pos_y, pos_x, pos_y-1, bouffe, dureevie);
				depl=1;
			}
			else if (random >= 50 && random < 75 && lab[pos_x][pos_y+1].etat!=mur && lab[pos_x][pos_y+1].etat!=insecte) {
				modif_pos(lab, fourmi, pos_x, pos_y, pos_x, pos_y+1, bouffe, dureevie);
				depl=1;
			}
			else if (random >= 75 && random < 100 && lab[pos_x+1][pos_y].etat!=mur && lab[pos_x+1][pos_y].etat!=insecte) {
				modif_pos(lab, fourmi, pos_x, pos_y, pos_x+1, pos_y, bouffe, dureevie);
				depl=1;
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %rbx
movl %r8d, %r13d
movl %ecx, %r14d
movq %rdx, %rbp
movl %esi, %r15d
movl %edi, %r12d
leaq 0x4102(%rip), %rdi      # 0x6721
callq 0x1070
movl %r12d, %edi
movl %r15d, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl %r13d, %r8d
movq %rbx, 0x18(%rsp)
movq %rbx, %r9
callq 0x2569
movl %eax, %ebx
leaq 0x20(%rsp), %rdi
callq 0x1100
movl %eax, %edi
callq 0x10d0
callq 0x1170
leal -0x1(%r12), %r8d
movslq %r8d, %rcx
movslq %r15d, %rdx
imulq $0x2d0, %rcx, %rcx      # imm = 0x2D0
addq %rbp, %rcx
leaq (%rdx,%rdx,2), %rsi
cmpl $0x23, 0x4(%rcx,%rsi,4)
movslq %r12d, %r11
jne 0x26bf
leal -0x1(%r15), %edx
movslq %edx, %rdi
imulq $0x2d0, %r11, %rdx      # imm = 0x2D0
addq %rbp, %rdx
leaq (%rdi,%rdi,2), %rdi
cmpl $0x23, 0x4(%rdx,%rdi,4)
jne 0x26bf
leal 0x1(%r15), %edi
movslq %edi, %rdi
leaq (%rdi,%rdi,2), %rdi
cmpl $0x23, 0x4(%rdx,%rdi,4)
jne 0x26bf
cmpl $0x23, 0x2d4(%rdx,%rsi,4)
je 0x27ec
testl %ebx, %ebx
jne 0x27ec
movq %r13, 0x8(%rsp)
movq %r14, 0x10(%rsp)
cltq
imulq $0x51eb851f, %rax, %rdx # imm = 0x51EB851F
movq %rdx, %rdi
shrq $0x3f, %rdi
sarq $0x25, %rdx
addl %edi, %edx
imull $0x64, %edx, %edx
subl %edx, %eax
leaq (%rcx,%rsi,4), %rcx
addq $0x4, %rcx
leal -0x19(%rax), %edx
leal -0x1(%r15), %r9d
movslq %r9d, %rdi
imulq $0x2d0, %r11, %r14      # imm = 0x2D0
addq %rbp, %r14
leaq (%rdi,%rdi,2), %rdi
leaq (%r14,%rdi,4), %rdi
addq $0x4, %rdi
leal -0x32(%rax), %ebx
leal 0x1(%r15), %r10d
movslq %r10d, %r13
leaq (%r13,%r13,2), %r13
leaq (%r14,%r13,4), %r14
addq $0x4, %r14
incl %r11d
movslq %r11d, %r13
imulq $0x2d0, %r13, %r13      # imm = 0x2D0
addq %rbp, %r13
leaq 0x4(,%rsi,4), %rsi
addq %r13, %rsi
cmpl $0x18, %eax
ja 0x2752
movl (%rcx), %r13d
cmpl $0x23, %r13d
je 0x2752
cmpl $0x25, %r13d
jne 0x27a1
cmpl $0x18, %edx
ja 0x2766
movl (%rdi), %r13d
cmpl $0x23, %r13d
je 0x2766
cmpl $0x25, %r13d
jne 0x27b4
cmpl $0x18, %ebx
ja 0x277a
movl (%r14), %r13d
cmpl $0x23, %r13d
je 0x277a
cmpl $0x25, %r13d
jne 0x27c7
cmpl $0x4b, %eax
jl 0x273e
movl (%rsi), %r13d
cmpl $0x23, %r13d
je 0x273e
cmpl $0x25, %r13d
je 0x273e
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r11d, %r8d
jmp 0x27af
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r15d, %r9d
jmp 0x27db
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
jmp 0x27db
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r10d, %r9d
pushq 0x8(%rsp)
pushq 0x18(%rsp)
callq 0x3345
addq $0x10, %rsp
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq