// File: Alcaro[P]bridges/ui-arlib.cpp
// Function: main
int main(int argc, char** argv)
{
	static uint32_t pixels[640*480]; // static to keep the stack frame small
	image out; // initialized up here so perf-ui can use it too
	out.init_ptr(pixels, 640, 480, sizeof(uint32_t)*640, ifmt_xrgb8888); // xrgb is faster than 0rgb
	
#ifndef STDOUT_ERROR
	argparse args;
	bool do_bench_solv = false;
	args.add("perf-solv", &do_bench_solv);
	bool do_bench_ui = false;
	args.add("perf-ui", &do_bench_ui);
	args.parse(argv);
	
	if (do_bench_solv && do_bench_ui)
	{
		puts("can't benchmark both solver and UI");
		return 1;
	}
	if (do_bench_solv)
	{
		g_rand.seed(0);
		bool vg = RUNNING_ON_VALGRIND;
		uint64_t start = time_ms_ne();
		
		int nsolv = 0;
		int nunsolv = 0;
		int nmultisolv = 0;
		for (int side=3;side<10;side++)
		{
			for (int i=0;i<(vg ? 1000 : 10000);i++) // ignore benchmark, we want iteration count constant between runs
			{
				if (i%(vg ? 10 : 100) == 0) { printf("%i %i     \r", side, i); fflush(stdout); }
				
				gamemap::genparams par = {};
				par.width = side;
				par.height = side;
				par.density = 0.4;
				par.dense = true;
				par.use_reef = false;
				par.use_large = false;
				par.use_castle = false;
				par.allow_ambiguous = true;
				par.difficulty = 0.0;
				par.quality = 1;
				
				gamemap map;
				map.generate(par);
				map.reset();
				int result = 0;
				if (map.solve())
				{
					result = 1;
					if (map.solve_another()) result = 2;
				}
				
				if (result == 0)
				{
					puts("ERROR");
					puts(map.serialize());
					exit(1);
				}
				if (result == 0) nunsolv++;
				if (result == 1) nsolv++;
				if (result == 2) nmultisolv++;
			}
		}
		uint64_t end = time_ms_ne();
		//expected (with side = 3..9, i = 0..9999, generate.cpp md5 f32cac429a654b96cc327086541aac4b):
		//41535 solvable, 0 unsolvable, 28465 multiple solutions, took 7266 ms
		printf("%i solvable, %i unsolvable, %i multiple solutions, took %u ms\n",
		       nsolv, nunsolv, nmultisolv, (unsigned)(end-start));
		
		return 0;
	}
	if (do_bench_ui)
	{
		game* g = game::create();
		game::input in = {};
		game::input in_press = {};
		in_press.keys = 1 << game::k_confirm;
		
		using (benchmark b)
		{
			while (b) g->run(in, out);
			printf("title screen: %u frames in %ums = %ffps\n", b.iterations, b.us/1000, b.per_second());
		}
		
		g->run(in_press, out);
		
		using (benchmark b)
		{
			while (b) g->run(in, out);
			printf("level select: %u frames in %ums = %ffps\n", b.iterations, b.us/1000, b.per_second());
		}
		
		g->run(in_press, out);
		
		using (benchmark b)
		{
			while (b) g->run(in, out);
			printf("ingame: %u frames in %ums = %ffps\n", b.iterations, b.us/1000, b.per_second());
		}
		
		return 0;
	}
#endif
	
	aropengl gl;
	autoptr<gameview> gv = gameview::create(gl, 640, 480, aropengl::t_ver_1_0/*|aropengl::t_direct3d_vsync*/, "bridges");
	gl.swapInterval(1);
	
	gl.MatrixMode(GL_PROJECTION);
	gl.LoadIdentity();
	gl.Ortho(0, 640, 0, 480, -1.0, 1.0);
	gl.Viewport(0, 0, 640, 480);
	
	gl.MatrixMode(GL_MODELVIEW);
	gl.LoadIdentity();
	
	gl.Enable(GL_TEXTURE_2D);
	GLuint tex;
	gl.GenTextures(1, &tex);
	gl.BindTexture(GL_TEXTURE_2D, tex);
	
	gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1024, 512, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
	gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	
	// save support not implemented here, just hardcode something reasonable
	// the long-term plan has always been making this game a libretro core, this frontend is mostly a far-too-long-lived placeholder
	static const uint8_t save[] = { 31,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
	autoptr<game> g = game::create(save);
	game::input in = {};
	
	gv->keys_cb([&in](int scancode, gameview::key_t key, bool down) {
//printf("key %d,%d,%d\n",scancode,key,down);
		int bit;
		if(0);
		else if (key == gameview::K_RIGHT  || key == gameview::K_d)         bit = game::k_right;
		else if (key == gameview::K_UP     || key == gameview::K_w)         bit = game::k_up;
		else if (key == gameview::K_LEFT   || key == gameview::K_a)         bit = game::k_left;
		else if (key == gameview::K_DOWN   || key == gameview::K_s)         bit = game::k_down;
		else if (key == gameview::K_RETURN || key == gameview::K_SPACE)     bit = game::k_confirm;
		else if (key == gameview::K_ESCAPE || key == gameview::K_BACKSPACE) bit = game::k_cancel;
		else return;
		
		in.keys = (in.keys & ~(1<<bit)) | (down << bit);
	});
	
	gv->mouse_cb([&in](int x, int y, uint8_t buttons) {
//printf("mouse %d,%d,%d\n",x,y,buttons);
		in.mousex = x;
		in.mousey = y;
		in.lmousedown = (buttons&1);
		in.rmousedown = (buttons&2);
	});
	
	bool first = true;
	bool active = true;
	
	//time_t t=0;
	//int fps=0;
	
	while (gv->running())
	{
		//fps++;
		//if (t != time(NULL))
		//{
//printf("%dfps\n",fps);
			//fps = 0;
			//t = time(NULL);
		//}
		
		if (active)
		{
#if defined(ARLIB_OPT) && !defined(STDOUT_ERROR)
			timer t;
#endif
			int do_upload = g->run(in, out, !first);
			first = false;
#if defined(ARLIB_OPT) && !defined(STDOUT_ERROR)
			if (t.us() >= 2500)
				printf("rendered in %uus\n", (unsigned)t.us());
#endif
			if (do_upload > 0) gl.TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 640, 480, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
			active = (do_upload >= 0);
		}
		
		//redraw the texture, to avoid glitches if compositor discarded our pixels
		//no point reuploading, and no point checking why gv->tmp_step returned, just redraw
		gl.Clear(GL_COLOR_BUFFER_BIT); // does nothing, but docs say it makes things faster
		gl.Begin(GL_TRIANGLE_STRIP);
		gl.TexCoord2f(0,            0          ); gl.Vertex3i(0,   480, 0);
		gl.TexCoord2f(640.0/1024.0, 0          ); gl.Vertex3i(640, 480, 0);
		gl.TexCoord2f(0,            480.0/512.0); gl.Vertex3i(0,   0,   0);
		gl.TexCoord2f(640.0/1024.0, 480.0/512.0); gl.Vertex3i(640, 0,   0);
		gl.End();
		
		gl.swapBuffers();
		
		gv->step(!active);
		active = (gv->focused()); // keep them in this order, so the pause-if-inactive implementation works
	}
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x26ac0, %rsp          # imm = 0x26AC0
movl $0x0, -0x34(%rbp)
movl %edi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
leaq 0x5825c(%rip), %rsi     # 0xb28e0
movl $0x280, %edx            # imm = 0x280
movl $0x1e0, %ecx            # imm = 0x1E0
movl $0xa00, %r8d            # imm = 0xA00
movl $0x6, %r9d
callq 0x1aef0
leaq -0x98(%rbp), %rdi
callq 0x5b650
movb $0x0, -0x99(%rbp)
leaq -0xb0(%rbp), %rdi
leaq 0xc7f0(%rip), %rsi      # 0x66eb0
callq 0x58c0
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rcx
callq 0x5b6a0
movb $0x0, -0xb1(%rbp)
leaq -0xc8(%rbp), %rdi
leaq 0xc7bf(%rip), %rsi      # 0x66eba
callq 0x58c0
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x98(%rbp), %rdi
leaq -0xb1(%rbp), %rcx
callq 0x5b6a0
movq -0x40(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x51b0
testb $0x1, -0x99(%rbp)
je 0x5a765
testb $0x1, -0xb1(%rbp)
je 0x5a765
leaq 0xc778(%rip), %rdi      # 0x66ec2
callq 0x4580
movl $0x1, -0x34(%rbp)
movl $0x1, -0xcc(%rbp)
jmp 0x5b209
testb $0x1, -0x99(%rbp)
je 0x5ab13
leaq 0x26cb7(%rip), %rdi     # 0x81430
xorl %eax, %eax
movl %eax, %esi
callq 0x2feb0
movq $0x1001, -0x100(%rbp) # imm = 0x1001
movq $0x0, -0xf8(%rbp)
movq $0x0, -0xf0(%rbp)
movq $0x0, -0xe8(%rbp)
movq $0x0, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
leaq -0x100(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
rolq $0x3, %rdi
rolq $0xd, %rdi
rolq $0x3d, %rdi
rolq $0x33, %rdi
xchgq %rbx, %rbx
movq %rdx, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0xcd(%rbp)
callq 0x42cc0
movq %rax, -0x118(%rbp)
movl $0x0, -0x11c(%rbp)
movl $0x0, -0x120(%rbp)
movl $0x0, -0x124(%rbp)
movl $0x3, -0x128(%rbp)
cmpl $0xa, -0x128(%rbp)
jge 0x5aac0
movl $0x0, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
movb -0xcd(%rbp), %sil
movl $0x2710, %ecx           # imm = 0x2710
movl $0x3e8, %edx            # imm = 0x3E8
testb $0x1, %sil
cmovnel %edx, %ecx
cmpl %ecx, %eax
jge 0x5aaaa
movl -0x12c(%rbp), %eax
movb -0xcd(%rbp), %sil
movl $0x64, %ecx
movl $0xa, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x5a8cc
movl -0x128(%rbp), %esi
movl -0x12c(%rbp), %edx
leaq 0xc62f(%rip), %rdi      # 0x66ee5
movb $0x0, %al
callq 0x4050
movq 0x26704(%rip), %rax     # 0x80fc8
movq (%rax), %rdi
callq 0x43f0
movb $0x0, -0x160(%rbp)
movb $0x0, -0x15f(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x15c(%rbp)
movb $0x0, -0x158(%rbp)
movb $0x0, -0x157(%rbp)
movb $0x0, -0x156(%rbp)
movb $0x0, -0x155(%rbp)
movb $0x0, -0x154(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x150(%rbp)
movl $0x0, -0x14c(%rbp)
leaq -0x160(%rbp), %rdi
addq $0x18, %rdi
callq 0x4e750
movl -0x128(%rbp), %eax
movb %al, -0x160(%rbp)
movl -0x128(%rbp), %eax
movb %al, -0x15f(%rbp)
movss 0xb607(%rip), %xmm0     # 0x65f54
movss %xmm0, -0x15c(%rbp)
movb $0x1, -0x158(%rbp)
movb $0x0, -0x157(%rbp)
movb $0x0, -0x156(%rbp)
movb $0x0, -0x155(%rbp)
movb $0x1, -0x154(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x150(%rbp)
movl $0x1, -0x14c(%rbp)
leaq -0x24b68(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x4e870
leaq -0x24b68(%rbp), %rdi
callq 0x4f3c0
movl $0x0, -0x24b6c(%rbp)
leaq -0x24b68(%rbp), %rdi
callq 0x53bd0
testb $0x1, %al
jne 0x5a9c8
jmp 0x5a9f0
movl $0x1, -0x24b6c(%rbp)
leaq -0x24b68(%rbp), %rdi
callq 0x542f0
testb $0x1, %al
jne 0x5a9e4
jmp 0x5a9ee
movl $0x2, -0x24b6c(%rbp)
jmp 0x5a9f0
cmpl $0x0, -0x24b6c(%rbp)
jne 0x5aa42
leaq 0xc4f1(%rip), %rdi      # 0x66ef1
callq 0x4580
leaq -0x24b80(%rbp), %rdi
leaq -0x24b68(%rbp), %rsi
callq 0x4f7f0
leaq -0x24b80(%rbp), %rdi
callq 0x5660
movq %rax, %rdi
callq 0x4580
leaq -0x24b80(%rbp), %rdi
callq 0x5870
movl $0x1, %edi
callq 0x4430
cmpl $0x0, -0x24b6c(%rbp)
jne 0x5aa5a
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
cmpl $0x1, -0x24b6c(%rbp)
jne 0x5aa72
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
cmpl $0x2, -0x24b6c(%rbp)
jne 0x5aa8a
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x4e710
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x5a857
jmp 0x5aaac
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x5a840
callq 0x42cc0
movq %rax, -0x24b88(%rbp)
movl -0x11c(%rbp), %esi
movl -0x120(%rbp), %edx
movl -0x124(%rbp), %ecx
movq -0x24b88(%rbp), %rax
subq -0x118(%rbp), %rax
movl %eax, %r8d
leaq 0xc401(%rip), %rdi      # 0x66ef7
movb $0x0, %al
callq 0x4050
movl $0x0, -0x34(%rbp)
movl $0x1, -0xcc(%rbp)
jmp 0x5b209
testb $0x1, -0xb1(%rbp)
je 0x5add5
callq 0x47ff0
movq %rax, -0x24b90(%rbp)
leaq -0x24b9c(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4170
leaq -0x24ba8(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4170
movb $0x10, -0x24b9e(%rbp)
leaq -0x24bb8(%rbp), %rdi
callq 0x5b6f0
leaq -0x24bb8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x26a68(%rbp)
movl 0x8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x8(%rcx)
movl 0x8(%rcx), %eax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x5aba7
movq -0x26a68(%rbp), %rdi
callq 0x5c0d0
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x5abab
movb $0x1, -0x1(%rbp)
testb $0x1, -0x1(%rbp)
jne 0x5abb3
jmp 0x5abce
movq -0x24b90(%rbp), %rdi
movq (%rdi), %rax
leaq -0x24b9c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq *(%rax)
jmp 0x5ab65
movl -0x24bb0(%rbp), %eax
movl %eax, -0x26a70(%rbp)
movl -0x24bac(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, -0x26a6c(%rbp)
leaq -0x24bb8(%rbp), %rdi
callq 0x5b730
movl -0x26a70(%rbp), %esi
movl -0x26a6c(%rbp), %edx
leaq 0xc328(%rip), %rdi      # 0x66f36
movb $0x1, %al
callq 0x4050
movq -0x24b90(%rbp), %rdi
movq (%rdi), %rax
leaq -0x24ba8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq *(%rax)
leaq -0x24bc8(%rbp), %rdi
callq 0x5b6f0
leaq -0x24bc8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq %rcx, -0x26a78(%rbp)
movl 0x8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x8(%rcx)
movl 0x8(%rcx), %eax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x5ac7c
movq -0x26a78(%rbp), %rdi
callq 0x5c0d0
andb $0x1, %al
movb %al, -0x11(%rbp)
jmp 0x5ac80
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x5ac88
jmp 0x5aca3
movq -0x24b90(%rbp), %rdi
movq (%rdi), %rax
leaq -0x24b9c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq *(%rax)
jmp 0x5ac3a
movl -0x24bc0(%rbp), %eax
movl %eax, -0x26a80(%rbp)
movl -0x24bbc(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, -0x26a7c(%rbp)
leaq -0x24bc8(%rbp), %rdi
callq 0x5b730
movl -0x26a80(%rbp), %esi
movl -0x26a7c(%rbp), %edx
leaq 0xc27c(%rip), %rdi      # 0x66f5f
movb $0x1, %al
callq 0x4050
movq -0x24b90(%rbp), %rdi
movq (%rdi), %rax
leaq -0x24ba8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq *(%rax)
leaq -0x24bd8(%rbp), %rdi
callq 0x5b6f0
leaq -0x24bd8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, -0x26a88(%rbp)
movl 0x8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x8(%rcx)
movl 0x8(%rcx), %eax
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x5ad51
movq -0x26a88(%rbp), %rdi
callq 0x5c0d0
andb $0x1, %al
movb %al, -0x21(%rbp)
jmp 0x5ad55
movb $0x1, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
jne 0x5ad5d
jmp 0x5ad78
movq -0x24b90(%rbp), %rdi
movq (%rdi), %rax
leaq -0x24b9c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq *(%rax)
jmp 0x5ad0f
movl -0x24bd0(%rbp), %eax
movl %eax, -0x26a90(%rbp)
movl -0x24bcc(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, -0x26a8c(%rbp)
leaq -0x24bd8(%rbp), %rdi
callq 0x5b730
movl -0x26a90(%rbp), %esi
movl -0x26a8c(%rbp), %edx
leaq 0xc1d0(%rip), %rdi      # 0x66f88
movb $0x1, %al
callq 0x4050
movl $0x0, -0x34(%rbp)
movl $0x1, -0xcc(%rbp)
jmp 0x5b209
leaq -0x269c8(%rbp), %rdi
callq 0x5b760
leaq -0x269e0(%rbp), %rdi
leaq 0xc1bc(%rip), %rsi      # 0x66fab
callq 0x58c0
movq -0x269e0(%rbp), %r8
movq -0x269d8(%rbp), %r9
leaq -0x269c8(%rbp), %rdi
movl $0x280, %esi            # imm = 0x280
movl $0x1e0, %edx            # imm = 0x1E0
movl $0x64, %ecx
callq 0x5b780
movq %rax, %rsi
leaq -0x269d0(%rbp), %rdi
callq 0x5b820
leaq -0x269c8(%rbp), %rdi
movl $0x1, %esi
callq 0x5b840
movl $0x1701, %edi           # imm = 0x1701
callq *-0x25bd8(%rbp)
callq *-0x25c80(%rbp)
xorps %xmm2, %xmm2
movsd 0xc02f(%rip), %xmm1     # 0x66e88
movsd 0xc02f(%rip), %xmm3     # 0x66e90
movsd 0xc02f(%rip), %xmm4     # 0x66e98
movsd 0x8f8f(%rip), %xmm5     # 0x63e00
movaps %xmm2, %xmm0
callq *-0x259b0(%rbp)
xorl %esi, %esi
movl $0x280, %edx            # imm = 0x280
movl $0x1e0, %ecx            # imm = 0x1E0
movl %esi, %edi
callq *-0x24c80(%rbp)
movl $0x1700, %edi           # imm = 0x1700
callq *-0x25bd8(%rbp)
callq *-0x25c80(%rbp)
movl $0xde1, %edi            # imm = 0xDE1
callq *-0x263b0(%rbp)
movl $0x1, %edi
leaq -0x269e4(%rbp), %rsi
callq *-0x26210(%rbp)
movq -0x268e8(%rbp), %rax
movl -0x269e4(%rbp), %esi
movl $0xde1, %edi            # imm = 0xDE1
callq *%rax
movl $0xde1, %edi            # imm = 0xDE1
xorl %r9d, %r9d
movl $0x8051, %edx           # imm = 0x8051
movl $0x400, %ecx            # imm = 0x400
movl $0x200, %r8d            # imm = 0x200
xorl %eax, %eax
movl %r9d, %esi
movl $0x80e1, (%rsp)         # imm = 0x80E1
movl $0x8367, 0x8(%rsp)      # imm = 0x8367
movq $0x0, 0x10(%rsp)
callq *-0x25278(%rbp)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2800, %esi           # imm = 0x2800
movl $0x2600, %edx           # imm = 0x2600
callq *-0x25238(%rbp)
movl $0xde1, %edi            # imm = 0xDE1
movl $0x2801, %esi           # imm = 0x2801
movl $0x2600, %edx           # imm = 0x2600
callq *-0x25238(%rbp)
leaq -0x26a00(%rbp), %rdi
leaq 0xc07d(%rip), %rsi      # 0x66fc0
callq 0x5b870
movq -0x26a00(%rbp), %rdi
movq -0x269f8(%rbp), %rsi
callq 0x480e0
movq %rax, %rsi
leaq -0x269f0(%rbp), %rdi
callq 0x5b8a0
leaq -0x26a0c(%rbp), %rdi
xorl %esi, %esi
movl $0xc, %edx
callq 0x4170
leaq -0x269d0(%rbp), %rdi
callq 0x5b8c0
movq %rax, -0x26aa0(%rbp)
leaq -0x26a0c(%rbp), %rax
movq %rax, -0x26a30(%rbp)
movq -0x26a30(%rbp), %rsi
leaq -0x26a28(%rbp), %rdi
callq 0x5b230
movq -0x26aa0(%rbp), %rdi
movq (%rdi), %rax
leaq -0x26a28(%rbp), %rsi
callq *0x38(%rax)
leaq -0x26a28(%rbp), %rdi
callq 0x141b0
leaq -0x269d0(%rbp), %rdi
callq 0x5b8c0
movq %rax, -0x26a98(%rbp)
leaq -0x26a0c(%rbp), %rax
movq %rax, -0x26a58(%rbp)
movq -0x26a58(%rbp), %rsi
leaq -0x26a50(%rbp), %rdi
callq 0x5b260
movq -0x26a98(%rbp), %rdi
movq (%rdi), %rax
leaq -0x26a50(%rbp), %rsi
callq *0x40(%rax)
leaq -0x26a50(%rbp), %rdi
callq 0x14190
movb $0x1, -0x26a5a(%rbp)
movb $0x1, -0x26a5b(%rbp)
leaq -0x269d0(%rbp), %rdi
callq 0x5b8c0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x8(%rax)
testb $0x1, %al
jne 0x5b051
jmp 0x5b1e0
testb $0x1, -0x26a5b(%rbp)
je 0x5b0ef
leaq -0x269f0(%rbp), %rdi
callq 0x5b8e0
movq %rax, %rdi
movb -0x26a5a(%rbp), %cl
xorb $-0x1, %cl
movq (%rdi), %rax
movq (%rax), %rax
movzbl %cl, %ecx
andl $0x1, %ecx
leaq -0x26a0c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq *%rax
movl %eax, -0x26a60(%rbp)
movb $0x0, -0x26a5a(%rbp)
cmpl $0x0, -0x26a60(%rbp)
jle 0x5b0dd
movl $0xde1, %edi            # imm = 0xDE1
xorl %ecx, %ecx
movl $0x280, %r8d            # imm = 0x280
movl $0x1e0, %r9d            # imm = 0x1E0
leaq 0x57821(%rip), %rax     # 0xb28e0
movl %ecx, %esi
movl %ecx, %edx
movl $0x80e1, (%rsp)         # imm = 0x80E1
movl $0x8367, 0x8(%rsp)      # imm = 0x8367
movq %rax, 0x10(%rsp)
callq *-0x251f8(%rbp)
cmpl $0x0, -0x26a60(%rbp)
setge %al
andb $0x1, %al
movb %al, -0x26a5b(%rbp)
movl $0x4000, %edi           # imm = 0x4000
callq *-0x26828(%rbp)
movl $0x5, %edi
callq *-0x26988(%rbp)
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq *-0x253c8(%rbp)
xorl %edx, %edx
movl $0x1e0, %esi            # imm = 0x1E0
movl %edx, %edi
callq *-0x24fa0(%rbp)
movss 0xbd80(%rip), %xmm0     # 0x66ea8
xorps %xmm1, %xmm1
callq *-0x253c8(%rbp)
movl $0x280, %edi            # imm = 0x280
movl $0x1e0, %esi            # imm = 0x1E0
xorl %edx, %edx
callq *-0x24fa0(%rbp)
xorps %xmm0, %xmm0
movss 0xbd5e(%rip), %xmm1     # 0x66eac
callq *-0x253c8(%rbp)
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq *-0x24fa0(%rbp)
movss 0xbd40(%rip), %xmm0     # 0x66ea8
movss 0xbd3c(%rip), %xmm1     # 0x66eac
callq *-0x253c8(%rbp)
movl $0x280, %edi            # imm = 0x280
xorl %edx, %edx
movl %edx, %esi
callq *-0x24fa0(%rbp)
callq *-0x26390(%rbp)
leaq -0x269c8(%rbp), %rdi
callq 0x5b900
leaq -0x269d0(%rbp), %rdi
callq 0x5b8c0
movq %rax, %rdi
movb -0x26a5b(%rbp), %cl
xorb $-0x1, %cl
movq (%rdi), %rax
movq 0x30(%rax), %rax
movzbl %cl, %esi
andl $0x1, %esi
callq *%rax
leaq -0x269d0(%rbp), %rdi
callq 0x5b8c0
movq %rax, %rdi
movq (%rdi), %rax
callq *0x18(%rax)
andb $0x1, %al
movb %al, -0x26a5b(%rbp)
jmp 0x5b033
movl $0x0, -0x34(%rbp)
movl $0x1, -0xcc(%rbp)
leaq -0x269f0(%rbp), %rdi
callq 0x5b920
leaq -0x269d0(%rbp), %rdi
callq 0x5b940
leaq -0x98(%rbp), %rdi
callq 0x5b960
movl -0x34(%rbp), %eax
addq $0x26ac0, %rsp          # imm = 0x26AC0
popq %rbp
retq
nopw %cs:(%rax,%rax)