#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*/ clear_stdin();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int ask_exit(void) {
  int flag;
  printf("\nWhat do you want to do?\n"
         "  1: pick another model\n"
         "  2: exit\n");
  do {
    printf("\x1b["
           "1"
           "m"
           "Choose an action: "
           "\x1b[0m");
    scanf("%d", &flag);
    clear_stdin();
    if (flag < 1 || flag > 2)
      printf("\x1b["
             "1"
             ";3"
             "1"
             "m"
             "Invalid choice. Please retry.\n"
             "\x1b[0m");
  } while (flag < 1 || flag > 2);
  return flag - 2;
}


x86 assembly (clang, -O0):
<ask_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1040 <printf@plt>
lea    0xef1(%rip),%rdi
call   1040 <printf@plt>
lea    0xf00(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x0,%al
call   1030 <clear_stdin@plt>
cmpl   $0x1,-0x4(%rbp)
jl     117b <ask_exit+0x4b>
cmpl   $0x2,-0x4(%rbp)
jle    1187 <ask_exit+0x57>
lea    0xed8(%rip),%rdi
call   1040 <printf@plt>
jmp    118c <ask_exit+0x5c>
mov    $0x1,%al
cmpl   $0x1,-0x4(%rbp)
mov    %al,-0x5(%rbp)
jl     11a5 <ask_exit+0x75>
cmpl   $0x2,-0x4(%rbp)
setg   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    1144 <ask_exit+0x14>
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_exit>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xef9(%rip),%rdi
call   1040 <puts@plt>
lea    0xea5(%rip),%r14
lea    0xeb9(%rip),%r15
lea    0x4(%rsp),%rbx
lea    0xeb0(%rip),%r12
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
call   1030 <clear_stdin@plt>
mov    0x4(%rsp),%eax
lea    -0x3(%rax),%ecx
cmp    $0xfffffffd,%ecx
ja     11aa <ask_exit+0x6a>
mov    %r12,%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%eax
lea    -0x3(%rax),%ecx
cmp    $0xfffffffe,%ecx
jb     1170 <ask_exit+0x30>
add    $0xfffffffe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [60 x i8] c"\0AWhat do you want to do?\0A 1: pick another model\0A 2: exit\0A\00"
@.str.1 = [27 x i8] c"\1B[1mChoose an action: \1B[0m\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [42 x i8] c"\1B[1;31mInvalid choice. Please retry.\0A\1B[0m\00"
define i32 @ask_exit() {
%1 = alloca i32
%2 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %21, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = call i32 (...) @clear_stdin()
%7 = load i32, i32* %1
%8 = icmp slt i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %9, %3
%13 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
br label %15
15: ; preds = %14
%16 = load i32, i32* %1
%17 = icmp slt i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %1
%20 = icmp sgt i32 %19, 2
br label %21
21: ; preds = %18, %15
%22 = phi i1 [ true, %15 ], [ %20, %18 ]
br i1 %22, label %3, label %23
23: ; preds = %21
%24 = load i32, i32* %1
%25 = sub nsw i32 %24, 2
ret i32 %25
}

LLVM IR (-O2):
@.str.1 = [27 x i8] c"\1B[1mChoose an action: \1B[0m\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [42 x i8] c"\1B[1;31mInvalid choice. Please retry.\0A\1B[0m\00"
@str = [59 x i8] c"\0AWhat do you want to do?\0A 1: pick another model\0A 2: exit\00"
define i32 @ask_exit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %11, %0
%5 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 (...) @clear_stdin()
%8 = load i32, i32* %1
%9 = add i32 %8, -3
%10 = icmp ult i32 %9, -2
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = add i32 %13, -3
%15 = icmp ult i32 %14, -2
br i1 %15, label %4, label %16
16: ; preds = %4, %11
%17 = phi i32 [ %13, %11 ], [ %8, %4 ]
%18 = add nsw i32 %17, -2
ret i32 %18
}