// File: /workspace/github_c_makefile_star2_O2/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 0x4f88
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
addq %rax, %rbx
pushq $0x2
popq %r15
movl $0xffffff7e, %r12d      # imm = 0xFFFFFF7E
pushq $0x5
popq %rbp
movl %r15d, %edx
cmpl $0x2, %r15d
sete %al
cmpl $0x2, %edx
sete %cl
orb %al, %cl
movl (%rbx), %eax
cmpb $0x1, %cl
jne 0x4ea4
leal (%r15,%rax), %ecx
addl $-0x27, %ecx
cmpl $-0x27, %ecx
ja 0x4ea4
movl 0x4(%rbx), %ecx
leal (%rdx,%r12), %esi
addl %ecx, %esi
cmpl %r12d, %esi
ja 0x4ea7
callq 0x11d0
cltd
idivl %ebp
movl %edx, %r15d
addl $-0x2, %r15d
callq 0x11d0
cltd
idivl %ebp
addl $-0x2, %edx
jmp 0x4e58
movl 0x4(%rbx), %ecx
addl %eax, %r15d
cmpl $0x27, %r15d
ja 0x4f58
addl %ecx, %edx
cmpl $0x82, %edx
ja 0x4f58
movl %r15d, %esi
movl %edx, %edi
imulq $0xe38, %rsi, %rsi      # imm = 0xE38
addq %r14, %rsi
imulq $0x1c, %rdi, %rdi
cmpl $0x2, (%rdi,%rsi)
jne 0x4f4c
cmpl $0x2, %eax
jl 0x4f58
cmpl $0x25, %eax
ja 0x4f58
cmpl $0x80, %ecx
ja 0x4f58
leaq 0x1(%rax), %rsi
imulq $0xe38, %rsi, %r8       # imm = 0xE38
addq %r14, %r8
cmpl $0x2, (%rdi,%r8)
jne 0x4f4f
leal -0x1(%rax), %esi
movl %esi, %r8d
imulq $0xe38, %r8, %r8        # imm = 0xE38
addq %r14, %r8
cmpl $0x2, (%rdi,%r8)
jne 0x4f89
leal 0x1(%rcx), %edx
movl %edx, %edi
imulq $0xe38, %rax, %rsi      # imm = 0xE38
addq %r14, %rsi
imulq $0x1c, %rdi, %rdi
cmpl $0x2, (%rdi,%rsi)
jne 0x4f4c
cmpl $0x2, %ecx
jb 0x4f58
leal -0x1(%rcx), %edx
movslq %edx, %rdi
imulq $0x1c, %rdi, %rdi
cmpl $0x2, (%rdi,%rsi)
movl %r15d, %esi
jne 0x4f4f
jmp 0x4f58
movl %r15d, %esi
movl %esi, (%rbx)
movl %edx, 0x4(%rbx)
movl %edx, %ecx
movl %esi, %eax
cltq
movslq %ecx, %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %rax, %r14
imulq $0x1c, %rcx, %rax
cmpl $0x4, (%rax,%r14)
jne 0x4f80
addq %rax, %r14
movl $0x1, (%r14)
addl $-0x14, 0x8(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testb %dl, %dl
je 0x4f58
movzbl %dl, %edi
cmpl $0x82, %edi
je 0x4f58
jmp 0x4f4f