#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stdin;
char tolower(char);
int ask_question_yn(const char *query) {
  char buffer[256];
  assert(query != 0);
  do {
    printf("%s", query);
    if (fgets(buffer, sizeof(buffer), stdin) == 0) {
      return 0;
    }
    buffer[0] = tolower(buffer[0]);
    if (buffer[0] == '\n') {
      return 0;
    }
  } while ((buffer[0] != 'y' && buffer[0] != 'n') ||
           (buffer[1] != '\n' && buffer[1] != '\0'));
  return buffer[0] == 'y';
}


x86 assembly (clang, -O0):
<ask_question_yn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a1 <ask_question_yn+0x61>
movl   $0x0,-0x4(%rbp)
jmp    1256 <ask_question_yn+0x116>
movsbl -0x110(%rbp),%edi
call   1060 <tolower@plt>
mov    %al,-0x110(%rbp)
movsbl -0x110(%rbp),%eax
cmp    $0xa,%eax
jne    11cf <ask_question_yn+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    1256 <ask_question_yn+0x116>
jmp    11d4 <ask_question_yn+0x94>
movsbl -0x110(%rbp),%eax
cmp    $0x79,%eax
je     11fc <ask_question_yn+0xbc>
movsbl -0x110(%rbp),%ecx
mov    $0x1,%al
cmp    $0x6e,%ecx
mov    %al,-0x111(%rbp)
jne    1233 <ask_question_yn+0xf3>
movsbl -0x10f(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x112(%rbp)
je     1227 <ask_question_yn+0xe7>
movsbl -0x10f(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x112(%rbp)
mov    -0x112(%rbp),%al
mov    %al,-0x111(%rbp)
mov    -0x111(%rbp),%al
test   $0x1,%al
jne    1161 <ask_question_yn+0x21>
movsbl -0x110(%rbp),%eax
cmp    $0x79,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_question_yn>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    0x2e72(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11f0 <ask_question_yn+0xb0>
lea    0xe6a(%rip),%r15
mov    %rsp,%rbp
jmp    11c5 <ask_question_yn+0x85>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
je     11f0 <ask_question_yn+0xb0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    (%r12),%edx
mov    %rbp,%rdi
mov    $0x100,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11f0 <ask_question_yn+0xb0>
movsbl (%rsp),%edi
call   1060 <tolower@plt>
mov    %al,(%rsp)
cmp    $0x6e,%al
je     11d9 <ask_question_yn+0x99>
cmp    $0x79,%al
jne    11a0 <ask_question_yn+0x60>
movzbl 0x1(%rsp),%ecx
test   %cl,%cl
je     11e7 <ask_question_yn+0xa7>
cmp    $0xa,%cl
jne    11a4 <ask_question_yn+0x64>
xor    %r14d,%r14d
cmp    $0x79,%al
sete   %r14b
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
define i32 @ask_question_yn(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
br label %9
9: ; preds = %50, %1
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i64 @fgets(i8* %12, i32 256, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %9
store i32 0, i32* %2
br label %58
17: ; preds = %9
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%19 = load i8, i8* %18
%20 = call signext i8 @tolower(i8 signext %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 %20, i8* %21
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 0, i32* %2
br label %58
27: ; preds = %17
br label %28
28: ; preds = %27
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 121
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 110
br i1 %37, label %50, label %38
38: ; preds = %33, %28
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 10
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 1
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br label %48
48: ; preds = %43, %38
%49 = phi i1 [ false, %38 ], [ %47, %43 ]
br label %50
50: ; preds = %48, %33
%51 = phi i1 [ true, %33 ], [ %49, %48 ]
br i1 %51, label %9, label %52
52: ; preds = %50
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 121
%57 = zext i1 %56 to i32
store i32 %57, i32* %2
br label %58
58: ; preds = %52, %26, %16
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
define i32 @ask_question_yn(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp ne i8* %0, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %3, i32 256, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 1
br label %13
13: ; preds = %11, %18
%14 = load i8, i8* %3
%15 = call signext i8 @tolower(i8 signext %14)
store i8 %15, i8* %3
switch i8 %15, label %18 [
i8 10, label %26
i8 121, label %16
i8 110, label %16
]
16: ; preds = %13, %13
%17 = load i8, i8* %12
switch i8 %17, label %18 [
i8 10, label %23
i8 0, label %23
]
18: ; preds = %16, %13
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = load i32, i32* @stdin
%21 = call i64 @fgets(i8* %3, i32 256, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %13
23: ; preds = %16, %16
%24 = icmp eq i8 %15, 121
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %18, %13, %1, %23
%27 = phi i32 [ %25, %23 ], [ 0, %1 ], [ 0, %13 ], [ 0, %18 ]
ret i32 %27
}