#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*/ clearbuffer();
int getchar();
int /*<<< orphan*/ printf(char *);
char tolower(int);
ask_yes_no() {
  int c, opcao;
  do {
    printf("y/n:");
    c = opcao = getchar();
    if (c != '\n')
      clearbuffer();
  } while (tolower(opcao) != 'y' && tolower(opcao) != 'n');
  return (tolower(opcao) == 'y' ? 1 : 0);
}


x86 assembly (clang, -O0):
<ask_yes_no>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
je     1172 <ask_yes_no+0x32>
mov    $0x0,%al
call   1050 <clearbuffer@plt>
jmp    1177 <ask_yes_no+0x37>
mov    -0x8(%rbp),%edi
call   1060 <tolower@plt>
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0x79,%ecx
mov    %al,-0x9(%rbp)
je     11a4 <ask_yes_no+0x64>
mov    -0x8(%rbp),%edi
call   1060 <tolower@plt>
movsbl %al,%eax
cmp    $0x6e,%eax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1148 <ask_yes_no+0x8>
mov    -0x8(%rbp),%edi
call   1060 <tolower@plt>
movsbl %al,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x79,%edx
cmove  %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_yes_no>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
je     116d <ask_yes_no+0x2d>
xor    %eax,%eax
call   1050 <clearbuffer@plt>
mov    %ebp,%edi
call   1060 <tolower@plt>
cmp    $0x79,%al
je     1183 <ask_yes_no+0x43>
mov    %ebp,%edi
call   1060 <tolower@plt>
cmp    $0x6e,%al
jne    1150 <ask_yes_no+0x10>
mov    %ebp,%edi
call   1060 <tolower@plt>
xor    %ecx,%ecx
cmp    $0x79,%al
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"y/n:\00"
define i32 @ask_yes_no() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %21, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @getchar()
store i32 %5, i32* %2
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp ne i32 %6, 10
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 (...) @clearbuffer()
br label %10
10: ; preds = %8, %3
br label %11
11: ; preds = %10
%12 = load i32, i32* %2
%13 = call signext i8 @tolower(i32 %12)
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 121
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* %2
%18 = call signext i8 @tolower(i32 %17)
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 110
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ false, %11 ], [ %20, %16 ]
br i1 %22, label %3, label %23
23: ; preds = %21
%24 = load i32, i32* %2
%25 = call signext i8 @tolower(i32 %24)
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 121
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 1, i32 0
ret i32 %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"y/n:\00"
define i32 @ask_yes_no() {
br label %1
1: ; preds = %10, %0
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = icmp eq i32 %3, 10
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (...) @clearbuffer()
br label %7
7: ; preds = %1, %5
%8 = tail call signext i8 @tolower(i32 %3)
%9 = icmp eq i8 %8, 121
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call signext i8 @tolower(i32 %3)
%12 = icmp eq i8 %11, 110
br i1 %12, label %13, label %1
13: ; preds = %7, %10
%14 = tail call signext i8 @tolower(i32 %3)
%15 = icmp eq i8 %14, 121
%16 = zext i1 %15 to i32
ret i32 %16
}