#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int confirmToQuit(void) {
  printf("Are you sure you want to quit? enter y for yes and n for no\n(JVG)");
  char *ans = malloc(sizeof(char) * 300);
  fgets(ans, sizeof(char) * 300, stdin);
  char *ptr = ans;
  if ((ptr = strchr(ans, '\n')) != NULL)
    *ptr = '\0';
  int ret = strcmp(ans, "y") == 0;
  if (ret == 0 && strcmp(ans, "n") != 0) {
    free(ans);
    printf("Please enter a valid answer\n");
    return confirmToQuit();
  }
  free(ans);
  return ret;
}


x86 assembly (clang, -O0):
<confirmToQuit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
mov    $0x12c,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edx
mov    $0x12c,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11d4 <confirmToQuit+0x64>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1239 <confirmToQuit+0xc9>
mov    -0x10(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1239 <confirmToQuit+0xc9>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
call   1090 <confirmToQuit@plt>
mov    %eax,-0x4(%rbp)
jmp    1248 <confirmToQuit+0xd8>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<confirmToQuit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e66(%rip),%r14
lea    0xeb9(%rip),%r13
lea    0xeb4(%rip),%r15
lea    0xeaf(%rip),%r12
nopw   0x0(%rax,%rax,1)
lea    0xe59(%rip),%rdi
call   1060 <printf@plt>
mov    $0x12c,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0x12c,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11de <confirmToQuit+0x6e>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strcmp@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1213 <confirmToQuit+0xa3>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1213 <confirmToQuit+0xa3>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
jmp    11a0 <confirmToQuit+0x30>
xor    %r14d,%r14d
test   %rbp,%rbp
sete   %r14b
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"Are you sure you want to quit? enter y for yes and n for no\0A(JVG)\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [2 x i8] c"n\00"
@.str.3 = [29 x i8] c"Please enter a valid answer\0A\00"
define i32 @confirmToQuit() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @malloc(i32 300)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 300, i32 %8)
%10 = load i8*, i8** %2
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = load i8*, i8** %3
store i8 0, i8* %15
br label %16
16: ; preds = %14, %0
%17 = load i8*, i8** %2
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8*, i8** %2
%29 = call i32 @free(i8* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @confirmToQuit()
store i32 %31, i32* %1
br label %36
32: ; preds = %23, %16
%33 = load i8*, i8** %2
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %4
store i32 %35, i32* %1
br label %36
36: ; preds = %32, %27
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@.str = [66 x i8] c"Are you sure you want to quit? enter y for yes and n for no\0A(JVG)\00"
@stdin = global i32 0
@.str.1 = [2 x i8] c"y\00"
@.str.2 = [2 x i8] c"n\00"
@str = [28 x i8] c"Please enter a valid answer\00"
define i32 @confirmToQuit() {
br label %1
1: ; preds = %15, %0
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(300) i8* @malloc(i32 300)
%4 = load i32, i32* @stdin
%5 = tail call i32 @fgets(i8* %3, i32 300, i32 %4)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8 0, i8* %6
br label %9
9: ; preds = %8, %1
%10 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @free(i8* %3)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %1
18: ; preds = %12, %9
%19 = zext i1 %11 to i32
%20 = tail call i32 @free(i8* %3)
ret i32 %19
}