#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*/ str;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ warnx(char *, char *);
bool prompt_for_yes(bool verbose) {
  char str[20];
  fflush(stdout);
  if (fgets(str, sizeof(str), stdin) == NULL)
    return false;
  if (str[strlen(str) - 1] == '\n')
    str[strlen(str) - 1] = '\0';
  do {
    if (verbose)
      warnx("Prompt reply: '%s'", str);
  } while (0);
  if (strcasecmp(str, "y") == 0 || strcasecmp(str, "yes") == 0)
    return true;
  return false;
}


x86 assembly (clang, -O0):
<prompt_for_yes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    -0x20(%rbp),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
mov    $0x14,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1196 <prompt_for_yes+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1230 <prompt_for_yes+0xe0>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    11c5 <prompt_for_yes+0x75>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
jmp    11ca <prompt_for_yes+0x7a>
cmpl   $0x0,-0x8(%rbp)
je     11e4 <prompt_for_yes+0x94>
lea    -0x20(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1050 <warnx@plt>
jmp    11e9 <prompt_for_yes+0x99>
lea    -0x20(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
je     121d <prompt_for_yes+0xcd>
lea    -0x20(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1229 <prompt_for_yes+0xd9>
movl   $0x1,-0x4(%rbp)
jmp    1230 <prompt_for_yes+0xe0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_for_yes>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11e7 <prompt_for_yes+0x97>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11a4 <prompt_for_yes+0x54>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
test   %ebp,%ebp
je     11b7 <prompt_for_yes+0x67>
lea    0xe51(%rip),%rdi
mov    %rsp,%rsi
call   1050 <warnx@plt>
lea    0xe55(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11eb <prompt_for_yes+0x9b>
lea    0xe43(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcasecmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    11f0 <prompt_for_yes+0xa0>
xor    %eax,%eax
jmp    11f0 <prompt_for_yes+0xa0>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [19 x i8] c"Prompt reply: '%s'\00"
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [4 x i8] c"yes\00"
define i32 @prompt_for_yes(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* @stdout
%6 = call i32 @fflush(i32 %5)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %7, i32 20, i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %45
12: ; preds = %1
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %27
21: ; preds = %12
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %25
store i8 0, i8* %26
br label %27
27: ; preds = %21, %12
br label %28
28: ; preds = %27
%29 = load i32, i32* %3
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%33 = call i32 @warnx(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%37 = call i64 @strcasecmp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%41 = call i64 @strcasecmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39, %35
store i32 1, i32* %2
br label %45
44: ; preds = %39
store i32 0, i32* %2
br label %45
45: ; preds = %44, %43, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@.str = [19 x i8] c"Prompt reply: '%s'\00"
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [4 x i8] c"yes\00"
define i32 @prompt_for_yes(i32 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %3, i32 20, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %32, label %9
9: ; preds = %1
%10 = call i32 @strlen(i8* %3)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %21
16: ; preds = %9
%17 = call i32 @strlen(i8* %3)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %9, %16
%22 = icmp eq i32 %0, 0
br i1 %22, label %25, label %23
23: ; preds = %21
%24 = call i32 @warnx(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %25
25: ; preds = %23, %21
%26 = call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = call i64 @strcasecmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %28, %25, %1
%33 = phi i32 [ 0, %1 ], [ 1, %25 ], [ %31, %28 ]
ret i32 %33
}