#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 getchar();
scalar_t__ isspace(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
int affirm(char *prompt) {
  int reply;
  int done;
  void bail(char *msg, int status);
  if (prompt != NULL && (int)strlen(prompt) > 0) {
    printf("%s? ", prompt);
  }
  done = 0;
  while (!done) {
    reply = getchar();
    while (isspace(reply)) {
      reply = getchar();
    }
    if (reply == 'y' || reply == 'Y') {
      done = 1;
    } else if (reply == 'n' || reply == 'N') {
      done = 2;
    } else if (reply == 'q' || reply == 'Q') {
      done = 3;
    } else if (reply == 'x' || reply == 'X') {
      done = 3;
    } else {
      printf("Valid responses begin with: y Y n N q Q x X\n");
      if (prompt != NULL) {
        printf("%s? ", prompt);
      }
      while (reply != '\n') {
        reply = getchar();
      }
    }
  }
  if (done > 2) {
    bail(NULL, 0);
  } else if (done == 2) {
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<affirm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118b <affirm+0x3b>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jle    118b <affirm+0x3b>
mov    -0x10(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a8 <affirm+0x58>
jmp    12b5 <affirm+0x165>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11d3 <affirm+0x83>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
jmp    11b2 <affirm+0x62>
cmpl   $0x79,-0x14(%rbp)
je     11e7 <affirm+0x97>
cmpl   $0x59,-0x14(%rbp)
jne    11f3 <affirm+0xa3>
movl   $0x1,-0x18(%rbp)
jmp    12b0 <affirm+0x160>
cmpl   $0x6e,-0x14(%rbp)
je     1207 <affirm+0xb7>
cmpl   $0x4e,-0x14(%rbp)
jne    1213 <affirm+0xc3>
movl   $0x2,-0x18(%rbp)
jmp    12ab <affirm+0x15b>
cmpl   $0x71,-0x14(%rbp)
je     1227 <affirm+0xd7>
cmpl   $0x51,-0x14(%rbp)
jne    1233 <affirm+0xe3>
movl   $0x3,-0x18(%rbp)
jmp    12a6 <affirm+0x156>
cmpl   $0x78,-0x14(%rbp)
je     1247 <affirm+0xf7>
cmpl   $0x58,-0x14(%rbp)
jne    1253 <affirm+0x103>
movl   $0x3,-0x18(%rbp)
jmp    12a1 <affirm+0x151>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     127e <affirm+0x12e>
mov    -0x10(%rbp),%rsi
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1283 <affirm+0x133>
cmpl   $0xa,-0x14(%rbp)
je     129c <affirm+0x14c>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x14(%rbp)
jmp    1283 <affirm+0x133>
jmp    12a1 <affirm+0x151>
jmp    12a6 <affirm+0x156>
jmp    12ab <affirm+0x15b>
jmp    12b0 <affirm+0x160>
jmp    1192 <affirm+0x42>
cmpl   $0x2,-0x18(%rbp)
jle    12cf <affirm+0x17f>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1070 <bail@plt>
jmp    12ea <affirm+0x19a>
cmpl   $0x2,-0x18(%rbp)
jne    12e5 <affirm+0x195>
movl   $0x0,-0x4(%rbp)
jmp    12f1 <affirm+0x1a1>
jmp    12ea <affirm+0x19a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<affirm>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
test   %rdi,%rdi
je     118e <affirm+0x2e>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    118e <affirm+0x2e>
lea    0xe7c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe70(%rip),%r14
lea    0xe64(%rip),%r15
movabs $0x8100000081,%r13
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1060 <isspace@plt>
test   %rax,%rax
jne    11b0 <affirm+0x50>
mov    %ebx,%eax
and    $0xffffffdf,%eax
cmp    $0x4e,%eax
je     1236 <affirm+0xd6>
cmp    $0x59,%eax
je     1227 <affirm+0xc7>
lea    -0x51(%rbx),%eax
cmp    $0x27,%eax
ja     11e2 <affirm+0x82>
bt     %rax,%r13
jb     121e <affirm+0xbe>
mov    %r14,%rdi
call   1030 <puts@plt>
test   %r12,%r12
je     11fc <affirm+0x9c>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0xa,%ebx
je     11b0 <affirm+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%eax
jne    1210 <affirm+0xb0>
jmp    11b0 <affirm+0x50>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <bail@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %eax,%eax
jmp    122c <affirm+0xcc>

LLVM IR (-O0):
@.str = [5 x i8] c"%s? \00"
@.str.1 = [45 x i8] c"Valid responses begin with: y Y n N q Q x X\0A\00"
define i32 @affirm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %8, %1
store i32 0, i32* %5
br label %17
17: ; preds = %74, %16
%18 = load i32, i32* %5
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %75
21: ; preds = %17
%22 = call i32 (...) @getchar()
store i32 %22, i32* %4
br label %23
23: ; preds = %27, %21
%24 = load i32, i32* %4
%25 = call i64 @isspace(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (...) @getchar()
store i32 %28, i32* %4
br label %23
29: ; preds = %23
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 121
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 89
br i1 %34, label %35, label %36
35: ; preds = %32, %29
store i32 1, i32* %5
br label %74
36: ; preds = %32
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 110
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 78
br i1 %41, label %42, label %43
42: ; preds = %39, %36
store i32 2, i32* %5
br label %73
43: ; preds = %39
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 113
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 81
br i1 %48, label %49, label %50
49: ; preds = %46, %43
store i32 3, i32* %5
br label %72
50: ; preds = %46
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 120
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 88
br i1 %55, label %56, label %57
56: ; preds = %53, %50
store i32 3, i32* %5
br label %71
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%59 = load i8*, i8** %3
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i8*, i8** %3
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %57
br label %65
65: ; preds = %68, %64
%66 = load i32, i32* %4
%67 = icmp ne i32 %66, 10
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = call i32 (...) @getchar()
store i32 %69, i32* %4
br label %65
70: ; preds = %65
br label %71
71: ; preds = %70, %56
br label %72
72: ; preds = %71, %49
br label %73
73: ; preds = %72, %42
br label %74
74: ; preds = %73, %35
br label %17
75: ; preds = %17
%76 = load i32, i32* %5
%77 = icmp sgt i32 %76, 2
br i1 %77, label %78, label %79
78: ; preds = %75
br label %84
79: ; preds = %75
%80 = load i32, i32* %5
%81 = icmp eq i32 %80, 2
br i1 %81, label %82, label %83
82: ; preds = %79
store i32 0, i32* %2
br label %85
83: ; preds = %79
br label %84
84: ; preds = %83, %78
store i32 1, i32* %2
br label %85
85: ; preds = %84, %82
%86 = load i32, i32* %2
ret i32 %86
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s? \00"
@str = [44 x i8] c"Valid responses begin with: y Y n N q Q x X\00"
define i32 @affirm(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = trunc i64 %4 to i32
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %3, %1
br label %10
10: ; preds = %28, %9
%11 = tail call i32 (...) @getchar()
%12 = tail call i64 @isspace(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10, %14
%15 = tail call i32 (...) @getchar()
%16 = tail call i64 @isspace(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %14
18: ; preds = %14, %10
%19 = phi i32 [ %11, %10 ], [ %15, %14 ]
%20 = and i32 %19, -33
switch i32 %20, label %21 [
i32 89, label %33
i32 78, label %34
]
21: ; preds = %18
switch i32 %19, label %22 [
i32 120, label %32
i32 113, label %32
i32 88, label %32
i32 81, label %32
]
22: ; preds = %21
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
br i1 %2, label %26, label %24
24: ; preds = %22
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %26
26: ; preds = %24, %22
%27 = icmp eq i32 %19, 10
br i1 %27, label %28, label %29
28: ; preds = %29, %26
br label %10
29: ; preds = %26, %29
%30 = tail call i32 (...) @getchar()
%31 = icmp eq i32 %30, 10
br i1 %31, label %28, label %29
32: ; preds = %21, %21, %21, %21
tail call void @bail(i8* null, i32 0)
br label %34
33: ; preds = %18
br label %34
34: ; preds = %18, %33, %32
%35 = phi i32 [ 1, %32 ], [ 1, %33 ], [ 0, %18 ]
ret i32 %35
}