#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*/ printf(char *, char *);
int scanf(char *, char *);
int yes_no(char *question_str) {
  char answer;
  int rc;
  while (1) {
    printf("%s (y/n): ", question_str);
    rc = scanf("%c", &answer);
    if (rc != 1)
      return -1;
    if (answer == 'y')
      return 0;
    if (answer == 'n')
      return 1;
  }
}


x86 assembly (clang, -O0):
<yes_no>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1040 <scanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     1165 <yes_no+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <yes_no+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
jne    117e <yes_no+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    119c <yes_no+0x7c>
movsbl -0x11(%rbp),%eax
cmp    $0x6e,%eax
jne    1197 <yes_no+0x77>
movl   $0x1,-0x4(%rbp)
jmp    119c <yes_no+0x7c>
jmp    112c <yes_no+0xc>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yes_no>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xece(%rip),%r14
lea    0xed2(%rip),%r15
lea    0x7(%rsp),%r12
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    116f <yes_no+0x4f>
movzbl 0x7(%rsp),%eax
cmp    $0x79,%al
je     1176 <yes_no+0x56>
cmp    $0x6e,%al
jne    1140 <yes_no+0x20>
mov    $0x1,%eax
jmp    1178 <yes_no+0x58>
mov    $0xffffffff,%eax
jmp    1178 <yes_no+0x58>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"%s (y/n): \00"
@.str.1 = [3 x i8] c"%c\00"
define i32 @yes_no(i8* %0) {
%2 = alloca i8
br label %3
3: ; preds = %7, %1
%4 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = load i8, i8* %2
switch i8 %8, label %3 [
i8 121, label %9
i8 110, label %11
]
9: ; preds = %3, %7
%10 = phi i32 [ 0, %7 ], [ -1, %3 ]
br label %11
11: ; preds = %7, %9
%12 = phi i32 [ %10, %9 ], [ 1, %7 ]
ret i32 %12
}