#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 get_ok_char();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int get_response(char *question, int maxtries) {
  int input;
  printf("%s (y/n)? ", question);
  fflush(stdout);
  while (1) {
    sleep(2);
    switch (input = get_ok_char()) {
    case 'y':
    case 'Y':
      putchar('\n');
      return 0;
    case 'n':
    case 'N':
      putchar('\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    0xe96(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1060 <get_ok_char@plt>
mov    %eax,-0x18(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0x4e,%eax
je     11ed <get_response+0x9d>
jmp    11a4 <get_response+0x54>
mov    -0x1c(%rbp),%eax
sub    $0x59,%eax
je     11d7 <get_response+0x87>
jmp    11b5 <get_response+0x65>
mov    -0x1c(%rbp),%eax
sub    $0x6e,%eax
je     11ed <get_response+0x9d>
jmp    11c6 <get_response+0x76>
mov    -0x1c(%rbp),%eax
sub    $0x79,%eax
jne    1203 <get_response+0xb3>
jmp    11d7 <get_response+0x87>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
jmp    1232 <get_response+0xe2>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <get_response+0xe2>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jne    1223 <get_response+0xd3>
movl   $0x2,-0x4(%rbp)
jmp    1232 <get_response+0xe2>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    117d <get_response+0x2d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_response>:
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1060 <get_ok_char@plt>
cmp    $0x6d,%eax
jg     11a0 <get_response+0x50>
cmp    $0x4e,%eax
je     11bb <get_response+0x6b>
cmp    $0x59,%eax
jne    11aa <get_response+0x5a>
jmp    11c2 <get_response+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x6e,%eax
je     11bb <get_response+0x6b>
cmp    $0x79,%eax
je     11c2 <get_response+0x72>
sub    $0x1,%ebx
jb     11d0 <get_response+0x80>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    1170 <get_response+0x20>
mov    $0x1,%ebx
jmp    11c4 <get_response+0x74>
xor    %ebx,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d5 <get_response+0x85>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 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 ([11 x i8], [11 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, %23
%12 = call i32 @sleep(i32 2)
%13 = call i32 (...) @get_ok_char()
store i32 %13, i32* %6
switch i32 %13, label %18 [
i32 121, label %14
i32 89, label %14
i32 110, label %16
i32 78, label %16
]
14: ; preds = %11, %11
%15 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %3
br label %25
16: ; preds = %11, %11
%17 = call i32 @putchar(i8 signext 10)
store i32 1, i32* %3
br label %25
18: ; preds = %11
%19 = load i32, i32* %5
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
%21 = icmp eq i32 %19, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 2, i32* %3
br label %25
23: ; preds = %18
%24 = call i32 @putchar(i8 signext 7)
br label %11
25: ; preds = %22, %16, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [11 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 ([11 x i8], [11 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 = %12, %2
%7 = phi i32 [ %1, %2 ], [ %13, %12 ]
%8 = tail call i32 @sleep(i32 2)
%9 = tail call i32 (...) @get_ok_char()
switch i32 %9, label %10 [
i32 121, label %16
i32 89, label %16
i32 110, label %15
i32 78, label %15
]
10: ; preds = %6
%11 = icmp eq i32 %7, 0
br i1 %11, label %19, label %12
12: ; preds = %10
%13 = add nsw i32 %7, -1
%14 = tail call i32 @putchar(i8 signext 7)
br label %6
15: ; preds = %6, %6
br label %16
16: ; preds = %6, %6, %15
%17 = phi i32 [ 1, %15 ], [ 0, %6 ], [ 0, %6 ]
%18 = tail call i32 @putchar(i8 signext 10)
br label %19
19: ; preds = %10, %16
%20 = phi i32 [ %17, %16 ], [ 2, %10 ]
ret i32 %20
}