// File: Alcaro[P]bridges/game.cpp
// Function: (anonymous namespace)::game_impl::menu()
void menu()
	{
		background();
		
		if (in_press & 1<<k_left)
		{
			if (menu_focus == -1) menu_focus = 0;
			else if (menu_focus >= 100) menu_focus = (menu_focus-100)*10 + 9;
			else if (menu_focus%5 > 0) menu_focus--;
		}
		if (in_press & 1<<k_right)
		{
			if (menu_focus == -1) menu_focus = 0;
			else if (menu_focus < 100 && menu_focus%5 < 4) menu_focus++;
			else if (menu_focus%10 == 9 && unlocked >= menu_focus) menu_focus = 100 + (menu_focus/10);
		}
		if (in_press & 1<<k_up)
		{
			if (menu_focus == -1) menu_focus = 0;
			else if (menu_focus >= 100) menu_focus = (menu_focus-100)*10 + 4;
			else if (menu_focus/5 > 0) menu_focus -= 5;
		}
		if (in_press & 1<<k_down)
		{
			if (menu_focus == -1) menu_focus = 0;
			else if (menu_focus >= 100) menu_focus = (menu_focus-100)*10 + 14;
			else if (menu_focus/5 < unlocked-1) menu_focus += 5;
		}
		if (menu_focus < 100 && menu_focus > unlocked-1) menu_focus = unlocked-1;
		
		if (in_press & 1<<k_confirm)
		{
			if (menu_focus != -1)
				to_game(menu_focus, true);
		}
		if (in_press & 1<<k_cancel)
		{
			to_title();
		}
		
		resources::smallfont.color = 0xFFFFFF;
		
		static const char * const names[6] = {
			"Kimera - 7x7 Map (Tutorial)",
			"Remnant - 7x7 Map (Normal)",
			"Alchemia - 7x7 Map (Hard)",
			"Firestorm - 7x7 Map (Very Hard)", // originally Hardcore, but I'm not sure how that compares to Hard
			"Constantine - 9x9 Map (Normal)",
			"Silverstone - 9x9 Map (Hard)",
		};
		
		auto draw_level = [this](int x, int y, int n){
			out.insert(x, y, resources::levelbox);
			
			if (n < 100)
			{
				int d1 = (n+1)/10;
				int d2 = (n+1)%10;
				if (d1)
				{
					resources::smallfont.render(out, x+6    + 2*(d1==1), y+8, tostring(d1));
					resources::smallfont.render(out, x+6+12 + 2*(d2==1), y+8, tostring(d2));
				}
				else
				{
					resources::smallfont.render(out, x+6+6  + 2*(d2==1), y+8, tostring(d2));
				}
			}
			else
			{
				resources::smallfont.render(out, x+6+6+1, y+8, "?");
			}
			
			bool highlight = false;
			bool unlocked = (this->unlocked > n);
			if (n >= 100) unlocked = (this->unlocked >= (n-100)*5 + 11);
			if (unlocked && in.mousex >= x && in.mousex < x+35 && in.mousey >= y && in.mousey < y+35)
			{
				highlight = true;
				if (in_press & 1<<k_click)
					to_game(n, false);
			}
			if (menu_focus == n)
				highlight = true;
			if (highlight) // as a variable to make sure the box isn't drawn twice, that'd be ugly
				out.insert(x-10, y-10, resources::levelboxactive);
		};
		for (int y=0;y<6;y++)
		{
			int oy = 38+y*75;
			
			bool has_randoms = (y&1);
			
			bool b = (y>=4); // the rock tile contains a repeating pattern, better follow its size
			out.insert_tile_with_border(150 - 30*has_randoms, oy-8, 340 + 60*has_randoms, 50,
			                            (y<2 ? resources::fg0 : y<4 ? resources::fg1menu : resources::fg2),
			                            3+b, 37-b-b, 4+b, 36-b-b);
			
			for (int x=0;x<5+has_randoms;x++)
			{
				int ox = 182+60*x - 30*has_randoms;
				if (x==5) draw_level(ox, oy, 100 + y/2);
				else draw_level(ox, oy, y*5 + x);
			}
			
			if (unlocked <= (y+1)*5)
			{
				image outcrop;
				outcrop.init_ref(out);
				int hidefrom = 0;
				if (unlocked > y*5)
				{
					hidefrom = 170 + (unlocked - y*5)*60 - 30*has_randoms;
					outcrop.init_ref_sub(out, hidefrom,0, 640-hidefrom,480);
				}
				if (unlocked == (y+1)*5 && !has_randoms) hidefrom = 640;
				outcrop.insert_tile_with_border(150-hidefrom - 30*has_randoms, 30+y*75, 340 + 60*has_randoms, 50,
				                                (y<2 ? resources::fg0mask : y<4 ? resources::fg1mask : resources::fg0mask),
				                                3+b, 37-b, 4+b, 36-b);
			}
			
			uint32_t textwidth = resources::smallfont.measure(names[y]);
			resources::smallfont.render(out, 320-textwidth/2, oy-22, names[y]);
		}
		
		//no birds on the menu
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xe8, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x4ca10
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4958a
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x64(%rax)
jne 0x49544
movq -0x78(%rbp), %rax
movl $0x0, 0x64(%rax)
jmp 0x49588
movq -0x78(%rbp), %rax
cmpl $0x64, 0x64(%rax)
jl 0x49563
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
subl $0x64, %ecx
imull $0xa, %ecx, %ecx
addl $0x9, %ecx
movl %ecx, 0x64(%rax)
jmp 0x49586
movq -0x78(%rbp), %rax
movl 0x64(%rax), %eax
movl $0x5, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jle 0x49584
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x64(%rax)
jmp 0x49586
jmp 0x49588
jmp 0x4958a
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x49623
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x64(%rax)
jne 0x495b5
movq -0x78(%rbp), %rax
movl $0x0, 0x64(%rax)
jmp 0x49621
movq -0x78(%rbp), %rax
cmpl $0x64, 0x64(%rax)
jge 0x495e2
movq -0x78(%rbp), %rax
movl 0x64(%rax), %eax
movl $0x5, %ecx
cltd
idivl %ecx
cmpl $0x4, %edx
jge 0x495e2
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x64(%rax)
jmp 0x4961f
movq -0x78(%rbp), %rax
movl 0x64(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x9, %edx
jne 0x4961d
movq -0x78(%rbp), %rcx
movl 0x4c(%rcx), %eax
cmpl 0x64(%rcx), %eax
jl 0x4961d
movq -0x78(%rbp), %rax
movl 0x64(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x78(%rbp), %rax
addl $0x64, %ecx
movl %ecx, 0x64(%rax)
jmp 0x4961f
jmp 0x49621
jmp 0x49623
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x49690
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x64(%rax)
jne 0x4964a
movq -0x78(%rbp), %rax
movl $0x0, 0x64(%rax)
jmp 0x4968e
movq -0x78(%rbp), %rax
cmpl $0x64, 0x64(%rax)
jl 0x49669
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
subl $0x64, %ecx
imull $0xa, %ecx, %ecx
addl $0x4, %ecx
movl %ecx, 0x64(%rax)
jmp 0x4968c
movq -0x78(%rbp), %rax
movl 0x64(%rax), %eax
movl $0x5, %ecx
cltd
idivl %ecx
cmpl $0x0, %eax
jle 0x4968a
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
subl $0x5, %ecx
movl %ecx, 0x64(%rax)
jmp 0x4968c
jmp 0x4968e
jmp 0x49690
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x49702
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x64(%rax)
jne 0x496b7
movq -0x78(%rbp), %rax
movl $0x0, 0x64(%rax)
jmp 0x49700
movq -0x78(%rbp), %rax
cmpl $0x64, 0x64(%rax)
jl 0x496d6
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
subl $0x64, %ecx
imull $0xa, %ecx, %ecx
addl $0xe, %ecx
movl %ecx, 0x64(%rax)
jmp 0x496fe
movq -0x78(%rbp), %rcx
movl 0x64(%rcx), %eax
movl $0x5, %esi
cltd
idivl %esi
movl 0x4c(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x496fc
movq -0x78(%rbp), %rax
movl 0x64(%rax), %ecx
addl $0x5, %ecx
movl %ecx, 0x64(%rax)
jmp 0x496fe
jmp 0x49700
jmp 0x49702
movq -0x78(%rbp), %rax
cmpl $0x64, 0x64(%rax)
jge 0x4972a
movq -0x78(%rbp), %rcx
movl 0x64(%rcx), %eax
movl 0x4c(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x4972a
movq -0x78(%rbp), %rax
movl 0x4c(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x64(%rax)
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x49757
movq -0x78(%rbp), %rax
cmpl $-0x1, 0x64(%rax)
je 0x49755
movq -0x78(%rbp), %rdi
movl 0x64(%rdi), %esi
movl $0x1, %edx
callq 0x4cdf0
jmp 0x49757
movq -0x78(%rbp), %rax
movzbl 0x20(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x49770
movq -0x78(%rbp), %rdi
callq 0x48d30
movq -0x78(%rbp), %rax
leaq 0x68cad(%rip), %rcx     # 0xb2428
movl $0xffffff, 0x484(%rcx)  # imm = 0xFFFFFF
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x6, -0x1c(%rbp)
jge 0x49bc3
movq -0x78(%rbp), %rax
imull $0x4b, -0x1c(%rbp), %ecx
addl $0x26, %ecx
movl %ecx, -0x20(%rbp)
movl -0x1c(%rbp), %ecx
andl $0x1, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, -0x21(%rbp)
cmpl $0x4, -0x1c(%rbp)
setge %cl
andb $0x1, %cl
movb %cl, -0x22(%rbp)
addq $0x28, %rax
movq %rax, -0x90(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
imull $0x1e, %eax, %ecx
movl $0x96, %eax
subl %ecx, %eax
movl %eax, -0x84(%rbp)
movl -0x20(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x80(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
imull $0x3c, %eax, %eax
addl $0x154, %eax            # imm = 0x154
movl %eax, -0x7c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x4981c
leaq 0x378f1(%rip), %rax     # 0x81104
movq %rax, -0x98(%rbp)
jmp 0x49850
cmpl $0x4, -0x1c(%rbp)
jge 0x49832
leaq 0x3793b(%rip), %rax     # 0x81164
movq %rax, -0xa0(%rbp)
jmp 0x49842
leaq 0x37943(%rip), %rax     # 0x8117c
movq %rax, -0xa0(%rbp)
jmp 0x49842
movq -0xa0(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x7c(%rbp), %ecx
movl -0x80(%rbp), %edx
movl -0x84(%rbp), %esi
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %r9
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %ebx
addl $0x3, %ebx
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl $0x25, %r11d
subl %eax, %r11d
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
subl %eax, %r11d
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %r10d
addl $0x4, %r10d
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %r8d
movl $0x24, %eax
subl %r8d, %eax
movb -0x22(%rbp), %r8b
andb $0x1, %r8b
movzbl %r8b, %r8d
subl %r8d, %eax
movl $0x32, %r8d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x18bb0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl $0x5, %ecx
cmpl %ecx, %eax
jge 0x49967
imull $0x3c, -0x28(%rbp), %eax
addl $0xb6, %eax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
imull $0x1e, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x5, -0x28(%rbp)
jne 0x49941
movl -0x2c(%rbp), %esi
movl -0x20(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x1c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0xa4(%rbp), %edx
movl %eax, %ecx
addl $0x64, %ecx
leaq -0x18(%rbp), %rdi
callq 0x4ce40
jmp 0x49957
movl -0x2c(%rbp), %esi
movl -0x20(%rbp), %edx
imull $0x5, -0x1c(%rbp), %ecx
addl -0x28(%rbp), %ecx
leaq -0x18(%rbp), %rdi
callq 0x4ce40
jmp 0x49959
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x498e1
movq -0x78(%rbp), %rax
movl 0x4c(%rax), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
imull $0x5, %ecx, %ecx
cmpl %ecx, %eax
jg 0x49b09
movq -0x78(%rbp), %rsi
addq $0x28, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1af30
movq -0x78(%rbp), %rax
movl $0x0, -0x4c(%rbp)
movl 0x4c(%rax), %eax
imull $0x5, -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jle 0x499ee
movq -0x78(%rbp), %rsi
movl 0x4c(%rsi), %eax
imull $0x5, -0x1c(%rbp), %ecx
subl %ecx, %eax
imull $0x3c, %eax, %eax
addl $0xaa, %eax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
imull $0x1e, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
addq $0x28, %rsi
movl -0x4c(%rbp), %edx
movl $0x280, %r8d            # imm = 0x280
subl -0x4c(%rbp), %r8d
leaq -0x48(%rbp), %rdi
xorl %ecx, %ecx
movl $0x1e0, %r9d            # imm = 0x1E0
callq 0x1afe0
movq -0x78(%rbp), %rax
movl 0x4c(%rax), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
imull $0x5, %ecx, %ecx
cmpl %ecx, %eax
jne 0x49a0f
testb $0x1, -0x21(%rbp)
jne 0x49a0f
movl $0x280, -0x4c(%rbp)     # imm = 0x280
movl $0x96, %eax
subl -0x4c(%rbp), %eax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
imull $0x1e, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0xb0(%rbp)
imull $0x4b, -0x1c(%rbp), %eax
addl $0x1e, %eax
movl %eax, -0xac(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
imull $0x3c, %eax, %eax
addl $0x154, %eax            # imm = 0x154
movl %eax, -0xa8(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x49a64
leaq 0x376c1(%rip), %rax     # 0x8111c
movq %rax, -0xb8(%rbp)
jmp 0x49a98
cmpl $0x4, -0x1c(%rbp)
jge 0x49a7a
leaq 0x376db(%rip), %rax     # 0x8114c
movq %rax, -0xc0(%rbp)
jmp 0x49a8a
leaq 0x3769b(%rip), %rax     # 0x8111c
movq %rax, -0xc0(%rbp)
jmp 0x49a8a
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0xa8(%rbp), %ecx
movl -0xac(%rbp), %edx
movl -0xb0(%rbp), %esi
movq -0xb8(%rbp), %r9
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %ebx
addl $0x3, %ebx
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl $0x25, %r11d
subl %eax, %r11d
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %r10d
addl $0x4, %r10d
movb -0x22(%rbp), %al
andb $0x1, %al
movzbl %al, %edi
movl $0x24, %eax
subl %edi, %eax
leaq -0x48(%rbp), %rdi
movl $0x32, %r8d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x18bb0
movslq -0x1c(%rbp), %rcx
leaq 0x36cbc(%rip), %rax     # 0x807d0
movq (%rax,%rcx,8), %rsi
leaq -0x60(%rbp), %rdi
callq 0x58c0
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq 0x688f8(%rip), %rdi     # 0xb2428
xorps %xmm0, %xmm0
callq 0x472e0
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, -0x50(%rbp)
addq $0x28, %rax
movq %rax, -0xd0(%rbp)
movl -0x50(%rbp), %ecx
shrl %ecx
movl $0x140, %eax            # imm = 0x140
subl %ecx, %eax
movl %eax, -0xc8(%rbp)
movl -0x20(%rbp), %eax
subl $0x16, %eax
movl %eax, -0xc4(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x36c5b(%rip), %rax     # 0x807d0
movq (%rax,%rcx,8), %rsi
leaq -0x70(%rbp), %rdi
callq 0x58c0
movq -0xd0(%rbp), %rsi
movl -0xc8(%rbp), %edx
movl -0xc4(%rbp), %ecx
movq -0x70(%rbp), %r8
movq -0x68(%rbp), %r9
leaq 0x68884(%rip), %rdi     # 0xb2428
xorps %xmm0, %xmm0
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x473f0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x49790
addq $0xe8, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)