// File: /workspace/github_c_makefile_star2_O2/S01den[P]Lost_CavernRL/ennemy.c
// Function: iaCore
void iaCore(Ennemy ennemies[], Player *player, Map map[LONGUEUR][LARGEUR], int *nbrEnnmies, char messagePrint[], int *colorPrint, Armor *armor, WINDOW *win_msg, int *source)
{
// this is a ratio-based IA
// do enemies who can teleport themselves and enemies who can infect the player
	int degats = 0;
	int i = 0;
	int action = 0;

	for(i = 0; i < *nbrEnnmies; i++)
	{
		if(map[ennemies[i].x][ennemies[i].y].effect == 2) // if the enemy is in a radioactive zone
		{
			ennemies[i].life--;
		}
		else if(map[ennemies[i].x][ennemies[i].y].effect == 1 || map[ennemies[i].x][ennemies[i].y].effect == 3) // if the enemy is in a fire zone
		{
			ennemies[i].life-=4;
			ennemies[i].effect = 1;
		}

		if(ennemies[i].effect == 1)
		{
			ennemies[i].life -= 5;
			if(rand()%10 == 0)
			{
				ennemies[i].effect = 0;
			}
		}

		if(map[ennemies[i].x][ennemies[i].y].trap == 1)
		{
			ennemies[i].life -= 5;
			map[ennemies[i].x][ennemies[i].y].trap = 0;
			map[ennemies[i].x][ennemies[i].y].content = FLOOR;
		}
		else if(map[ennemies[i].x][ennemies[i].y].trap == 2)
		{
			ennemies[i].effect = 2;
			map[ennemies[i].x][ennemies[i].y].trap = 0;
			map[ennemies[i].x][ennemies[i].y].content = FLOOR;
			if(rand()%5 == 0)
			{
				ennemies[i].effect = 0;
			}
		}
		else if(map[ennemies[i].x][ennemies[i].y].trap == 3)
		{
			map[ennemies[i].x][ennemies[i].y].trap = 0;
			map[ennemies[i].x][ennemies[i].y].content = FLOOR;
			map[ennemies[i].x][ennemies[i].y+1].effect = 1;
			map[ennemies[i].x][ennemies[i].y-1].effect = 1;
			map[ennemies[i].x+1][ennemies[i].y].effect = 1;
			map[ennemies[i].x-1][ennemies[i].y].effect = 1;	
		}
		
		if(ennemies[i].life > 0 && ennemies[i].effect != 2)
		{
			switch(ennemies[i].type)
			{
				case 1: // droid
					if(ennemies[i].boss == 3)
					{
						action = rand()%100+1;
						if(action <= 10)
						{
							snprintf(messagePrint,100,"YOU CAN'T WIN THIS GAME!");
							player->life -= rand()%5+1;
							player->state = rand()%3+1;
							popUpArchitect();
						}
						else if(action > 10 && action <= 30)
						{
							map[player->x+1][player->y].content = WALL;
							map[player->x+1][player->y].resistance = 10;
							map[player->x-1][player->y].content = WALL;
							map[player->x-1][player->y].resistance = 10;
							map[player->x][player->y+1].content = WALL;
							map[player->x][player->y+1].resistance = 10;
							map[player->x][player->y-1].content = WALL;
							map[player->x][player->y-1].resistance = 10;
						}
						else if(action > 30 && action <= 40)
						{
							int n = 0;
							for(n = 0; n < LARGEUR; n++)
							{
								map[ennemies[i].x+1][n].content = WALL;
								map[ennemies[i].x+1][n].resistance = 5;
								map[ennemies[i].x+2][n].effect = 1;
							}
						}
						else if(action > 40 && action <= 60)
						{
							int n = 0;
							for(n = 0; n < LONGUEUR; n++)
							{
								map[n][player->y-1].effect = 1;
								map[n][player->y+1].effect = 1;
							}				
						}
						else if(action > 60 && action <= 70)
						{
							int n = 0;
							int m = 0;
							int col = rand()%LARGEUR;
							for(m = col; m < LARGEUR; m++)
							{
								for(n = 0; n < LONGUEUR; n++)
								{
									if(player->x == n && player->y == m)
									{
										player->life -= 10;
									}
									else
									{
										map[n][m].content = WALL;
										map[n][m].resistance = 5;
									}
								}	
							}
						}
						else if(action > 70 && action <= 95)
						{
							moveRand(ennemies,map,i);
						}
						else
						{
							map[rand()%LONGUEUR][rand()%LARGEUR].effect = 3;
						}
					}
					else
					{
						if(ennemies[i].seen == 0)
						{
							moveRand(ennemies,map,i);
						}
						else
						{
							action = rand()%10;
							if(action > 7 || (ennemies[i].life <= 15 && action > 4)) 
							{
								wclear(win_msg);
								repair(ennemies,i, colorPrint, messagePrint);
							}
							else if(action == 0)
							{
								moveRand(ennemies,map,i);
							}
							else
							{
								if(abs(player->x-ennemies[i].x) <= 1 && abs(player->y-ennemies[i].y) <= 1)
								{
									//melee
									if(rand()%101 <= ennemies[i].efficiency)
									{
										int degats = ennemies[i].strength*2 + rand()%3+1 - abs(armor->resistance);
										if(degats > 0)
										{
											armor->state -= degats/3;
											player->life -= degats/2;
											wclear(win_msg);
											*colorPrint = 197; // RED LIKE BLOOOOOOOD
											snprintf(messagePrint,100,"%s HITS YOU WITH HIS ROTATIVE BLADE (-%d LP)",ennemies[i].name,degats/2); 
											*source = 7;
										}
									}
									else
									{
										wclear(win_msg);
										*colorPrint = 47;
										snprintf(messagePrint,100,"%s MISSED YOU !",ennemies[i].name);
									}
								}
								else
								{
									if(ennemies[i].haveBlaster != 1)
									{
										if(abs(player->x - ennemies[i].x) > abs(player->y-ennemies[i].y))
										{
											if(player->x > ennemies[i].x)
											{
												if(map[ennemies[i].x+1][ennemies[i].y].content != WALL && map[ennemies[i].x+1][ennemies[i].y].content != DOOR)
													ennemies[i].x++;
											}
											else
											{
												if(map[ennemies[i].x-1][ennemies[i].y].content != WALL && map[ennemies[i].x-1][ennemies[i].y].content != DOOR)
													ennemies[i].x--;
											}
										}
										else
										{
											if(player->y > ennemies[i].y)
											{
												if(map[ennemies[i].x][ennemies[i].y+1].content != WALL && map[ennemies[i].x][ennemies[i].y+1].content != DOOR)
													ennemies[i].y++;
											}
											else
											{
												if(map[ennemies[i].x][ennemies[i].y-1].content != WALL && map[ennemies[i].x][ennemies[i].y-1].content != DOOR)
													ennemies[i].y--;
											}
										}
									}
									else
									{
										if(rand()%101 <= ennemies[i].efficiency)
										{
											degats = blastHit(ennemies[i],player,armor,map);
											if(degats > 0)
											{
												wclear(win_msg);
												*colorPrint = 197; // RED LIKE BLOOOOOOOD
												snprintf(messagePrint,100,"%s HITS YOU WITH HIS HIS BLASTER (-%d LP)",ennemies[i].name,degats/2);	
												*source = 7;			
											}
										}
										else
										{
											wclear(win_msg);
											*colorPrint = 47;
											snprintf(messagePrint,100,"%s MISSED YOU !",ennemies[i].name);
										}
									}
								}
							}
						}
					}
				break;

				case 2: // sentry
					action = rand()%10;
					if(ennemies[i].seen == 0)
					{
						if(rand()%75 == 0)
						{
							ennemies[i].life++;
						}
					}
					else
					{
						if(ennemies[i].boss != 0)
						{
							if(action <= 6)
							{
								if(rand()%101 <= ennemies[i].efficiency)
								{
									degats = blastHit(ennemies[i],player,armor,map);
									if(degats > 0)
									{
										wclear(win_msg);
										*colorPrint = 197; // RED LIKE BLOOOOOOOD
										snprintf(messagePrint,100,"%s HITS YOU WITH HIS HIS LASER-CANON (-%d LP)",ennemies[i].name,degats/2);
										*source = 8;		
									}
								}
								else
								{
									wclear(win_msg);
									*colorPrint = 47;
									snprintf(messagePrint,100,"%s MISSED YOU !",ennemies[i].name);
								}			
							}
							else if(action == 7)
							{
								int xBomb = rand()%5-2;
								int yBomb = rand()%5-2;
								wclear(win_msg);
								*colorPrint = 197; // RED LIKE BLOOOOOOOD
								snprintf(messagePrint,100,"%s THROWS A BOMB NEAR YOU !",ennemies[i].name);
								map[player->x+xBomb][player->y+yBomb].content = BOMB;
								map[player->x+xBomb][player->y+yBomb].resistance = 4;
							}
							else if(action == 8)
							{
								wclear(win_msg);
								*colorPrint = 47;
								snprintf(messagePrint,100,"********** BUG ! CORE DUMPED ! **********");					
							}
							else
							{
								*colorPrint = 197; // RED LIKE BLOOOOOOOD
								snprintf(messagePrint,100,"*** FIRE MODULE ACTIVATED ! ***");
								map[player->x+rand()%5-2][player->y+rand()%5-2].effect = 1;
							}

						}
						else
						{
							if(action <= 7)
							{
								if(rand()%101 <= ennemies[i].efficiency)
								{
									degats = blastHit(ennemies[i],player,armor,map);
									if(degats > 0)
									{
										wclear(win_msg);
										*colorPrint = 197; // RED LIKE BLOOOOOOOD
										snprintf(messagePrint,100,"%s HITS YOU WITH HIS HIS LASER-CANON (-%d LP)",ennemies[i].name,degats/2);	
										*source = 8;			
									}
								}
								else
								{
									wclear(win_msg);
									*colorPrint = 47;
									snprintf(messagePrint,100,"%s MISSED YOU !",ennemies[i].name);
								}			
							}
							else
							{
								wclear(win_msg);
								repair(ennemies,i, colorPrint, messagePrint);
							}
						}
					}

				break;

			case 3:
					if(ennemies[i].boss == 1) // BOSS 1: ALTHORUS THE GUARDIAN
					{
						if(abs(player->x-ennemies[i].x) <= 2 && abs(player->y-ennemies[i].y) <= 2 && rand()%6 == 0)
						{
							int sign = 1;
							if(player->x > ennemies[i].x)
								sign = 1;
							else
								sign = -1;
							int turns = 0;
							while(turns < 4 && map[player->x][player->y].content != WALL)
							{
								player->x+=sign;
								turns++;
							}
							if(map[player->x][player->y].content == WALL)
							{
								player->life -= 10;
								armor->state -= 10;
								map[player->x][player->y].content = FLOOR;
							}
						}
						else if(abs(player->x-ennemies[i].x) <= 5 && abs(player->y-ennemies[i].y) <= 5 && (*nbrEnnmies)+1 < ENEMIES_MAX && rand()%10 == 1)
						{
							(*nbrEnnmies)++;
							ennemies[i+(*nbrEnnmies)].x = player->x + rand()%1-3;
							ennemies[i+(*nbrEnnmies)].y = player->y + rand()%1-3;
							ennemies[i+(*nbrEnnmies)].type = 3;
							ennemies[i+(*nbrEnnmies)].boss = 0;
							ennemies[i+(*nbrEnnmies)].life = 30;
							ennemies[i+(*nbrEnnmies)].strength = rand()%3+4;
							ennemies[i+(*nbrEnnmies)].seen = 0;
							ennemies[i+(*nbrEnnmies)].agility = 3;
							ennemies[i+(*nbrEnnmies)].haveBlaster = 0;
							ennemies[i+(*nbrEnnmies)].name = "MINI-GUARDIAN";	
						}
						else
						{
							if(abs(player->x - ennemies[i].x) > abs(player->y-ennemies[i].y))
							{
								if(player->x > ennemies[i].x)
								{
									if(map[ennemies[i].x+1][ennemies[i].y].content != WALL && map[ennemies[i].x+1][ennemies[i].y].content != DOOR)
										ennemies[i].x++;
								}
								else
								{
									if(map[ennemies[i].x-1][ennemies[i].y].content != WALL && map[ennemies[i].x-1][ennemies[i].y].content != DOOR)
										ennemies[i].x--;
								}
							}
							else
							{
								if(player->y > ennemies[i].y)
								{
									if(map[ennemies[i].x][ennemies[i].y+1].content != WALL && map[ennemies[i].x][ennemies[i].y+1].content != DOOR)
										ennemies[i].y++;
								}
								else
								{
									if(map[ennemies[i].x][ennemies[i].y-1].content != WALL && map[ennemies[i].x][ennemies[i].y-1].content != DOOR)
										ennemies[i].y--;
								}
							}
						}
					}
					else
					{
						if(abs(player->x-ennemies[i].x) <= 1 && abs(player->y-ennemies[i].y) <= 1)
						{
						//melee
							if(rand()%101 <= ennemies[i].efficiency)
							{
								int degats = ennemies[i].strength*2 + rand()%5 + 3 - armor->resistance;
								if(degats > 0)
								{
									armor->state -= degats/3;
									player->life -= degats/2;
									wclear(win_msg);
									*colorPrint = 197; // RED LIKE BLOOOOOOOD
									snprintf(messagePrint,100,"%s HITS YOU WITH HIS SPEAR (-%d LP)",ennemies[i].name,degats/2); 
									*source = 9;
								}
							}
							else
							{
								wclear(win_msg);
								*colorPrint = 47;
								snprintf(messagePrint,100,"%s MISSED YOU !",ennemies[i].name);
							}
						}
						else
						{
							if(rand()%10+1 < 8)
							{
								if(abs(player->x - ennemies[i].x) > abs(player->y-ennemies[i].y))
								{
									if(player->x > ennemies[i].x)
									{
										if(map[ennemies[i].x+1][ennemies[i].y].content != WALL && map[ennemies[i].x+1][ennemies[i].y].content != DOOR)
											ennemies[i].x++;
									}
									else
									{
										if(map[ennemies[i].x-1][ennemies[i].y].content != WALL && map[ennemies[i].x-1][ennemies[i].y].content != DOOR)
											ennemies[i].x--;
									}
								}
								else
								{
									if(player->y > ennemies[i].y)
									{
										if(map[ennemies[i].x][ennemies[i].y+1].content != WALL && map[ennemies[i].x][ennemies[i].y+1].content != DOOR)
											ennemies[i].y++;
									}
									else
									{
										if(map[ennemies[i].x][ennemies[i].y-1].content != WALL&& map[ennemies[i].x][ennemies[i].y-1].content != DOOR)
											ennemies[i].y--;
									}
								}
							}
						}
					}
				break;

				case 4:
						if(abs(player->x-ennemies[i].x) <= 1 && abs(player->y-ennemies[i].y) <= 1)
						{
							if(rand()%3 == 1)
							{
								// explode !
								ennemies[i].life = 0;
								map[ennemies[i].x][ennemies[i].y].content = BOMB;

								int angle = 0;
								int c = 0;
								float ox = 0;
								float oy = 0;
								int tailleRad = 3;

								for(angle = 0; angle < 360; angle++)
								{
									if(oy >= 0 && oy <= LARGEUR && ox <= LONGUEUR && ox >= 0)
									{
										float angleI = cos((float)angle*0.01745f); // 1° = 0.01745 rad because 360° = 2pi rad
										float angleJ = sin((float)angle*0.01745f);
										ox = (float)ennemies[i].x+0.5f;
										oy = (float)ennemies[i].y+0.5f;

										for(c = 0; c < tailleRad && (int)ox+angleI <= LONGUEUR && (int)oy+angleJ <= LARGEUR; c++)
										{
											map[(int)ox][(int)oy].effect = 2;

											ox+=angleI;
											oy+=angleJ;		
										}
									}
								}
							}
						}
						else
						{
							if(abs(player->x - ennemies[i].x) > abs(player->y-ennemies[i].y))
							{
								if(player->x > ennemies[i].x)
								{
									if(map[ennemies[i].x+1][ennemies[i].y].content != WALL && map[ennemies[i].x+1][ennemies[i].y].content != DOOR)
										ennemies[i].x++;
								}
								else
								{
									if(map[ennemies[i].x-1][ennemies[i].y].content != WALL && map[ennemies[i].x-1][ennemies[i].y].content != DOOR)
										ennemies[i].x--;
								}
							}
							else
							{
								if(player->y > ennemies[i].y)
								{
									if(map[ennemies[i].x][ennemies[i].y+1].content != WALL && map[ennemies[i].x][ennemies[i].y+1].content != DOOR)
										ennemies[i].y++;
								}
								else
								{
									if(map[ennemies[i].x][ennemies[i].y-1].content != WALL&& map[ennemies[i].x][ennemies[i].y-1].content != DOOR)
										ennemies[i].y--;
								}
							}
					}
				break;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %rcx, 0x58(%rsp)
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbp
leaq -0xe38(%rdx), %rax
movq %rax, 0x50(%rsp)
leaq -0x1c70(%rdx), %rax
movq %rax, 0x88(%rsp)
leaq 0x14(%rdx), %rax
movq %rax, 0x78(%rsp)
leaq 0x1c74(%rdx), %rax
movq %rax, 0x80(%rsp)
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jge 0x5e28
imulq $0x38, %rbx, %rax
leaq (%rax,%rbp), %r15
movslq (%rbp,%rax), %rcx
movslq 0x4(%rbp,%rax), %rax
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %r12, %rcx
imulq $0x1c, %rax, %rax
movl 0x4(%rax,%rcx), %eax
cmpl $0x1, %eax
je 0x5073
cmpl $0x3, %eax
je 0x5073
cmpl $0x2, %eax
jne 0x5080
decl 0x8(%r15)
jmp 0x5080
addl $-0x4, 0x8(%r15)
movl $0x1, 0x24(%r15)
cmpl $0x1, 0x24(%r15)
jne 0x50a0
addl $-0x5, 0x8(%r15)
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
testl %edx, %edx
jne 0x50a0
andl $0x0, 0x24(%r15)
movslq (%r15), %rax
movslq 0x4(%r15), %rsi
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
imulq $0x1c, %rsi, %rcx
leaq (%rcx,%rax), %rdx
addq $0x18, %rdx
movl (%rdx), %edi
cmpl $0x3, %edi
je 0x5107
cmpl $0x2, %edi
je 0x50df
cmpl $0x1, %edi
jne 0x512f
addl $-0x5, 0x8(%r15)
andl $0x0, (%rdx)
movl $0x1, (%rcx,%rax)
jmp 0x512f
movl $0x2, 0x24(%r15)
andl $0x0, (%rdx)
movl $0x1, (%rcx,%rax)
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
testl %edx, %edx
jne 0x512f
andl $0x0, 0x24(%r15)
jmp 0x512f
andl $0x0, (%rdx)
pushq $0x1
popq %rdi
movl %edi, (%rcx,%rax)
movl %edi, 0x20(%rcx,%rax)
decl %esi
movslq %esi, %rdx
imulq $0x1c, %rdx, %rdx
movl %edi, 0x4(%rdx,%rax)
movl %edi, 0xe3c(%rcx,%rax)
movl %edi, -0xe34(%rcx,%rax)
cmpl $0x0, 0x8(%r15)
jle 0x513d
cmpl $0x2, 0x24(%r15)
jne 0x5145
incq %rbx
jmp 0x5029
movl 0x20(%r15), %eax
decl %eax
cmpl $0x3, %eax
ja 0x513d
leaq 0x8dc9(%rip), %rcx      # 0xdf20
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x3, 0x28(%r15)
jne 0x56a3
callq 0x11d0
cltd
pushq $0x64
popq %rcx
idivl %ecx
cmpl $0x9, %edx
jg 0x5833
movups 0x8dc3(%rip), %xmm0     # 0xdf49
movq 0x40(%rsp), %rax
movups %xmm0, 0x9(%rax)
movups 0x8daa(%rip), %xmm0     # 0xdf40
movups %xmm0, (%rax)
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
notl %edx
addl %edx, 0x10(%r13)
callq 0x11d0
cltd
pushq $0x3
popq %rcx
idivl %ecx
incl %edx
movl %edx, 0x30(%r13)
xorl %eax, %eax
callq 0x95a7
jmp 0x513d
movl (%r15), %ecx
movl 0x14(%r13), %eax
movl %eax, %edx
subl %ecx, %edx
movl %edx, %edi
negl %edi
cmovsl %edx, %edi
cmpl $0x1, 0x28(%r15)
jne 0x55c4
movl 0x18(%r13), %esi
movl 0x4(%r15), %edx
cmpl $0x2, %edi
ja 0x5238
movl %esi, %r8d
subl %edx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl $0x2, %r9d
ja 0x5241
callq 0x11d0
cltd
pushq $0x6
popq %rcx
idivl %ecx
movl 0x14(%r13), %eax
movl (%r15), %ecx
testl %edx, %edx
je 0x5b24
movl 0x18(%r13), %esi
movl 0x4(%r15), %edx
movl %eax, %r8d
subl %ecx, %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
cmpl $0x5, %edi
ja 0x5c47
movl %esi, %r8d
subl %edx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl $0x5, %r9d
ja 0x5c47
movq 0x58(%rsp), %r8
cmpl $0x21, (%r8)
jg 0x5c47
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
cmpl $0x1, %edx
jne 0x5c29
movq 0x58(%rsp), %r15
incl (%r15)
movl 0x14(%r13), %r14d
callq 0x11d0
addl $-0x3, %r14d
movl %r14d, %ecx
movslq (%r15), %rax
movslq %ebx, %r14
addq %r14, %rax
imulq $0x38, %rax, %rax
movl %ecx, (%rbp,%rax)
movl 0x18(%r13), %eax
movl %eax, 0x60(%rsp)
callq 0x11d0
movl 0x60(%rsp), %ecx
addl $-0x3, %ecx
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
movl %ecx, 0x4(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
pushq $0x3
popq %rcx
movl %ecx, 0x20(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
andl $0x0, 0x28(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
movl $0x1e, 0x8(%rbp,%rax)
callq 0x11d0
cltd
pushq $0x3
popq %rcx
idivl %ecx
addl $0x4, %edx
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
movl %edx, 0x10(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
andl $0x0, 0xc(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
movl %ecx, 0x14(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
andl $0x0, 0x18(%rbp,%rax)
movslq (%r15), %rax
addq %r14, %rax
imulq $0x38, %rax, %rax
leaq 0x8d00(%rip), %rcx      # 0xe054
movq %rcx, 0x30(%rbp,%rax)
jmp 0x513d
movl 0x14(%r13), %edx
movl 0x18(%r13), %esi
movslq (%r15), %rax
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, %edi
negl %edi
cmovsl %ecx, %edi
cmpl $0x2, %edi
setb %r9b
movslq 0x4(%r15), %rcx
movl %esi, %r10d
subl %ecx, %r10d
movl %r10d, %r8d
negl %r8d
cmovsl %r10d, %r8d
cmpl $0x2, %r8d
setb %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x568a
callq 0x11d0
movss 0x8b43(%rip), %xmm6     # 0xdef4
movss 0x8b37(%rip), %xmm5     # 0xdef0
cltd
pushq $0x3
popq %rcx
idivl %ecx
cmpl $0x1, %edx
jne 0x513d
andl $0x0, 0x8(%r15)
movslq (%r15), %rax
movslq 0x4(%r15), %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
imulq $0x1c, %rcx, %rcx
movl $0xa, (%rcx,%rax)
xorps %xmm0, %xmm0
xorl %r14d, %r14d
cmpl $0x168, %r14d           # imm = 0x168
je 0x513d
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
ucomiss 0x8af2(%rip), %xmm1     # 0xdefc
jb 0x54ee
ucomiss %xmm1, %xmm5
jb 0x54ee
ucomiss %xmm0, %xmm6
jb 0x54ee
ucomiss 0x8ad3(%rip), %xmm0     # 0xdefc
jb 0x54ee
cvtsi2ss %r14d, %xmm0
mulss 0x8abc(%rip), %xmm0     # 0xdef8
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x90(%rsp)
callq 0x10c0
movaps %xmm0, 0x60(%rsp)
movsd 0x90(%rsp), %xmm0
callq 0x1200
movss 0x8a8b(%rip), %xmm6     # 0xdef4
movss 0x8a7f(%rip), %xmm5     # 0xdef0
movapd 0x60(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
cvtpd2ps %xmm1, %xmm1
movapd %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
movsd (%r15), %xmm0
cvtdq2ps %xmm0, %xmm0
addps 0x8a6a(%rip), %xmm0     # 0xdf00
pushq $0x3
popq %rax
subl $0x1, %eax
jb 0x54ee
cvttps2dq %xmm0, %xmm3
cvtdq2ps %xmm3, %xmm3
addss %xmm1, %xmm3
ucomiss %xmm3, %xmm6
jb 0x54ee
movaps %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm3     # xmm3 = xmm3[1,1],xmm0[1,1]
cvttps2dq %xmm3, %xmm4
cvtdq2ps %xmm4, %xmm4
addss %xmm2, %xmm4
ucomiss %xmm4, %xmm5
jb 0x54ee
cvttss2si %xmm0, %ecx
cvttss2si %xmm3, %edx
movslq %ecx, %rcx
movslq %edx, %rdx
imulq $0xe38, %rcx, %rcx      # imm = 0xE38
addq %r12, %rcx
imulq $0x1c, %rdx, %rdx
movl $0x2, 0x4(%rdx,%rcx)
addps %xmm1, %xmm0
jmp 0x5499
incl %r14d
jmp 0x53ef
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
cmpl $0x0, 0xc(%r15)
je 0x5817
cmpl $0x0, 0x28(%r15)
je 0x5889
cmpl $0x6, %edx
jle 0x588e
cmpl $0x8, %edx
je 0x5a28
cmpl $0x7, %edx
jne 0x5a6a
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
movslq %edx, %rax
movq %rax, 0x60(%rsp)
callq 0x11d0
movl %eax, %r14d
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movq 0x30(%r15), %rcx
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x8a76(%rip), %rdx      # 0xdfee
xorl %eax, %eax
callq 0x1050
movslq 0x14(%r13), %rcx
addq 0x60(%rsp), %rcx
movl %r14d, %eax
cltd
pushq $0x5
popq %rsi
idivl %esi
movslq %edx, %rax
movslq 0x18(%r13), %rdx
addq %rax, %rdx
imulq $0xe38, %rcx, %rax      # imm = 0xE38
imulq $0x1c, %rdx, %rcx
addq %r12, %rax
movl $0xa, -0x1ca8(%rcx,%rax)
movl $0x4, -0x1c94(%rcx,%rax)
jmp 0x513d
cmpl $0x1, %edi
ja 0x57a3
movl 0x18(%r13), %eax
subl 0x4(%r15), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl $0x1, %ecx
ja 0x57a3
callq 0x11d0
cltd
pushq $0x65
popq %rcx
idivl %ecx
cmpl 0x1c(%r15), %edx
jg 0x58a3
movl 0x10(%r15), %r14d
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
leal (%rdx,%r14,2), %r14d
movq 0xd0(%rsp), %rax
subl 0x14(%rax), %r14d
addl $0x3, %r14d
testl %r14d, %r14d
jle 0x513d
movl %r14d, %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
movq 0xd0(%rsp), %rcx
subl %eax, 0x18(%rcx)
shrl %r14d
subl %r14d, 0x10(%r13)
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movq 0x30(%r15), %rcx
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x89f5(%rip), %rdx      # 0xe062
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1050
movq 0xe0(%rsp), %rax
movl $0x9, (%rax)
jmp 0x513d
cmpl %r8d, %edi
ja 0x57ea
cmpl %ecx, %esi
jle 0x59b7
incq %rcx
jmp 0x59ba
cmpl $0x0, 0xc(%r15)
je 0x5ddd
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
cmpl $0x7, %edx
jg 0x58da
cmpl $0x5, %edx
jl 0x56d2
cmpl $0xf, 0x8(%r15)
jle 0x58da
testl %edx, %edx
je 0x5ddd
movl 0x14(%r13), %edx
movslq (%r15), %rax
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
cmpl $0x1, %esi
ja 0x5b7b
movl 0x18(%r13), %ecx
subl 0x4(%r15), %ecx
movl %ecx, %edi
negl %edi
cmovsl %ecx, %edi
cmpl $0x1, %edi
ja 0x5b7b
callq 0x11d0
cltd
pushq $0x65
popq %rcx
idivl %ecx
cmpl 0x1c(%r15), %edx
jg 0x58a3
movl 0x10(%r15), %r14d
callq 0x11d0
cltd
pushq $0x3
popq %rcx
idivl %ecx
movq 0xd0(%rsp), %rax
movl 0x14(%rax), %eax
movl %eax, %ecx
negl %ecx
leal (%rdx,%r14,2), %edx
cmovnsl %eax, %ecx
leal (%rcx,%rdx), %r14d
incl %r14d
testl %r14d, %r14d
jle 0x513d
movl %r14d, %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
movq 0xd0(%rsp), %rcx
subl %eax, 0x18(%rcx)
shrl %r14d
subl %r14d, 0x10(%r13)
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movq 0x30(%r15), %rcx
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x87bb(%rip), %rdx      # 0xdf59
jmp 0x5c0c
callq 0x11d0
cltd
pushq $0xa
popq %rcx
idivl %ecx
cmpl $0x6, %edx
jg 0x513d
movl 0x14(%r13), %edx
movl 0x18(%r13), %esi
movslq (%r15), %rax
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, %edi
negl %edi
cmovsl %ecx, %edi
movslq 0x4(%r15), %rcx
movl %esi, %r8d
subl %ecx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %r9d, %edi
jbe 0x5a19
cmpl %eax, %edx
jle 0x5900
incq %rax
imulq $0xe38, %rax, %rdx      # imm = 0xE38
addq %r12, %rdx
imulq $0x1c, %rcx, %rcx
movl (%rcx,%rdx), %ecx
orl $0x4, %ecx
cmpl $0x6, %ecx
je 0x513d
jmp 0x5921
callq 0x11d0
cltd
pushq $0x4b
popq %rcx
idivl %ecx
testl %edx, %edx
jne 0x513d
incl 0x8(%r15)
jmp 0x513d
cmpl $0x1d, %edx
ja 0x59cd
movslq 0x14(%r13), %rax
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
movslq 0x18(%r13), %rcx
imulq $0x1c, %rcx, %rcx
pushq $0x2
popq %rsi
movl %esi, 0xe38(%rcx,%rax)
pushq $0xa
popq %rdx
movl %edx, 0xe4c(%rcx,%rax)
movl %esi, -0xe38(%rcx,%rax)
movl %edx, -0xe24(%rcx,%rax)
movl %esi, 0x1c(%rcx,%rax)
movl %edx, 0x30(%rcx,%rax)
movl %esi, -0x1c(%rcx,%rax)
movl %edx, -0x8(%rcx,%rax)
jmp 0x513d
cmpl $0x7, %edx
jg 0x58da
callq 0x11d0
cltd
pushq $0x65
popq %rcx
idivl %ecx
cmpl 0x1c(%r15), %edx
jle 0x5929
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0x2f, (%rax)
movq 0x30(%r15), %rcx
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x86b8(%rip), %rdx      # 0xdf86
xorl %eax, %eax
callq 0x1050
jmp 0x513d
movq 0xd8(%rsp), %rdi
callq 0x1030
movq %rbp, %rdi
movl %ebx, %esi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0x5e3a
jmp 0x513d
imulq $0xe38, %rax, %rdx      # imm = 0xE38
addq 0x50(%rsp), %rdx
imulq $0x1c, %rcx, %rcx
movl (%rcx,%rdx), %ecx
orl $0x4, %ecx
cmpl $0x6, %ecx
je 0x513d
decl %eax
movl %eax, (%r15)
jmp 0x513d
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
movq 0xd0(%rsp), %rsi
movq %r12, %rdx
callq 0x5eba
testl %eax, %eax
jle 0x513d
movl %eax, %r14d
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movq 0x30(%r15), %rcx
shrl %r14d
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x8626(%rip), %rdx      # 0xdfc0
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1050
movq 0xe0(%rsp), %rax
movl $0x8, (%rax)
jmp 0x513d
decq %rcx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
imulq $0x1c, %rcx, %rdx
jmp 0x5dc0
cmpl $0x27, %edx
ja 0x5adc
movslq (%r15), %rax
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq 0x80(%rsp), %rax
movq $-0xe38, %rcx           # imm = 0xF1C8
testq %rcx, %rcx
je 0x513d
movl $0x2, -0x4(%rax,%rcx)
movl $0x5, 0x10(%rax,%rcx)
movl $0x1, 0xe38(%rax,%rcx)
addq $0x1c, %rcx
jmp 0x59ef
cmpl %ecx, %esi
jle 0x5dad
incl %ecx
jmp 0x5daf
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0x2f, (%rax)
movups 0x85c3(%rip), %xmm0     # 0xe00a
movq 0x40(%rsp), %rax
movups %xmm0, (%rax)
movups 0x85c4(%rip), %xmm0     # 0xe01a
movups %xmm0, 0x10(%rax)
movups 0x85c3(%rip), %xmm0     # 0xe024
movups %xmm0, 0x1a(%rax)
jmp 0x513d
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movups 0x85c8(%rip), %xmm0     # 0xe044
movq 0x40(%rsp), %rax
movups %xmm0, 0x10(%rax)
movups 0x85a8(%rip), %xmm0     # 0xe034
movups %xmm0, (%rax)
movslq 0x14(%r13), %r14
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
movslq %edx, %r15
addq %r14, %r15
movl 0x18(%r13), %r14d
callq 0x11d0
cltd
pushq $0x5
popq %rcx
idivl %ecx
leal (%r14,%rdx), %eax
addl $-0x2, %eax
cltq
imulq $0x1c, %rax, %rax
imulq $0xe38, %r15, %rcx      # imm = 0xE38
addq 0x88(%rsp), %rcx
movl $0x1, 0x4(%rax,%rcx)
jmp 0x513d
cmpl $0x3b, %edx
ja 0x5ce6
movl 0x18(%r13), %eax
leal -0x1(%rax), %ecx
movslq %ecx, %rcx
incl %eax
movslq %eax, %rdx
imulq $0x1c, %rcx, %rax
addq %r12, %rax
imulq $0x1c, %rdx, %rcx
addq %r12, %rcx
pushq $0x4
popq %rdx
cmpq $0x22a8c, %rdx          # imm = 0x22A8C
je 0x513d
pushq $0x1
popq %rsi
movl %esi, (%rax,%rdx)
movl %esi, (%rcx,%rdx)
addq $0xe38, %rdx            # imm = 0xE38
jmp 0x5b05
movslq %eax, %rsi
xorl %edi, %edi
cmpl %ecx, %eax
setle %dil
movl %edi, %edx
negl %edx
orl $0x1, %edx
movslq 0x18(%r13), %r8
imulq $0xe38, %rsi, %rcx      # imm = 0xE38
addq %r12, %rcx
negq %rdi
orq $0x1, %rdi
imulq $0xe38, %rdi, %rdi      # imm = 0xE38
imulq $0x1c, %r8, %rsi
addl %edx, %eax
pushq $0x4
popq %r8
subl $0x1, %r8d
jb 0x5d5d
cmpl $0x2, (%rcx,%rsi)
je 0x5d67
movl %eax, 0x14(%r13)
addq %rdi, %rcx
addl %edx, %eax
jmp 0x5b5c
cmpl $0x1, 0x18(%r15)
jne 0x5d84
callq 0x11d0
cltd
pushq $0x65
popq %rcx
idivl %ecx
cmpl 0x1c(%r15), %edx
jg 0x58a3
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r13, %rdi
movq 0xd0(%rsp), %rsi
movq %r12, %rdx
callq 0x5eba
testl %eax, %eax
jle 0x513d
movl %eax, %r14d
movq 0xd8(%rsp), %rdi
callq 0x1030
movq 0x48(%rsp), %rax
movl $0xc5, (%rax)
movq 0x30(%r15), %rcx
shrl %r14d
movq 0x40(%rsp), %rdi
pushq $0x64
popq %rsi
leaq 0x838a(%rip), %rdx      # 0xdf96
movl %r14d, %r8d
xorl %eax, %eax
callq 0x1050
movq 0xe0(%rsp), %rax
movl $0x7, (%rax)
jmp 0x513d
movl 0x14(%r13), %eax
movl 0x18(%r13), %esi
movl (%r15), %ecx
movl 0x4(%r15), %edx
movl %eax, %r8d
subl %ecx, %r8d
movl %r8d, %edi
negl %edi
cmovsl %r8d, %edi
movl %esi, %r8d
subl %edx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
movslq %ecx, %r8
cmpl %r9d, %edi
jbe 0x5c8a
movslq %edx, %rdx
cmpl %ecx, %eax
jle 0x5c92
incl %ecx
movslq %ecx, %rax
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
imulq $0x1c, %rdx, %rdx
movl (%rdx,%rax), %eax
orl $0x4, %eax
cmpl $0x6, %eax
je 0x513d
jmp 0x5cb3
cmpl %edx, %esi
jle 0x5cbb
incl %edx
jmp 0x5cbd
imulq $0xe38, %r8, %rax       # imm = 0xE38
addq 0x50(%rsp), %rax
imulq $0x1c, %rdx, %rdx
movl (%rdx,%rax), %eax
orl $0x4, %eax
cmpl $0x6, %eax
je 0x513d
decl %ecx
movl %ecx, (%r15)
jmp 0x513d
decl %edx
movslq %edx, %rax
imulq $0xe38, %r8, %rcx       # imm = 0xE38
addq %r12, %rcx
imulq $0x1c, %rax, %rax
movl (%rax,%rcx), %eax
orl $0x4, %eax
cmpl $0x6, %eax
je 0x513d
movl %edx, 0x4(%r15)
jmp 0x513d
cmpl $0x45, %edx
ja 0x5dd8
callq 0x11d0
cltd
movl $0x82, %ecx
idivl %ecx
movl 0x14(%r13), %esi
movslq %edx, %rax
imulq $0x1c, %rax, %rcx
addq 0x78(%rsp), %rcx
imulq $0xe38, %rsi, %rdx      # imm = 0xE38
cmpq $0x81, %rax
jg 0x513d
xorl %esi, %esi
cmpq $0x22a88, %rsi          # imm = 0x22A88
je 0x5d54
cmpq %rsi, %rdx
jne 0x5d3c
cmpl %eax, 0x18(%r13)
jne 0x5d3c
addl $-0xa, 0x10(%r13)
jmp 0x5d4b
movl $0x2, -0x14(%rcx,%rsi)
movl $0x5, (%rcx,%rsi)
addq $0xe38, %rsi            # imm = 0xE38
jmp 0x5d21
incq %rax
addq $0x1c, %rcx
jmp 0x5d13
cmpl $0x2, (%rcx,%rsi)
jne 0x513d
addl $-0xa, 0x10(%r13)
movq 0xd0(%rsp), %rax
addl $-0xa, 0x18(%rax)
movl $0x1, (%rcx,%rsi)
jmp 0x513d
movl 0x18(%r13), %edi
movslq 0x4(%r15), %rcx
movl %edi, %r8d
subl %ecx, %r8d
movl %r8d, %r9d
negl %r9d
cmovsl %r8d, %r9d
cmpl %r9d, %esi
ja 0x57ea
cmpl %ecx, %edi
jg 0x5a21
decl %ecx
movslq %ecx, %rdx
imulq $0xe38, %rax, %rax      # imm = 0xE38
addq %r12, %rax
imulq $0x1c, %rdx, %rdx
movl (%rdx,%rax), %eax
orl $0x4, %eax
cmpl $0x6, %eax
je 0x513d
movl %ecx, 0x4(%r15)
jmp 0x513d
cmpl $0x5e, %edx
ja 0x5def
movq %rbp, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x4e20
jmp 0x513d
callq 0x11d0
cltd
pushq $0x27
popq %rcx
idivl %ecx
movslq %edx, %r14
callq 0x11d0
cltd
movl $0x82, %ecx
idivl %ecx
movslq %edx, %rax
imulq $0xe38, %r14, %rcx      # imm = 0xE38
addq %r12, %rcx
imulq $0x1c, %rax, %rax
movl $0x3, 0x4(%rax,%rcx)
jmp 0x513d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq