// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x20
popq %r13
pushq $0x10
popq %rdi
pushq $0x2a
popq %rsi
testl %r9d, %r9d
je 0x90c4
pushq $0x13
popq %rdx
pushq $0x20
jmp 0x90c9
pushq $0xe
popq %rdx
pushq $0x6e
popq %rcx
callq 0x1130
movq %rax, %r12
subq $0x20, %rsp
andl $0x0, 0x10(%rsp)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
movq %rax, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1120
addq $0x20, %rsp
movq %r12, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x11c0
movq %r15, (%rsp)
movl (%r15), %r8d
leaq 0x5d2e(%rip), %rcx      # 0xee47
pushq $0x1
popq %rbp
movq %r12, %rdi
movl %ebp, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq 0x8(%rsp), %rax
movl (%rax), %r8d
leaq 0x5d1d(%rip), %rcx      # 0xee56
pushq $0x10
popq %rdx
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1070
movq 0x10(%rsp), %rax
movl (%rax), %r8d
leaq 0x5d10(%rip), %rcx      # 0xee67
pushq $0x21
popq %rdx
movq %r12, %rdi
movl %ebp, %esi
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x20000, %esi          # imm = 0x20000
xorl %edx, %edx
callq 0x1060
movq %r12, %rdi
movl $0x2f00, %esi           # imm = 0x2F00
xorl %edx, %edx
callq 0x11c0
leaq 0x5ce5(%rip), %rcx      # 0xee70
pushq $0x2
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x2f00, %esi           # imm = 0x2F00
xorl %edx, %edx
callq 0x1060
leaq 0x5ce1(%rip), %rcx      # 0xee91
pushq $0x3
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
xorl %edx, %edx
callq 0x11c0
leaq 0x5cd1(%rip), %rcx      # 0xeea6
pushq $0x4
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x7c00, %esi           # imm = 0x7C00
xorl %edx, %edx
callq 0x1060
movq %r12, %rdi
movl $0x1600, %esi           # imm = 0x1600
xorl %edx, %edx
callq 0x11c0
leaq 0x5cb1(%rip), %rcx      # 0xeeba
pushq $0x5
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x1600, %esi           # imm = 0x1600
xorl %edx, %edx
callq 0x1060
movq %r12, %rdi
movl $0x1700, %esi           # imm = 0x1700
xorl %edx, %edx
callq 0x11c0
leaq 0x5c98(%rip), %rcx      # 0xeed5
pushq $0x6
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0x1700, %esi           # imm = 0x1700
xorl %edx, %edx
callq 0x1060
movq %r12, %rdi
movl $0xf500, %esi           # imm = 0xF500
xorl %edx, %edx
callq 0x11c0
leaq 0x5c81(%rip), %rcx      # 0xeef2
pushq $0x7
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
movl $0xf500, %esi           # imm = 0xF500
xorl %edx, %edx
callq 0x1060
leaq 0x5c7b(%rip), %rcx      # 0xef11
pushq $0x8
popq %rsi
movq %r12, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1070
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
callq 0x11e0
movl %eax, %r15d
subq $0x8, %rsp
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
movl %r13d, %ecx
movl %r13d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq $0x0
callq 0x1120
addq $0x18, %rsp
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
movl %r13d, %ecx
movl %r13d, %r8d
movl %r13d, %r9d
pushq %r13
pushq %r13
pushq %r13
callq 0x1120
addq $0x20, %rsp
movq %r12, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1100
movq %r12, %rdi
callq 0x1110
addl $-0x31, %r15d
cmpl $0x6, %r15d
ja 0x9596
leaq 0x50(%rsp), %rax
leaq 0x5720(%rip), %rcx      # 0xea50
movslq (%rcx,%r15,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq (%rsp), %rcx
cmpl $0x14, (%rcx)
jl 0x9596
movq 0x10(%rsp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
jle 0x9596
decl %ecx
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
movq (%rsp), %rcx
addl $-0x14, (%rcx)
movl 0x3c(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
negq %rcx
pushq $-0x1
popq %rdx
leaq (%rcx,%rdx), %rax
cmpq $-0x1, %rax
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, 0x8(%rbx,%rdx,8)
movq %rax, %rdx
jne 0x9375
movl %ebp, %ecx
jmp 0x9534
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0x9596
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movl 0x3c(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
negq %rcx
pushq $-0x1
popq %rdx
leaq (%rcx,%rdx), %rax
cmpq $-0x1, %rax
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, 0x8(%rbx,%rdx,8)
movq %rax, %rdx
jne 0x93c0
pushq $0x4
jmp 0x9533
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0xf, %ecx
jl 0x9596
addl $-0xf, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movl 0x3c(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
negq %rcx
pushq $-0x1
popq %rdx
leaq (%rcx,%rdx), %rax
cmpq $-0x1, %rax
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, 0x8(%rbx,%rdx,8)
movq %rax, %rdx
jne 0x940b
pushq $0x2
jmp 0x9533
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0x9596
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movl 0x3c(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
negq %rcx
pushq $-0x1
popq %rdx
leaq (%rcx,%rdx), %rax
cmpq $-0x1, %rax
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, 0x8(%rbx,%rdx,8)
movq %rax, %rdx
jne 0x9456
pushq $0x3
jmp 0x9533
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x1e, %ecx
jl 0x9596
addl $-0x1e, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movl 0x3c(%rax), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, (%rbx,%rdx,8)
movq %rax, %rdx
jne 0x949d
movl $0x2, -0x8(%rbx,%rax,8)
xorl %ecx, %ecx
cmpq $0x7, %rcx
je 0x9596
cmpl $0x0, (%r14)
jne 0x94d1
movl %ecx, -0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
jmp 0x94bd
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x28, %ecx
jl 0x9596
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx)
jle 0x9596
addl $-0x28, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rcx
decl (%rcx)
movl 0x3c(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
negq %rcx
pushq $-0x1
popq %rdx
leaq (%rcx,%rdx), %rax
cmpq $-0x1, %rax
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, 0x8(%rbx,%rdx,8)
movq %rax, %rdx
jne 0x9519
pushq $0x5
popq %rcx
movl $0x3, (%rbx,%rax,8)
movl %ecx, 0x4(%rbx,%rax,8)
jmp 0x9596
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x23, %ecx
jl 0x9596
addl $-0x23, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movl 0x3c(%rax), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x9596
leaq 0x1(%rdx), %rax
cmpl $-0x1, (%rbx,%rdx,8)
movq %rax, %rdx
jne 0x9561
movl $0x2, -0x8(%rbx,%rax,8)
xorl %ecx, %ecx
cmpq $0x7, %rcx
je 0x9596
cmpl $0x2, (%r14)
jne 0x958d
movl %ecx, -0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
jmp 0x957d
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq