// File: /workspace/github_c_makefile_star2_O1/S01den[P]Lost_CavernRL/item.c
// Function: setObjects
void setObjects(Map map[LONGUEUR][LARGEUR], Weapons listWeapons[], Weapons weponsOnFloor[], int nbrMaxWeapons, int *nbrWeapons, Armor armorList[], Armor armorOnFloor[], int nbrMaxArmor, int *nbrArmors)
{
	srand(time(NULL));

	int i = 0;
	int indice = 0;

	*nbrWeapons = rand()%nbrMaxWeapons+1;
	*nbrArmors = rand()%nbrMaxArmor+1;

	for(i = 0; i < *nbrWeapons; i++)
	{
		int rarity = rand()%100+1;
		if(rarity < 70)
		{
			indice = rand()%7;
			if(indice == 3)
				indice = 11;
			if(indice == 4)
				indice = 12;
			if(indice == 6)
				indice = 13;
		}
		else if(rarity >= 70 && rarity < 95)
		{
			indice = rand()%4+4;
			if(indice == 5)
				indice = 8;
			if(indice == 7)
				indice = 9;
		}
		else
		{
			indice = rand()%3+7;
			if(indice == 8)
				indice = 10;
			if(indice == 9)
				indice = 14;
		}

		indice = rand()%NBR_WEAPONS;
		weponsOnFloor[i].indice = indice;
		weponsOnFloor[i].name = listWeapons[indice].name;
		weponsOnFloor[i].rarity = listWeapons[indice].rarity;
		weponsOnFloor[i].degat = listWeapons[indice].degat;
		weponsOnFloor[i].efficiency = listWeapons[indice].efficiency;
		weponsOnFloor[i].strengthRequired = listWeapons[indice].strengthRequired;
		weponsOnFloor[i].state = listWeapons[indice].state;
		weponsOnFloor[i].range = listWeapons[indice].range;
		weponsOnFloor[i].type = listWeapons[indice].type;
		weponsOnFloor[i].cost = listWeapons[indice].cost;

		int posX = rand()%LONGUEUR;
		int posY = rand()%LARGEUR;
		if(posX == 0)
			posX++;
		if(posX == LONGUEUR-1)
			posX--;
		if(posY == 0)
			posY++;
		if(posY == LARGEUR || posY == LARGEUR-1)
			posY-=2;
		weponsOnFloor[i].x = posX;
		weponsOnFloor[i].y = posY;

		if(listWeapons[indice].type == 0)
			map[posX][posY].content = CONTACT_WEAPON;
		else
			map[posX][posY].content = DIST_WEAPON;
	}

	for(i = 0; i < *nbrArmors; i++)
	{
		int rarity = rand()%100+1;
		if(rarity < 70)
		{
			indice = rand()%4;
			if(indice == 1)
				indice = 4;
		}
		else if(rarity >= 70 && rarity < 95)
		{
			indice = rand()%3+4;
			if(indice == 4)
				indice = 1;
		}
		else
		{
			indice = rand()%2+7;
		}

		armorOnFloor[i].indice = indice;
		armorOnFloor[i].name = armorList[indice].name;
		armorOnFloor[i].rarity = armorList[indice].rarity;
		armorOnFloor[i].resistance = armorList[indice].resistance;
		armorOnFloor[i].strengthRequired = armorList[indice].strengthRequired;
		armorOnFloor[i].state = armorList[indice].state;

		int posX = rand()%LONGUEUR;
		int posY = rand()%LARGEUR;
		if(posX == 0)
			posX++;
		if(posX == LONGUEUR)
			posX--;
		if(posY == 0)
			posY++;
		if(posY == LARGEUR)
			posY--;

		armorOnFloor[i].x = posX;
		armorOnFloor[i].y = posY;
		map[posX][posY].content = ARMOR;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r15
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x8(%rsp)
movq 0x60(%rsp), %r14
xorl %edi, %edi
callq 0x1210
movl %eax, %edi
callq 0x1170
callq 0x11d0
cltd
idivl %ebp
incl %edx
movl %edx, (%r15)
callq 0x11d0
cltd
idivl 0x58(%rsp)
incl %edx
movl %edx, (%r14)
movq %r15, 0x10(%rsp)
cmpl $0x0, (%r15)
jle 0x82ca
addq $0x38, %r12
xorl %ebp, %ebp
callq 0x11d0
callq 0x11d0
callq 0x11d0
cltq
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x3, %ecx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
movl %eax, -0xc(%r12)
movslq %eax, %r14
shlq $0x6, %r14
movq (%r13,%r14), %rax
movq %rax, -0x38(%r12)
movl 0x30(%r13,%r14), %eax
movl %eax, -0x8(%r12)
movl 0x10(%r13,%r14), %eax
movl %eax, -0x28(%r12)
movl 0x14(%r13,%r14), %eax
movl %eax, -0x24(%r12)
movl 0x18(%r13,%r14), %eax
movl %eax, -0x20(%r12)
movl 0x1c(%r13,%r14), %eax
movl %eax, -0x1c(%r12)
movl 0x20(%r13,%r14), %eax
movl %eax, -0x18(%r12)
movl 0x24(%r13,%r14), %eax
movl %eax, -0x14(%r12)
movl 0x28(%r13,%r14), %eax
movl %eax, -0x10(%r12)
callq 0x11d0
movslq %eax, %r15
imulq $-0x2df2df2d, %r15, %rax # imm = 0xD20D20D3
shrq $0x20, %rax
addl %r15d, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
imull $0x27, %eax, %eax
subl %eax, %r15d
callq 0x11d0
cmpl $0x1, %r15d
movl %r15d, %edx
adcl $0x0, %edx
movl $0x25, %ecx
cmpl $0x26, %r15d
je 0x8244
movl %edx, %ecx
movslq %eax, %rsi
imulq $0x7e07e07f, %rsi, %rax # imm = 0x7E07E07F
movq %rax, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rax
addl %edx, %eax
movl %eax, %edx
shll $0x7, %edx
leal (%rdx,%rax,2), %eax
subl %eax, %esi
cmpl $0x1, %esi
movl %esi, %edx
adcl $0x0, %edx
movl $0x7f, %eax
cmpl $0x81, %esi
je 0x827c
movl %edx, %eax
movl %ecx, -0x4(%r12)
movl %eax, (%r12)
cmpl $0x1, 0x24(%r13,%r14)
movl $0x9, %edx
sbbl $0x0, %edx
movslq %ecx, %rcx
cltq
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
imulq $0xe38, %rcx, %rax      # imm = 0xE38
addq 0x8(%rsp), %rax
movl %edx, (%rax,%rsi)
incq %rbp
movq 0x10(%rsp), %rax
movslq (%rax), %rax
addq $0x40, %r12
cmpq %rax, %rbp
jl 0x816c
movq 0x60(%rsp), %rax
cmpl $0x0, (%rax)
jle 0x844b
movq 0x50(%rsp), %r15
addq $0x2c, %r15
xorl %r12d, %r12d
movl $0x4, %ebp
movl $0x1, %r13d
callq 0x11d0
movslq %eax, %r14
imulq $0x51eb851f, %r14, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
imull $0x64, %eax, %eax
subl %eax, %r14d
cmpl $0x44, %r14d
jg 0x8331
callq 0x11d0
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
subl %ecx, %eax
cmpl $0x1, %eax
cmovel %ebp, %eax
jmp 0x837a
callq 0x11d0
cmpl $0x5d, %r14d
jg 0x8369
movslq %eax, %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,2), %ecx
movl %eax, %edx
subl %ecx, %edx
negl %ecx
addl %ecx, %eax
addl $0x4, %eax
testl %edx, %edx
cmovel %r13d, %eax
jmp 0x837a
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
negl %ecx
addl %ecx, %eax
addl $0x7, %eax
movl %eax, -0xc(%r15)
cltq
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movq (%rbx,%rax), %rcx
movq %rcx, -0x2c(%r15)
movl 0x24(%rbx,%rax), %ecx
movl %ecx, -0x8(%r15)
movl 0x14(%rbx,%rax), %ecx
movl %ecx, -0x18(%r15)
movl 0x1c(%rbx,%rax), %ecx
movl %ecx, -0x10(%r15)
movl 0x18(%rbx,%rax), %eax
movl %eax, -0x14(%r15)
callq 0x11d0
movslq %eax, %r14
imulq $-0x2df2df2d, %r14, %rax # imm = 0xD20D20D3
shrq $0x20, %rax
addl %r14d, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
imull $0x27, %eax, %eax
subl %eax, %r14d
callq 0x11d0
cltq
imulq $0x7e07e07f, %rax, %rcx # imm = 0x7E07E07F
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
movl %ecx, %edx
shll $0x7, %edx
leal (%rdx,%rcx,2), %ecx
subl %ecx, %eax
cmpl $0x1, %r14d
adcl $0x0, %r14d
cmpl $0x1, %eax
adcl $0x0, %eax
movl %r14d, -0x4(%r15)
movl %eax, (%r15)
movslq %r14d, %rcx
cltq
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
imulq $0xe38, %rcx, %rax      # imm = 0xE38
addq 0x8(%rsp), %rax
movl $0x7, (%rax,%rdx)
incq %r12
movq 0x60(%rsp), %rax
movslq (%rax), %rax
addq $0x30, %r15
cmpq %rax, %r12
jl 0x82ef
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq