// File: kodejuice[P]chip8-emulator/main.cc
// Function: main
int main(int argc, char** argv) {
	if (argc < 2)
		COMMAND_USAGE;

	Chip8 cpu = Chip8();

	string arg1 = string(argv[1]);
	if (arg1 == "--decode") {
		// load/decode program
		if (argc < 3) COMMAND_USAGE;
		cpu.load_program(argv[2]);

		cout << cpu.disassemble();
		return 0;
	}
	else {
		// load program
		if (!cpu.load_program(arg1)) exit(1);
	}

	printf("\nPress P to pause emulation.\n");


	/////////
	// GUI //
	/////////

	string filename = getfilename(arg1);

	// create window
	string title = "Chip8 Emulator - " + filename;
	SDL_Window* window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, W, H, SDL_WINDOW_RESIZABLE);
	SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); SDL_RenderSetLogicalSize(renderer, W, H);
	SDL_Texture* texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);

	// mapping of SDL keyboard symbols to chip8 keypad codes
	unordered_map<int,int> keymap{
		{SDLK_1, 0x1}, {SDLK_2, 0x2}, {SDLK_3, 0x3}, {SDLK_4, 0xC},
		{SDLK_q, 0x4}, {SDLK_w, 0x5}, {SDLK_e, 0x6}, {SDLK_r, 0xD},
		{SDLK_a, 0x7}, {SDLK_s, 0x8}, {SDLK_d, 0x9}, {SDLK_f, 0xE},
		{SDLK_z, 0xA}, {SDLK_x, 0x0}, {SDLK_c, 0xB}, {SDLK_v, 0xF},
		{SDLK_5, 0x5}, {SDLK_6, 0x6}, {SDLK_7, 0x7}, {SDLK_p, -2},
		{SDLK_8, 0x8}, {SDLK_9, 0x9}, {SDLK_0, 0x0}, {SDLK_ESCAPE,-1}
	};

	// Init. SDL audio
	SDL_AudioSpec spec, obtained;
	spec.freq     = 44100;
	spec.format   = AUDIO_S16SYS;
	spec.channels = 2;
	spec.samples  = spec.freq/20;
	spec.callback = [](void*, Uint8* stream, int len) {
		short* target = (short*)stream;
		while(len > 0 && !AudioQueue.empty()) {
			auto& data = AudioQueue.front();
			for(; len && data.first; target += 2, len -= 4, --data.first)
				target[0] = target[1] = data.second*300*((len&128)-64);
			if(!data.first) AudioQueue.pop_front();
		}
	};
	SDL_OpenAudio(&spec, &obtained);
	SDL_PauseAudio(0);


	int msg = 0;
	int frames_done = 0;
	bool running = true,
		 paused = false;


	auto start = chrono::system_clock::now();
	while (running) {

		/////////////////////////
		// Execute Instruction //
		/////////////////////////
		if (!cpu.awaitingKey && !paused)
			// if not waiting for input nor paused
			cpu.emulate_op();

		if (paused && !msg) {
			printf("\nPaused\n");
			msg = 1;
		}

		////////////////////
		// Process events //
		////////////////////
		for(SDL_Event ev; SDL_PollEvent(&ev); )
			switch(ev.type)
			{
				case SDL_QUIT: running = 0; break;
				case SDL_KEYDOWN:
				case SDL_KEYUP:
					auto i = keymap.find(ev.key.keysym.sym);

					if (i == keymap.end()) break;
					if (i->second == -1) { running = 0; break; }
					if (i->second == -2 && ev.type==SDL_KEYDOWN) {
						paused=!paused, msg=0;
						if (!paused) printf("Resumed\n");
						break;
					}

					cpu.key_pressed[i->second] = (ev.type == SDL_KEYDOWN);

					if(ev.type==SDL_KEYDOWN && cpu.awaitingKey) {
						cpu.V[cpu.awaitingKey & 0x7f] = i->second;
						cpu.awaitingKey = 0;
					}
			}


		/////////////
		// Render  //
		/////////////
		auto cur = chrono::system_clock::now();

		chrono::duration<double> elapsed_seconds = cur-start;
		int frames = int(elapsed_seconds.count() * 60) - frames_done;

		if (frames > 0 && !paused) {
			frames_done += frames;

            // Update the timer registers
            int st = min<int>(frames, cpu.ST); cpu.ST -= st;
            int dt = min<int>(frames, cpu.DT); cpu.DT -= dt;

            //////////////////
            // Render audio //
            SDL_LockAudio();
             AudioQueue.emplace_back( obtained.freq*st/60,  true );
             AudioQueue.emplace_back( obtained.freq*(frames-st)/60, false );
            SDL_UnlockAudio();

			/////////////////////
			// Render graphics //
			if (cpu.redraw) {
				renderTo(pixels, cpu.screen);
				SDL_UpdateTexture(texture, nullptr, pixels, 4*w);
				SDL_RenderClear(renderer);
				SDL_RenderCopy(renderer, texture, nullptr, nullptr);
				SDL_RenderPresent(renderer);

				cpu.redraw = false;
			}
		}

		if (!paused)
			this_thread::sleep_for(chrono::microseconds(1300));
	}

	return 0;
}

// Assembly:
subq $0x1c28, %rsp           # imm = 0x1C28
movl $0x0, 0x1c24(%rsp)
movl %edi, 0x1c20(%rsp)
movq %rsi, 0x1c18(%rsp)
cmpl $0x2, 0x1c20(%rsp)
jge 0x46fd
movq 0x9906(%rip), %rdi      # 0xdfd8
leaq 0x5caf(%rip), %rsi      # 0xa388
callq 0x22a0
movq %rax, %rdi
movq 0x98e0(%rip), %rsi      # 0xdfc8
callq 0x22e0
movl $0x1, 0x1c24(%rsp)
jmp 0x5260
leaq 0x3c0(%rsp), %rdi
callq 0x2600
movq 0x1c18(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x98(%rsp)
leaq 0x39f(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x2420
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0x3a0(%rsp), %rdi
callq 0x2380
jmp 0x4752
leaq 0x39f(%rsp), %rdi
callq 0x22f0
leaq 0x5c60(%rip), %rsi      # 0xa3c6
leaq 0x3a0(%rsp), %rdi
callq 0x5610
movb %al, 0x97(%rsp)
jmp 0x477c
movb 0x97(%rsp), %al
testb $0x1, %al
jne 0x478c
jmp 0x495e
cmpl $0x3, 0x1c20(%rsp)
jge 0x4827
movq 0x9837(%rip), %rdi      # 0xdfd8
leaq 0x5be0(%rip), %rsi      # 0xa388
callq 0x22a0
movq %rax, 0x88(%rsp)
jmp 0x47b7
movq 0x88(%rsp), %rdi
movq 0x9802(%rip), %rsi      # 0xdfc8
callq 0x22e0
jmp 0x47cd
movl $0x1, 0x1c24(%rsp)
movl $0x1, 0x388(%rsp)
jmp 0x5242
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x39f(%rsp), %rdi
callq 0x22f0
jmp 0x526f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
jmp 0x5251
movq 0x1c18(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x78(%rsp)
leaq 0x367(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x2420
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
leaq 0x368(%rsp), %rdi
callq 0x2380
jmp 0x4869
leaq 0x3c0(%rsp), %rdi
leaq 0x368(%rsp), %rsi
callq 0x27c0
jmp 0x4880
leaq 0x368(%rsp), %rdi
callq 0x21e0
leaq 0x367(%rsp), %rdi
callq 0x22f0
leaq 0x340(%rsp), %rdi
leaq 0x3c0(%rsp), %rsi
callq 0x3650
jmp 0x48b1
movq 0x9720(%rip), %rdi      # 0xdfd8
leaq 0x340(%rsp), %rsi
callq 0x2260
jmp 0x48c7
leaq 0x340(%rsp), %rdi
callq 0x21e0
movl $0x0, 0x1c24(%rsp)
movl $0x1, 0x388(%rsp)
jmp 0x5242
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
jmp 0x4926
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x368(%rsp), %rdi
callq 0x21e0
leaq 0x367(%rsp), %rdi
callq 0x22f0
jmp 0x5251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x340(%rsp), %rdi
callq 0x21e0
jmp 0x5251
leaq 0x320(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x2170
jmp 0x4975
leaq 0x3c0(%rsp), %rdi
leaq 0x320(%rsp), %rsi
callq 0x27c0
movb %al, 0x77(%rsp)
jmp 0x4990
movb 0x77(%rsp), %al
xorb $-0x1, %al
movb %al, 0x76(%rsp)
leaq 0x320(%rsp), %rdi
callq 0x21e0
movb 0x76(%rsp), %al
testb $0x1, %al
jne 0x49b1
jmp 0x49e1
movl $0x1, %edi
callq 0x2340
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x320(%rsp), %rdi
callq 0x21e0
jmp 0x5251
jmp 0x49e3
leaq 0x59e5(%rip), %rdi      # 0xa3cf
xorl %eax, %eax
callq 0x2060
jmp 0x49f3
leaq 0x2e0(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0x2170
jmp 0x4a0a
leaq 0x300(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x5280
jmp 0x4a21
leaq 0x2e0(%rsp), %rdi
callq 0x21e0
leaq 0x59b8(%rip), %rsi      # 0xa3ed
leaq 0x2c0(%rsp), %rdi
leaq 0x300(%rsp), %rdx
callq 0x5640
jmp 0x4a4c
leaq 0x2c0(%rsp), %rdi
callq 0x2160
movq %rax, %rdi
movl $0x1fff0000, %edx       # imm = 0x1FFF0000
movl $0x400, %ecx            # imm = 0x400
movl $0x200, %r8d            # imm = 0x200
movl $0x20, %r9d
movl %edx, %esi
callq 0x2070
movq %rax, 0x68(%rsp)
jmp 0x4a80
movq 0x68(%rsp), %rax
movq %rax, 0x2b8(%rsp)
movq 0x2b8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x2040
movq %rax, 0x60(%rsp)
jmp 0x4aa8
movq 0x60(%rsp), %rax
movq %rax, 0x2b0(%rsp)
movq 0x2b0(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movl $0x200, %edx            # imm = 0x200
callq 0x2120
jmp 0x4ace
movq 0x2b0(%rsp), %rdi
movl $0x16362004, %esi       # imm = 0x16362004
movl $0x1, %edx
movl $0x40, %ecx
movl $0x20, %r8d
callq 0x2430
movq %rax, 0x58(%rsp)
jmp 0x4af7
movq 0x58(%rsp), %rax
movq %rax, 0x2a8(%rsp)
leaq 0x55f1(%rip), %rsi      # 0xa0fc
leaq 0x1a0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
movl $0xc0, %edx
callq 0x2240
movq 0x48(%rsp), %rax
movq %rax, 0x260(%rsp)
movq $0x18, 0x268(%rsp)
leaq 0x19d(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x5770
movq 0x50(%rsp), %rcx
movq 0x260(%rsp), %rsi
movq 0x268(%rsp), %rdx
movq %rsp, %rax
movq %rcx, (%rax)
xorl %eax, %eax
movl %eax, %ecx
leaq 0x270(%rsp), %rdi
leaq 0x19f(%rsp), %r8
leaq 0x19e(%rsp), %r9
callq 0x5780
jmp 0x4b8b
leaq 0x19d(%rsp), %rdi
callq 0x57f0
movl $0xac44, 0x178(%rsp) # imm = 0xAC44
movw $0x8010, 0x17c(%rsp)    # imm = 0x8010
movb $0x2, 0x17e(%rsp)
movslq 0x178(%rsp), %rax
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x23, %rax
addl %ecx, %eax
movw %ax, 0x180(%rsp)
leaq 0x157(%rsp), %rdi
callq 0x5370
movq %rax, 0x188(%rsp)
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x23d0
jmp 0x4c05
xorl %edi, %edi
callq 0x2220
jmp 0x4c0e
movl $0x0, 0x150(%rsp)
movl $0x0, 0x14c(%rsp)
movb $0x1, 0x14b(%rsp)
movb $0x0, 0x14a(%rsp)
callq 0x2080
movq %rax, 0x140(%rsp)
testb $0x1, 0x14b(%rsp)
je 0x51e7
cmpb $0x0, 0x1412(%rsp)
jne 0x4d23
testb $0x1, 0x14a(%rsp)
jne 0x4d23
leaq 0x3c0(%rsp), %rdi
callq 0x2930
jmp 0x4c7a
jmp 0x4d23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x2e0(%rsp), %rdi
callq 0x21e0
jmp 0x5251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
jmp 0x5233
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
jmp 0x5226
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x19d(%rsp), %rdi
callq 0x57f0
jmp 0x5226
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x390(%rsp)
movl %eax, 0x38c(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x5af0
jmp 0x5226
testb $0x1, 0x14a(%rsp)
je 0x4d52
cmpl $0x0, 0x150(%rsp)
jne 0x4d52
leaq 0x56c1(%rip), %rdi      # 0xa3ff
xorl %eax, %eax
callq 0x2060
jmp 0x4d47
movl $0x1, 0x150(%rsp)
jmp 0x4d54
leaq 0x108(%rsp), %rdi
callq 0x21d0
movl %eax, 0x44(%rsp)
jmp 0x4d67
movl 0x44(%rsp), %eax
cmpl $0x0, %eax
je 0x4efe
movl 0x108(%rsp), %eax
movl %eax, 0x40(%rsp)
subl $0x100, %eax            # imm = 0x100
je 0x4d9b
jmp 0x4d88
movl 0x40(%rsp), %eax
addl $0xfffffd00, %eax       # imm = 0xFFFFFD00
subl $0x2, %eax
jb 0x4da8
jmp 0x4ef9
movb $0x0, 0x14b(%rsp)
jmp 0x4ef9
leaq 0x11c(%rsp), %rsi
leaq 0x270(%rsp), %rdi
callq 0x5800
movq %rax, 0x38(%rsp)
jmp 0x4dc4
movq 0x38(%rsp), %rax
movq %rax, 0x100(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x5850
movq %rax, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x5830
testb $0x1, %al
jne 0x4e01
jmp 0x4e06
jmp 0x4ef9
leaq 0x100(%rsp), %rdi
callq 0x5880
cmpl $-0x1, 0x4(%rax)
jne 0x4e26
movb $0x0, 0x14b(%rsp)
jmp 0x4ef9
leaq 0x100(%rsp), %rdi
callq 0x5880
cmpl $-0x2, 0x4(%rax)
jne 0x4e81
cmpl $0x300, 0x108(%rsp) # imm = 0x300
jne 0x4e81
movb 0x14a(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x14a(%rsp)
movl $0x0, 0x150(%rsp)
testb $0x1, 0x14a(%rsp)
jne 0x4e7f
leaq 0x5594(%rip), %rdi      # 0xa408
xorl %eax, %eax
callq 0x2060
jmp 0x4e7d
jmp 0x4e7f
jmp 0x4ef9
cmpl $0x300, 0x108(%rsp) # imm = 0x300
sete %al
movb %al, 0x37(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5880
movb 0x37(%rsp), %cl
movslq 0x4(%rax), %rax
andb $0x1, %cl
movb %cl, 0x1402(%rsp,%rax)
cmpl $0x300, 0x108(%rsp) # imm = 0x300
jne 0x4ef7
cmpb $0x0, 0x1412(%rsp)
je 0x4ef7
leaq 0x100(%rsp), %rdi
callq 0x5880
movl 0x4(%rax), %eax
movb %al, %cl
movzbl 0x1412(%rsp), %eax
andl $0x7f, %eax
cltq
movb %cl, 0x13f2(%rsp,%rax)
movb $0x0, 0x1412(%rsp)
jmp 0x4ef9
jmp 0x4d54
callq 0x2080
movq %rax, 0xf0(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x58a0
movq %rax, 0x28(%rsp)
jmp 0x4f27
movq 0x28(%rsp), %rax
movq %rax, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x58f0
jmp 0x4f4b
leaq 0xe8(%rsp), %rdi
callq 0x5930
movsd %xmm0, 0x20(%rsp)
jmp 0x4f60
movsd 0x20(%rsp), %xmm0
movsd 0x5252(%rip), %xmm1     # 0xa1c0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
subl 0x14c(%rsp), %eax
movl %eax, 0xdc(%rsp)
cmpl $0x0, 0xdc(%rsp)
jle 0x51a5
testb $0x1, 0x14a(%rsp)
jne 0x51a5
movl 0xdc(%rsp), %ecx
movl 0x14c(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x14c(%rsp)
movzbl 0x13f1(%rsp), %eax
movl %eax, 0xd4(%rsp)
leaq 0xdc(%rsp), %rdi
leaq 0xd4(%rsp), %rsi
callq 0x5940
movq %rax, 0x18(%rsp)
jmp 0x4fe2
movq 0x18(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xd8(%rsp)
movl 0xd8(%rsp), %ecx
movzbl 0x13f1(%rsp), %eax
subl %ecx, %eax
movb %al, 0x13f1(%rsp)
movzbl 0x13f0(%rsp), %eax
movl %eax, 0xcc(%rsp)
leaq 0xdc(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x5940
movq %rax, 0x10(%rsp)
jmp 0x5033
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xd0(%rsp)
movl 0xd0(%rsp), %ecx
movl 0x13f0(%rsp), %eax
subl %ecx, %eax
movb %al, 0x13f0(%rsp)
callq 0x20b0
jmp 0x505f
movl 0x158(%rsp), %ecx
movl 0xd8(%rsp), %eax
imull %eax, %ecx
movslq %ecx, %rax
imulq $-0x77777777, %rax, %rax # imm = 0x88888889
shrq $0x20, %rax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
movl %eax, 0xc8(%rsp)
movb $0x1, 0xc7(%rsp)
leaq 0xc5b0(%rip), %rdi      # 0x11650
leaq 0xc8(%rsp), %rsi
leaq 0xc7(%rsp), %rdx
callq 0x5980
jmp 0x50b7
movl 0x158(%rsp), %ecx
movl 0xdc(%rsp), %eax
movl 0xd8(%rsp), %edx
subl %edx, %eax
imull %eax, %ecx
movslq %ecx, %rax
imulq $-0x77777777, %rax, %rax # imm = 0x88888889
shrq $0x20, %rax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
movl %eax, 0xc0(%rsp)
movb $0x0, 0xbf(%rsp)
leaq 0xc54f(%rip), %rdi      # 0x11650
leaq 0xc0(%rsp), %rsi
leaq 0xbf(%rsp), %rdx
callq 0x5980
jmp 0x5118
callq 0x20e0
jmp 0x511f
testb $0x1, 0x1c13(%rsp)
je 0x51a3
leaq 0x1413(%rsp), %rsi
leaq 0xa518(%rip), %rdi      # 0xf650
movq %rdi, 0x8(%rsp)
callq 0x4640
movq 0x8(%rsp), %rdx
movq 0x2a8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x100, %ecx            # imm = 0x100
callq 0x2210
jmp 0x515f
movq 0x2b0(%rsp), %rdi
callq 0x2270
jmp 0x516e
movq 0x2b0(%rsp), %rdi
movq 0x2a8(%rsp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x2310
jmp 0x518c
movq 0x2b0(%rsp), %rdi
callq 0x20a0
jmp 0x519b
movb $0x0, 0x1c13(%rsp)
jmp 0x51a5
testb $0x1, 0x14a(%rsp)
jne 0x51e2
movl $0x514, 0xac(%rsp) # imm = 0x514
leaq 0xb0(%rsp), %rdi
leaq 0xac(%rsp), %rsi
callq 0x5ad0
jmp 0x51d1
leaq 0xb0(%rsp), %rdi
callq 0x5a00
jmp 0x51e0
jmp 0x51e2
jmp 0x4c41
movl $0x0, 0x1c24(%rsp)
movl $0x1, 0x388(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x5af0
leaq 0x2c0(%rsp), %rdi
callq 0x21e0
leaq 0x300(%rsp), %rdi
callq 0x21e0
jmp 0x5242
leaq 0x2c0(%rsp), %rdi
callq 0x21e0
leaq 0x300(%rsp), %rdi
callq 0x21e0
jmp 0x5251
leaq 0x3a0(%rsp), %rdi
callq 0x21e0
jmp 0x5260
leaq 0x3a0(%rsp), %rdi
callq 0x21e0
jmp 0x526f
movl 0x1c24(%rsp), %eax
addq $0x1c28, %rsp           # imm = 0x1C28
retq
movq 0x390(%rsp), %rdi
callq 0x2410
nopl (%rax)