// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x20(%rax)
je 0x83f1
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x3, 0x20(%rax)
jne 0x8a03
movl $0x2, -0x18(%rbp)
movl $0x2, -0x1c(%rbp)
cmpl $0x2, -0x18(%rbp)
je 0x8410
xorl %eax, %eax
cmpl $0x2, -0x1c(%rbp)
movb %al, -0x1d(%rbp)
jne 0x848c
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
cmpl $0x0, %eax
jle 0x8447
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
addl -0x18(%rbp), %ecx
xorl %eax, %eax
cmpl $0x27, %ecx
movb %al, -0x1d(%rbp)
jl 0x848c
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
addl -0x1c(%rbp), %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x1e(%rbp)
jle 0x8486
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cmpl $0x82, %eax
setge %al
movb %al, -0x1e(%rbp)
movb -0x1e(%rbp), %al
movb %al, -0x1d(%rbp)
movb -0x1d(%rbp), %al
testb $0x1, %al
jne 0x8495
jmp 0x84c0
callq 0x21e0
movl $0x5, %ecx
cltd
idivl %ecx
subl $0x2, %edx
movl %edx, -0x18(%rbp)
callq 0x21e0
movl $0x5, %ecx
cltd
idivl %ecx
subl $0x2, %edx
movl %edx, -0x1c(%rbp)
jmp 0x83ff
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
cmpl $0x0, %eax
jl 0x896a
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
cmpl $0x27, %eax
jg 0x896a
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cmpl $0x0, %eax
jl 0x896a
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cmpl $0x82, %eax
jg 0x896a
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
jne 0x893a
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jle 0x8938
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
addl $0x1, %eax
cmpl $0x27, %eax
jge 0x8938
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cmpl $0x0, %eax
jle 0x8938
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cmpl $0x82, %eax
jge 0x8938
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0x8680
movl $0x1, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x8936
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0x8773
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jle 0x876e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
subl $0x1, %eax
cmpl $0x27, %eax
jge 0x876e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cmpl $0x0, %eax
jle 0x876e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x1c(%rbp), %eax
cmpl $0x82, %eax
jge 0x876e
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x8934
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq (%rcx), %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0x8853
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jle 0x884e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x27, (%rax)
jge 0x884e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cmpl $0x0, %eax
jle 0x884e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
cmpl $0x82, %eax
jge 0x884e
movl $0x1, -0x1c(%rbp)
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x8932
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq (%rcx), %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x2, (%rax)
je 0x8930
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jle 0x892e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x27, (%rax)
jge 0x892e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jle 0x892e
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
subl $0x1, %eax
cmpl $0x82, %eax
jge 0x892e
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x8930
jmp 0x8932
jmp 0x8934
jmp 0x8936
jmp 0x8938
jmp 0x8968
movl -0x18(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
jmp 0x896a
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq (%rcx), %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq 0x4(%rcx), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x4, (%rax)
jne 0x8a01
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq (%rcx), %rcx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %rcx, %rax
movq -0x8(%rbp), %rcx
movslq -0x14(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movslq 0x4(%rcx), %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl $0x1, (%rax)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
subl $0x14, %ecx
movl %ecx, 0x8(%rax)
jmp 0x8a03
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)