// File: /workspace/github_c_makefile_star2_O1/S01den[P]Lost_CavernRL/menu.c
// Function: craftMenu
int craftMenu(Inventory inventory[], Drug listDrug[], Player player, int *component, int *exoticBlood, int *gem, int minimal)
{
	int ret = 0;
	int s = 0;

	WINDOW* win;
	if(!minimal)
		win = newwin(16,42,LONGUEUR/2-5,LARGEUR-20);
	else
		win = newwin(16,42,LONGUEUR/2,LARGEUR/4);
	box(win, 0 , 0);
	wattron(win,A_UNDERLINE);
	mvwprintw(win,1,1,"COMPONENTS: %d",*component);
	mvwprintw(win,1,16,"EXOTIC BLOOD: %d",*exoticBlood);
	mvwprintw(win,1,33,"GEMS: %d",*gem);
	wattroff(win,A_UNDERLINE);

	wattron(win,COLOR_PAIR(47));
	mvwprintw(win,2,1,"1) * : NUCLEAR CHARGE (30c + 1g)");
	wattroff(win,COLOR_PAIR(47));
	mvwprintw(win,3,1,"2) ! : VACCIN (30eb)");
	wattron(win,COLOR_PAIR(124));
	mvwprintw(win,4,1,"3) ~ : SHIELD (15c)");
	wattroff(win,COLOR_PAIR(124));
	wattron(win,COLOR_PAIR(22));
	mvwprintw(win,5,1,"4) = : ELECTRIC TRAP (20c)");
	wattroff(win,COLOR_PAIR(22));
	wattron(win,COLOR_PAIR(23));
	mvwprintw(win,6,1,"5) = : PARALYSING TRAP (20c)");
	wattroff(win,COLOR_PAIR(23));
	wattron(win,COLOR_PAIR(COLOR_LAVA));
	mvwprintw(win,7,1,"6) * : LAVA BUCKET (40eb + 1g)");
	wattroff(win,COLOR_PAIR(COLOR_LAVA));
	mvwprintw(win,8,1,"7) ! : ANTIDOTE (35eb)");

	wrefresh(win);

	int key = wgetch(win);

	box(win, ' ', ' ');
	wborder(win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
	wclear(win);
	wrefresh(win);
	delwin(win);	

	switch(key)
	{	
		case '1':
			if(*component >= 20 && *gem >= 1)
			{
				(*gem)--;
				*component -= 20;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 3;
						inventory[s].object = 1; // nuclear charge
						break;
					}
				}
			}
			break;
		case '2':
			if(*exoticBlood >= 30)
			{
				*exoticBlood -= 30;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 2;
						int indiceVax = 0;
						for(indiceVax = 0; indiceVax < NBR_DRUGS; indiceVax++)
						{
							if(listDrug[indiceVax].type == 0)
								inventory[s].object = indiceVax; // vaccin
						}
						break;
					}
				}
			}
			break;
		case '3':
			if(*component >= 15)
			{
				*component -= 15;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 3;
						inventory[s].object = 2; // shield 
						break;
					}
				}
			}
			break;
		case '4':
			if(*component >= 20)
			{
				*component -= 20;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 3;
						inventory[s].object = 3; 
						break;
					}
				}
			}
			break;
		case '5':
			if(*component >= 20)
			{
				*component -= 20;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 3;
						inventory[s].object = 4;
						break;
					}
				}
			}
			break;
		case '6':
			if(*exoticBlood >= 40 && *gem >= 1)
			{
				*exoticBlood -= 40;
				(*gem)--;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 3;
						inventory[s].object = 5;
						break;
					}
				}
			}
			break;
		case '7':
			if(*exoticBlood >= 35)
			{
				*exoticBlood -= 35;
				for(s = 0; s < player.inventorySize; s++)
				{
					if(inventory[s].type == -1)
					{
						inventory[s].type = 2;
						int indiceAntidote = 0;
						for(indiceAntidote = 0; indiceAntidote < NBR_DRUGS; indiceAntidote++)
						{
							if(listDrug[indiceAntidote].type == 2)
								inventory[s].object = indiceAntidote; // vaccin
						}
						break;
					}
				}
			}
			break;
	}

	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl $0x10, %edi
movl $0x2a, %esi
testl %r9d, %r9d
je 0xa473
movl $0x13, %edx
movl $0x20, %ecx
jmp 0xa47d
movl $0xe, %edx
movl $0x6e, %ecx
callq 0x1130
movq %rax, %rbp
subq $0x8, %rsp
xorl %r12d, %r12d
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r12
pushq %r12
pushq %r12
callq 0x1120
addq $0x20, %rsp
movq %rbp, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
movq %r15, (%rsp)
movl (%r15), %r8d
leaq 0x68e0(%rip), %rcx      # 0x10da7
movq %rbp, %rdi
movl $0x1, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %r13, 0x8(%rsp)
movl (%r13), %r8d
leaq 0x68cb(%rip), %rcx      # 0x10db6
movq %rbp, %rdi
movl $0x1, %esi
movl $0x10, %edx
xorl %eax, %eax
callq 0x1070
movq 0x10(%rsp), %rax
movl (%rax), %r8d
leaq 0x68b9(%rip), %rcx      # 0x10dc7
movq %rbp, %rdi
movl $0x1, %esi
movl $0x21, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x1060
movq %rbp, %rdi
movl $0x2f00, %esi           # imm = 0x2F00
xorl %edx, %edx
callq 0x11c0
leaq 0x6889(%rip), %rcx      # 0x10dd0
movq %rbp, %rdi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x2f00, %esi           # imm = 0x2F00
xorl %edx, %edx
callq 0x1060
leaq 0x6880(%rip), %rcx      # 0x10df1
movq %rbp, %rdi
movl $0x3, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
xorl %edx, %edx
callq 0x11c0
leaq 0x686b(%rip), %rcx      # 0x10e06
movq %rbp, %rdi
movl $0x4, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
xorl %edx, %edx
callq 0x1060
movq %rbp, %rdi
movl $0x1600, %esi           # imm = 0x1600
xorl %edx, %edx
callq 0x11c0
leaq 0x6846(%rip), %rcx      # 0x10e1a
movq %rbp, %rdi
movl $0x5, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x1600, %esi           # imm = 0x1600
xorl %edx, %edx
callq 0x1060
movq %rbp, %rdi
movl $0x1700, %esi           # imm = 0x1700
xorl %edx, %edx
callq 0x11c0
leaq 0x6828(%rip), %rcx      # 0x10e35
movq %rbp, %rdi
movl $0x6, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0x1700, %esi           # imm = 0x1700
xorl %edx, %edx
callq 0x1060
movq %rbp, %rdi
movl $0xf500, %esi           # imm = 0xF500
xorl %edx, %edx
callq 0x11c0
leaq 0x680c(%rip), %rcx      # 0x10e52
movq %rbp, %rdi
movl $0x7, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
movl $0xf500, %esi           # imm = 0xF500
xorl %edx, %edx
callq 0x1060
leaq 0x6801(%rip), %rcx      # 0x10e71
movq %rbp, %rdi
movl $0x8, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %rbp, %rdi
callq 0x1100
movq %rbp, %rdi
callq 0x11e0
movl %eax, %r13d
subq $0x8, %rsp
movl $0x20, %r15d
movq %rbp, %rdi
movl $0x20, %esi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x20, %r8d
xorl %r9d, %r9d
pushq %r12
pushq %r12
pushq %r12
callq 0x1120
addq $0x18, %rsp
movq %rbp, %rdi
movl $0x20, %esi
movl $0x20, %edx
movl $0x20, %ecx
movl $0x20, %r8d
movl $0x20, %r9d
pushq %r15
pushq %r15
pushq %r15
callq 0x1120
addq $0x20, %rsp
movq %rbp, %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1100
movq %rbp, %rdi
callq 0x1110
addl $-0x31, %r13d
cmpl $0x6, %r13d
ja 0xa97d
leaq 0x50(%rsp), %rax
leaq 0x6282(%rip), %rcx      # 0x109ac
movslq (%rcx,%r13,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq (%rsp), %rcx
cmpl $0x14, (%rcx)
jl 0xa97d
movq 0x10(%rsp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
jle 0xa97d
decl %ecx
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
movq (%rsp), %rcx
addl $-0x14, (%rcx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa966
incq %rax
cmpq %rax, %rcx
jne 0xa76e
jmp 0xa97d
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0xa97d
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa90d
incq %rax
cmpq %rax, %rcx
jne 0xa7ac
jmp 0xa97d
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0xf, %ecx
jl 0xa97d
addl $-0xf, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa914
incq %rax
cmpq %rax, %rcx
jne 0xa7ea
jmp 0xa97d
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0xa97d
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa91b
incq %rax
cmpq %rax, %rcx
jne 0xa828
jmp 0xa97d
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x1e, %ecx
jl 0xa97d
addl $-0x1e, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa922
incq %rax
cmpq %rax, %rcx
jne 0xa868
jmp 0xa97d
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x28, %ecx
jl 0xa97d
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx)
jle 0xa97d
addl $-0x28, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rcx
decl (%rcx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa96d
incq %rax
cmpq %rax, %rcx
jne 0xa8bd
jmp 0xa97d
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x23, %ecx
jl 0xa97d
addl $-0x23, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xa97d
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xa944
incq %rax
cmpq %rax, %rcx
jne 0xa8fd
jmp 0xa97d
movl $0x4, %ecx
jmp 0xa972
movl $0x2, %ecx
jmp 0xa972
movl $0x3, %ecx
jmp 0xa972
movl $0x2, (%rbx,%rax,8)
xorl %ecx, %ecx
cmpl $0x0, (%r14)
jne 0xa935
movl %ecx, 0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
cmpq $0x7, %rcx
jne 0xa92b
jmp 0xa97d
movl $0x2, (%rbx,%rax,8)
xorl %ecx, %ecx
cmpl $0x2, (%r14)
jne 0xa957
movl %ecx, 0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
cmpq $0x7, %rcx
jne 0xa94d
jmp 0xa97d
movl $0x1, %ecx
jmp 0xa972
movl $0x5, %ecx
movl $0x3, (%rbx,%rax,8)
movl %ecx, 0x4(%rbx,%rax,8)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq