// File: /workspace/github_c_makefile_star2_O3/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, %r14d
cmpl %esi, %edi
jge 0x3fab
movl %esi, %r13d
leal -0x1(%r14), %ebx
leaq -0x3a(%rbp), %r15
movq %r15, %rdi
callq 0x2e01
andb $-0x79, 0x6(%r15)
movq %r15, %rdi
callq 0x2e22
movq %r15, %rdi
callq 0x2e01
andb $-0x3, 0x6(%r15)
movb 0x63d9(%rip), %al       # 0xa267
movb %al, 0xf(%r15)
movq %r15, %rdi
callq 0x2e22
movq 0x62bf(%rip), %rsi      # 0xa160
leaq 0x2992(%rip), %rdi      # 0x683a
movl $0x338, %edx            # imm = 0x338
movl %r14d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x27b9
movq 0x610f(%rip), %rax      # 0x9fd0
movq (%rax), %rdi
callq 0x20e0
movl %eax, %r12d
movq 0x628d(%rip), %rsi      # 0xa160
leaq 0x2986(%rip), %rdi      # 0x6860
movl $0x33b, %edx            # imm = 0x33B
movl %eax, %ecx
xorl %eax, %eax
callq 0x27b9
cmpl $0x63, %r12d
jg 0x3f05
cmpl $0x9, %r12d
je 0x3f36
cmpl $0xa, %r12d
je 0x3f5a
movl %ebx, %r15d
cmpl $0x61, %r12d
je 0x3f1a
jmp 0x3f6d
cmpl $0x64, %r12d
je 0x3f29
cmpl $0x73, %r12d
je 0x3f29
movl %ebx, %r15d
cmpl $0x77, %r12d
jne 0x3f6d
cmpl %r14d, %ebx
movl %r13d, %r15d
cmovgl %ebx, %r15d
decl %r15d
jmp 0x3f6d
leal 0x1(%rbx), %r15d
cmpl %r13d, %r15d
cmovgel %r14d, %r15d
jmp 0x3f6d
movq 0x6223(%rip), %rsi      # 0xa160
leaq 0x2942(%rip), %rdi      # 0x6886
movl $0x348, %edx            # imm = 0x348
xorl %eax, %eax
callq 0x27b9
callq 0x3594
movl %r14d, %r15d
jmp 0x3f6d
cmpl %r14d, %ebx
setge %al
cmpl %r13d, %ebx
setl %cl
movl %r14d, %r15d
testb %cl, %al
jne 0x3fb0
cmpl %r14d, %ebx
setl %al
cmpl %r13d, %ebx
setge %cl
orb %al, %cl
jne 0x3f84
movl %ebx, %edi
callq 0x369d
cmpl %r14d, %r15d
setl %al
cmpl %r13d, %r15d
setge %cl
orb %al, %cl
movl %r15d, %ebx
jne 0x3eba
movl %r15d, %edi
callq 0x3856
movl %r15d, %ebx
jmp 0x3eba
movl %r14d, %ebx
jmp 0x3fe5
leaq -0x3a(%rbp), %r14
movq %r14, %rdi
callq 0x2e01
orb $0x78, 0x6(%r14)
movq %r14, %rdi
callq 0x2e22
movq 0x6190(%rip), %rsi      # 0xa160
leaq 0x28d3(%rip), %rdi      # 0x68aa
movl $0x360, %edx            # imm = 0x360
movl %ebx, %ecx
xorl %eax, %eax
callq 0x27b9
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq