// File: /workspace/github_c_makefile_star2_O1/S01den[P]Lost_CavernRL/ennemy.c
// Function: moveRand
void moveRand(Ennemy ennemies[], Map map[LONGUEUR][LARGEUR], int indice) 
{
	if(ennemies[indice].type == 1 || ennemies[indice].type == 3)
	{
		int movX = 2;
		int movY = 2;

		while((movX == 2 || movY == 2) && (ennemies[indice].x+movX <= 0 || ennemies[indice].x+movX >= LONGUEUR) && (ennemies[indice].y+movY <= 0 || ennemies[indice].y+movY >= LARGEUR))
		{
			movX = rand()%5-2;
			movY = rand()%5-2;		
		}
		
		if(ennemies[indice].x+movX >= 0 && ennemies[indice].x+movX <= LONGUEUR && ennemies[indice].y+movY >= 0 && ennemies[indice].y+movY <= LARGEUR)
		{
			if(map[ennemies[indice].x+movX][ennemies[indice].y+movY].content == WALL)
			{
				if(ennemies[indice].x-1 > 0 && ennemies[indice].x+1 < LONGUEUR && ennemies[indice].y+1 > 0 && ennemies[indice].y+1 < LARGEUR)
				{	
					if(map[ennemies[indice].x+1][ennemies[indice].y+movY].content != WALL)
					{
						movX = 1;
						ennemies[indice].x += movX;
						ennemies[indice].y += movY;
					}
					else if(map[ennemies[indice].x-1][ennemies[indice].y+movY].content != WALL)
					{
						if(ennemies[indice].x-1 > 0 && ennemies[indice].x-1 < LONGUEUR && ennemies[indice].y+movY > 0 && ennemies[indice].y+movY < LARGEUR)
						{
							movX = -1;
							ennemies[indice].x += movX;
							ennemies[indice].y += movY;
						}		
					}
					else if(map[ennemies[indice].x][ennemies[indice].y+1].content != WALL)
					{
						if(ennemies[indice].x > 0 && ennemies[indice].x < LONGUEUR && ennemies[indice].y+1 > 0 && ennemies[indice].y+1 < LARGEUR)
						{
							movY = 1;
							ennemies[indice].x += movX;
							ennemies[indice].y += movY;
						}		
					}
					else if(map[ennemies[indice].x][ennemies[indice].y-1].content != WALL)
					{
						if(ennemies[indice].x > 0 && ennemies[indice].x < LONGUEUR && ennemies[indice].y-1 > 0 && ennemies[indice].y-1 < LARGEUR)
						{
							movY = -1;
							ennemies[indice].x += movX;
							ennemies[indice].y += movY;
						}		
					}
				}
			}
			else
			{
				ennemies[indice].x += movX;
				ennemies[indice].y += movY;	
			}
		}

		if(map[ennemies[indice].x][ennemies[indice].y].content == MINES)
		{
			map[ennemies[indice].x][ennemies[indice].y].content = FLOOR;
			ennemies[indice].life -= 20;
		}
	}
}

// Assembly:
movslq %edx, %rax
imulq $0x38, %rax, %rax
movl 0x20(%rdi,%rax), %ecx
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x5791
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
addq %rax, %rbx
movl $0x2, %eax
movl $0xffffff7e, %ebp       # imm = 0xFFFFFF7E
movl $0x2, %r15d
movl (%rbx), %ecx
addl %r15d, %ecx
addl $-0x27, %ecx
cmpl $-0x27, %ecx
ja 0x567d
movl 0x4(%rbx), %ecx
addl %eax, %ecx
addl %ebp, %ecx
cmpl %ebp, %ecx
ja 0x567d
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
leal (%rax,%rcx), %r15d
addl $-0x2, %r15d
callq 0x11d0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
addl %ecx, %eax
addl $-0x2, %eax
cmpl $0x2, %r15d
sete %cl
cmpl $0x2, %eax
sete %dl
orb %cl, %dl
jne 0x5607
movl (%rbx), %edx
addl %edx, %r15d
cmpl $0x27, %r15d
ja 0x5756
movslq 0x4(%rbx), %rcx
addl %ecx, %eax
cmpl $0x82, %eax
ja 0x5756
movl %r15d, %esi
movl %eax, %r8d
imulq $0xe38, %rsi, %rsi      # imm = 0xE38
addq %r14, %rsi
leaq (%r8,%r8,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %r8, %rdi
cmpl $0x2, (%rsi,%rdi)
jne 0x574e
cmpl $0x2, %edx
jl 0x5756
cmpl $0x25, %edx
jg 0x5756
cmpl $0x80, %ecx
ja 0x5756
leaq 0x1(%rdx), %rsi
imulq $0xe38, %rsi, %r8       # imm = 0xE38
addq %r14, %r8
cmpl $0x2, (%r8,%rdi)
jne 0x5751
leal -0x1(%rdx), %esi
movl %esi, %r8d
imulq $0xe38, %r8, %r8        # imm = 0xE38
addq %r14, %r8
cmpl $0x2, (%r8,%rdi)
jne 0x5792
leal 0x1(%rcx), %eax
movl %eax, %esi
imulq $0xe38, %rdx, %rdx      # imm = 0xE38
addq %r14, %rdx
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
cmpl $0x2, (%rdx,%rdi)
jne 0x574e
cmpl $0x2, %ecx
jl 0x5756
leaq -0x1(%rcx), %rax
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rsi, %rcx
decq %rcx
cmpl $0x2, (%rdx,%rcx)
movl %r15d, %esi
jne 0x5751
jmp 0x5756
movl %r15d, %esi
movl %esi, (%rbx)
movl %eax, 0x4(%rbx)
movslq (%rbx), %rax
movslq 0x4(%rbx), %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %rax, %r14
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rax
addq %rcx, %rax
cmpl $0x4, (%r14,%rax)
jne 0x5787
addq %rax, %r14
movl $0x1, (%r14)
addl $-0x14, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
testb %al, %al
je 0x5756
movzbl %al, %ecx
cmpl $0x82, %ecx
je 0x5756
jmp 0x5751