#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int get_select_option() {
  char option[128];
  while ((fgets(option, 128, stdin)) != NULL) {
    if (strlen(option) > 2)
      printf("too much worlds...\ntry again:");
    else if (option[0] >= '0' && option[0] <= '9')
      return option[0] - '0';
    else
      printf("no such option!\ntry agian:");
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_select_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    -0x90(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11cd <get_select_option+0x9d>
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jle    1185 <get_select_option+0x55>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
jmp    11c8 <get_select_option+0x98>
movsbl -0x90(%rbp),%eax
cmp    $0x30,%eax
jl     11b7 <get_select_option+0x87>
movsbl -0x90(%rbp),%eax
cmp    $0x39,%eax
jg     11b7 <get_select_option+0x87>
movsbl -0x90(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <get_select_option+0xa4>
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
jmp    11c8 <get_select_option+0x98>
jmp    113b <get_select_option+0xb>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_select_option>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2ea2(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11bf <get_select_option+0x8f>
mov    %rsp,%rbx
lea    0xe95(%rip),%rbp
lea    0xeac(%rip),%r12
jmp    119a <get_select_option+0x6a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1040 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11bf <get_select_option+0x8f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
cmp    $0x2,%eax
jg     1180 <get_select_option+0x50>
movzbl (%rsp),%eax
lea    -0x30(%rax),%ecx
mov    %r12,%rdi
cmp    $0x9,%cl
ja     1180 <get_select_option+0x50>
add    $0xffffffd0,%eax
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [30 x i8] c"too much worlds...\0Atry again:\00"
@.str.1 = [27 x i8] c"no such option!\0Atry agian:\00"
define i32 @get_select_option() {
%1 = alloca i32
%2 = alloca [128 x i8]
br label %3
3: ; preds = %32, %0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 128, i32 %5)
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %33
8: ; preds = %3
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %32
14: ; preds = %8
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp sge i32 %17, 48
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp sle i32 %22, 57
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 48
store i32 %28, i32* %1
br label %34
29: ; preds = %19, %14
%30 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29
br label %32
32: ; preds = %31, %12
br label %3
33: ; preds = %3
store i32 -1, i32* %1
br label %34
34: ; preds = %33, %24
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [30 x i8] c"too much worlds...\0Atry again:\00"
@.str.1 = [27 x i8] c"no such option!\0Atry agian:\00"
define i32 @get_select_option() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32* @fgets(i8* %2, i32 128, i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %22, label %6
6: ; preds = %0, %16
%7 = call i32 @strlen(i8* %2)
%8 = icmp sgt i32 %7, 2
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = load i8, i8* %2
%11 = add i8 %10, -48
%12 = icmp ult i8 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = zext i8 %10 to i32
%15 = add nsw i32 %14, -48
br label %22
16: ; preds = %9, %6
%17 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %9 ]
%18 = call i32 @printf(i8* dereferenceable(1) %17)
%19 = load i32, i32* @stdin
%20 = call i32* @fgets(i8* %2, i32 128, i32 %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %6
22: ; preds = %16, %0, %13
%23 = phi i32 [ %15, %13 ], [ -1, %0 ], [ -1, %16 ]
ret i32 %23
}