#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int yes(const char *s) {
  char b[20];
  for (;;) {
    printf("%s? ", s);
    if (fgets(b, 20, stdin) == NULL)
      exit(0);
    if (b[0] == 'y')
      return (1);
    if (b[0] == 'n')
      return (0);
    printf("Answer `yes' or `no'.\n");
  }
}


x86 assembly (clang, -O0):
<yes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1176 <yes+0x46>
xor    %edi,%edi
call   1050 <exit@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x79,%eax
jne    118f <yes+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    11bb <yes+0x8b>
movsbl -0x30(%rbp),%eax
cmp    $0x6e,%eax
jne    11a8 <yes+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11bb <yes+0x8b>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113c <yes+0xc>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yes>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e80(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
mov    $0x14,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c7 <yes+0x87>
lea    0xe80(%rip),%r14
lea    0xe74(%rip),%r15
mov    %rsp,%r12
nop
movzbl (%rsp),%eax
cmp    $0x6e,%al
je     11ce <yes+0x8e>
cmp    $0x79,%al
je     11d2 <yes+0x92>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    $0x14,%esi
call   1050 <fgets@plt>
test   %rax,%rax
jne    1190 <yes+0x50>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
jmp    11d7 <yes+0x97>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s? \00"
@stdin = global i32 0
@.str.1 = [23 x i8] c"Answer `yes' or `no'.\0A\00"
define i32 @yes(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [20 x i8]
store i8* %0, i8** %3
br label %5
5: ; preds = %26, %1
%6 = load i8*, i8** %3
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 20, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %5
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 121
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 1, i32* %2
br label %28
20: ; preds = %14
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 110
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 0, i32* %2
br label %28
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %5
28: ; preds = %25, %19
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s? \00"
@stdin = global i32 0
@str = [22 x i8] c"Answer `yes' or `no'.\00"
define i32 @yes(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %3, i32 20, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %12, %1
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %1, %12
%11 = load i8, i8* %3
switch i8 %11, label %12 [
i8 121, label %18
i8 110, label %19
]
12: ; preds = %10
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%15 = load i32, i32* @stdin
%16 = call i32* @fgets(i8* %3, i32 20, i32 %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %8, label %10
18: ; preds = %10
br label %19
19: ; preds = %10, %18
%20 = phi i32 [ 1, %18 ], [ 0, %10 ]
ret i32 %20
}