// File: /workspace/github_c_makefile_star2_O3/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 0xa568
movl $0x13, %edx
movl $0x20, %ecx
jmp 0xa572
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 0x68cb(%rip), %rcx      # 0x10e87
movq %rbp, %rdi
movl $0x1, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x1070
movq %r13, 0x8(%rsp)
movl (%r13), %r8d
leaq 0x68b6(%rip), %rcx      # 0x10e96
movq %rbp, %rdi
movl $0x1, %esi
movl $0x10, %edx
xorl %eax, %eax
callq 0x1070
movq 0x10(%rsp), %rax
movl (%rax), %r8d
leaq 0x68a4(%rip), %rcx      # 0x10ea7
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 0x6874(%rip), %rcx      # 0x10eb0
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 0x686b(%rip), %rcx      # 0x10ed1
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 0x6856(%rip), %rcx      # 0x10ee6
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 0x6831(%rip), %rcx      # 0x10efa
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 0x6813(%rip), %rcx      # 0x10f15
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 0x67f7(%rip), %rcx      # 0x10f32
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 0x67ec(%rip), %rcx      # 0x10f51
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 0xaa72
leaq 0x50(%rsp), %rax
leaq 0x6271(%rip), %rcx      # 0x10a90
movslq (%rcx,%r13,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq (%rsp), %rcx
cmpl $0x14, (%rcx)
jl 0xaa72
movq 0x10(%rsp), %rcx
movl (%rcx), %ecx
testl %ecx, %ecx
jle 0xaa72
decl %ecx
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx)
movq (%rsp), %rcx
addl $-0x14, (%rcx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa5b
incq %rax
cmpq %rax, %rcx
jne 0xa863
jmp 0xaa72
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0xaa72
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa02
incq %rax
cmpq %rax, %rcx
jne 0xa8a1
jmp 0xaa72
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0xf, %ecx
jl 0xaa72
addl $-0xf, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa09
incq %rax
cmpq %rax, %rcx
jne 0xa8df
jmp 0xaa72
movq (%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x14, %ecx
jl 0xaa72
addl $-0x14, %ecx
movq (%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa10
incq %rax
cmpq %rax, %rcx
jne 0xa91d
jmp 0xaa72
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x1e, %ecx
jl 0xaa72
addl $-0x1e, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa17
incq %rax
cmpq %rax, %rcx
jne 0xa95d
jmp 0xaa72
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x28, %ecx
jl 0xaa72
movq 0x10(%rsp), %rdx
cmpl $0x0, (%rdx)
jle 0xaa72
addl $-0x28, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movq 0x10(%rsp), %rcx
decl (%rcx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa62
incq %rax
cmpq %rax, %rcx
jne 0xa9b2
jmp 0xaa72
movq 0x8(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x23, %ecx
jl 0xaa72
addl $-0x23, %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movslq 0x3c(%rax), %rcx
testq %rcx, %rcx
jle 0xaa72
xorl %eax, %eax
cmpl $-0x1, (%rbx,%rax,8)
je 0xaa39
incq %rax
cmpq %rax, %rcx
jne 0xa9f2
jmp 0xaa72
movl $0x4, %ecx
jmp 0xaa67
movl $0x2, %ecx
jmp 0xaa67
movl $0x3, %ecx
jmp 0xaa67
movl $0x2, (%rbx,%rax,8)
xorl %ecx, %ecx
cmpl $0x0, (%r14)
jne 0xaa2a
movl %ecx, 0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
cmpq $0x7, %rcx
jne 0xaa20
jmp 0xaa72
movl $0x2, (%rbx,%rax,8)
xorl %ecx, %ecx
cmpl $0x2, (%r14)
jne 0xaa4c
movl %ecx, 0x4(%rbx,%rax,8)
incq %rcx
addq $0x1c, %r14
cmpq $0x7, %rcx
jne 0xaa42
jmp 0xaa72
movl $0x1, %ecx
jmp 0xaa67
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