#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ get_ok_char();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int tolower(int /*<<< orphan*/);
int get_response(char *question, int maxtries) {
  int input;
  printf("%s (y/n)?", question);
  fflush(stdout);
  while (1) {
    sleep(5);
    input = tolower(get_ok_char());
    if (input == 'y')
      return 0;
    if (input == 'n')
      return 1;
    if (maxtries-- == 0)
      return 2;
    putchar('\a');
  }
}


x86 assembly (clang, -O0):
<get_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    $0x0,%al
call   1070 <get_ok_char@plt>
mov    %eax,%edi
call   1050 <tolower@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x79,-0x18(%rbp)
jne    11be <get_response+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1203 <get_response+0xa3>
cmpl   $0x6e,-0x18(%rbp)
jne    11d4 <get_response+0x74>
movl   $0x1,-0x4(%rbp)
jmp    1203 <get_response+0xa3>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jne    11f4 <get_response+0x94>
movl   $0x2,-0x4(%rbp)
jmp    1203 <get_response+0xa3>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    118d <get_response+0x2d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_response>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x5,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
call   1070 <get_ok_char@plt>
mov    %eax,%edi
call   1050 <tolower@plt>
cmp    $0x6e,%eax
je     11c3 <get_response+0x63>
cmp    $0x79,%eax
je     11cf <get_response+0x6f>
sub    $0x1,%ebx
jb     11ca <get_response+0x6a>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    1190 <get_response+0x30>
mov    $0x1,%ebp
jmp    11cf <get_response+0x6f>
mov    $0x2,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%s (y/n)?\00"
@stdout = global i32 0
define i32 @get_response(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
br label %11
11: ; preds = %2, %27
%12 = call i32 @sleep(i32 5)
%13 = call i32 (...) @get_ok_char()
%14 = call i32 @tolower(i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 121
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 0, i32* %3
br label %29
18: ; preds = %11
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 110
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 1, i32* %3
br label %29
22: ; preds = %18
%23 = load i32, i32* %5
%24 = add nsw i32 %23, -1
store i32 %24, i32* %5
%25 = icmp eq i32 %23, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 2, i32* %3
br label %29
27: ; preds = %22
%28 = call i32 @putchar(i8 signext 7)
br label %11
29: ; preds = %26, %21, %17
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s (y/n)?\00"
@stdout = global i32 0
define i32 @get_response(i8* %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
br label %6
6: ; preds = %13, %2
%7 = phi i32 [ %1, %2 ], [ %14, %13 ]
%8 = tail call i32 @sleep(i32 5)
%9 = tail call i32 (...) @get_ok_char()
%10 = tail call i32 @tolower(i32 %9)
switch i32 %10, label %11 [
i32 121, label %16
i32 110, label %18
]
11: ; preds = %6
%12 = icmp eq i32 %7, 0
br i1 %12, label %16, label %13
13: ; preds = %11
%14 = add nsw i32 %7, -1
%15 = tail call i32 @putchar(i8 signext 7)
br label %6
16: ; preds = %6, %11
%17 = phi i32 [ 2, %11 ], [ 0, %6 ]
br label %18
18: ; preds = %6, %16
%19 = phi i32 [ %17, %16 ], [ 1, %6 ]
ret i32 %19
}