// File: /workspace/github_c_makefile_star2_O1/wierton[P]socket-based-naive-game/client.c
// Function: switch_selected_button_respond_to_key
int switch_selected_button_respond_to_key(int st, int ed) {
	int sel = st - 1;
	int old_sel = sel;

	if(st >= ed) return st;

	echo_off();
	disable_buffer();
	wlog("enter select button, [%d, %d)\n", st, ed);
	while(1) {
		int ch = fgetc(stdin);
		wlog("capture key '%c' in button ui\n", ch);
		switch(ch) {
			case 'a':
			case 'w':
				sel --;
				if(sel < st) sel = ed - 1;
				break;
			case 's':
			case 'd':
				sel ++;
				if(sel >= ed) sel = st;
				break;
			case '\t':
				wlog("sel_menu enter command mode\n");
				read_and_execute_command();
				sel = st;
				break;
		}

		if(ch == '\n') {
			if(st <= sel && sel < ed) {
				break;
			}else{
				sel = st;
			}
		}

		if(st <= old_sel && old_sel < ed) {
			draw_button(old_sel);
		}

		if(st <= sel && sel < ed)
			draw_selected_button(sel);
		old_sel = sel;
	}

	echo_on();
	wlogi("return sel: %d\n", sel);
	return sel;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
cmpl %esi, %edi
jge 0x3f2b
movl %esi, %r14d
leal -0x1(%rbx), %r15d
leaq -0x3e(%rbp), %r12
movq %r12, %rdi
callq 0x2dfb
andb $-0x79, 0x6(%r12)
movq %r12, %rdi
callq 0x2e1c
movq %r12, %rdi
callq 0x2dfb
andb $-0x3, 0x6(%r12)
movb 0x649b(%rip), %al       # 0xa267
movb %al, 0xf(%r12)
movq %r12, %rdi
callq 0x2e1c
movq 0x6380(%rip), %rsi      # 0xa160
leaq 0x2a56(%rip), %rdi      # 0x683d
movl $0x338, %edx            # imm = 0x338
movl %ebx, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x27b3
movl %r15d, %r13d
movl %r14d, -0x2c(%rbp)
movq 0x61ca(%rip), %rax      # 0x9fd0
movq (%rax), %rdi
callq 0x20e0
movl %eax, %r12d
movq 0x6348(%rip), %rsi      # 0xa160
leaq 0x2a44(%rip), %rdi      # 0x6863
movl $0x33b, %edx            # imm = 0x33B
movl %eax, %ecx
xorl %eax, %eax
callq 0x27b3
cmpl $0x63, %r12d
jle 0x3e47
cmpl $0x64, %r12d
je 0x3e5f
cmpl $0x73, %r12d
je 0x3e5f
cmpl $0x77, %r12d
je 0x3e53
jmp 0x3e8d
cmpl $0x9, %r12d
je 0x3e6b
cmpl $0x61, %r12d
jne 0x3e8d
cmpl %ebx, %r15d
cmovlel %r14d, %r15d
decl %r15d
jmp 0x3e8d
incl %r15d
cmpl %r14d, %r15d
cmovgel %ebx, %r15d
jmp 0x3e8d
movq 0x62ee(%rip), %rsi      # 0xa160
leaq 0x2a10(%rip), %rdi      # 0x6889
movl $0x348, %edx            # imm = 0x348
xorl %eax, %eax
callq 0x27b3
callq 0x35ae
movl %ebx, %r15d
cmpl $0xa, %r12d
jne 0x3eab
cmpl %ebx, %r15d
setge %al
cmpl %r14d, %r15d
setl %cl
movl %ebx, %r12d
testb %cl, %al
je 0x3eae
xorl %r14d, %r14d
jmp 0x3ee7
movl %r15d, %r12d
cmpl %ebx, %r13d
setl %al
cmpl %r14d, %r13d
setge %cl
orb %al, %cl
jne 0x3ec6
movl %r13d, %edi
callq 0x36b7
cmpl %ebx, %r12d
setl %al
cmpl %r14d, %r12d
setge %cl
movb $0x1, %r14b
orb %al, %cl
jne 0x3ee1
movl %r12d, %edi
callq 0x37f3
movl %r12d, %r15d
movl %r12d, %r13d
testb %r14b, %r14b
movl -0x2c(%rbp), %r14d
jne 0x3dff
leaq -0x3e(%rbp), %rbx
movq %rbx, %rdi
callq 0x2dfb
orb $0x78, 0x6(%rbx)
movq %rbx, %rdi
callq 0x2e1c
movq 0x624d(%rip), %rsi      # 0xa160
leaq 0x2993(%rip), %rdi      # 0x68ad
movl $0x360, %edx            # imm = 0x360
movl %r15d, %ecx
xorl %eax, %eax
callq 0x27b3
jmp 0x3f2e
movl %ebx, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq