#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 */
char EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char getchar();
int /*<<< orphan*/ printf(char *, char const *const);
int /*<<< orphan*/ stderr;
char toupper(char const);
int main(int argc, const char *const argv[]) {
  const char *message = argv[1];
  const char *options;
  if (!message) {
    fprintf(stderr,
            "dumbask: asks the user a question.\n"
            "Specify a message as the first argument (quoted!).\n"
            "You may optionally specify the choices as the second argument.\n"
            "Default choices are YN. Exit code is 0 for first, 1 for second, "
            "etc.\n");
    return 0;
  }
  options = argv[2] ?: "YN";
  printf("%s", argv[1]);
  for (;;) {
    char c = getchar();
    if (c == EOF)
      return 0;
    c = toupper(c);
    int i;
    for (i = 0; options[i]; i++)
      if (c == toupper(options[i]))
        return i;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118e <main+0x4e>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11b1 <main+0x71>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    11c1 <main+0x81>
lea    0xf23(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    11c1 <main+0x81>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xf06(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
mov    0x2df6(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1209 <main+0xc9>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x139>
movsbl -0x21(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x21(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1274 <main+0x134>
movsbl -0x21(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x3c(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
jne    1261 <main+0x121>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1279 <main+0x139>
jmp    1266 <main+0x126>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    121c <main+0xdc>
jmp    11dd <main+0x9d>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rax
mov    0x8(%rsi),%rsi
test   %rsi,%rsi
je     11cb <main+0x8b>
mov    0x10(%rax),%rax
test   %rax,%rax
lea    0xf7a(%rip),%r14
cmovne %rax,%r14
lea    0xf72(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e67(%rip),%r15
cmp    (%r15),%al
je     11e2 <main+0xa2>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
mov    (%r14),%al
test   %al,%al
je     11bb <main+0x7b>
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <toupper@plt>
cmp    %al,%bpl
je     11e2 <main+0xa2>
movzbl 0x1(%r14,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <main+0x60>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%al
jne    1186 <main+0x46>
jmp    11e2 <main+0xa2>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [219 x i8] c"dumbask: asks the user a question.\0ASpecify a message as the first argument (quoted!).\0AYou may optionally specify the choices as the second argument.\0ADefault choices are YN. Exit code is 0 for first, 1 for second, etc.\0A\00"
@.str.1 = [3 x i8] c"YN\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %67
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %24
23: ; preds = %18
br label %25
24: ; preds = %18
br label %25
25: ; preds = %24, %23
%26 = phi i8* [ %21, %23 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %24 ]
store i8* %26, i8** %7
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %66, %25
%32 = call signext i8 (...) @getchar()
store i8 %32, i8* %8
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %34, %36
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 0, i32* %3
br label %67
39: ; preds = %31
%40 = load i8, i8* %8
%41 = call signext i8 @toupper(i8 signext %40)
store i8 %41, i8* %8
store i32 0, i32* %9
br label %42
42: ; preds = %63, %39
%43 = load i8*, i8** %7
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = icmp ne i8 %47, 0
br i1 %48, label %49, label %66
49: ; preds = %42
%50 = load i8, i8* %8
%51 = sext i8 %50 to i32
%52 = load i8*, i8** %7
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = call signext i8 @toupper(i8 signext %56)
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %51, %58
br i1 %59, label %60, label %62
60: ; preds = %49
%61 = load i32, i32* %9
store i32 %61, i32* %3
br label %67
62: ; preds = %49
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %42
66: ; preds = %42
br label %31
67: ; preds = %60, %38, %15
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [219 x i8] c"dumbask: asks the user a question.\0ASpecify a message as the first argument (quoted!).\0AYou may optionally specify the choices as the second argument.\0ADefault choices are YN. Exit code is 0 for first, 1 for second, etc.\0A\00"
@.str.1 = [3 x i8] c"YN\00"
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
%13 = select i1 %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = tail call signext i8 (...) @getchar()
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %39, label %22
18: ; preds = %32, %22
%19 = tail call signext i8 (...) @getchar()
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %39, label %22
22: ; preds = %9, %18
%23 = phi i8 [ %19, %18 ], [ %15, %9 ]
%24 = tail call signext i8 @toupper(i8 signext %23)
%25 = load i8, i8* %13
%26 = icmp eq i8 %25, 0
br i1 %26, label %18, label %27
27: ; preds = %22, %32
%28 = phi i64 [ %33, %32 ], [ 0, %22 ]
%29 = phi i8 [ %35, %32 ], [ %25, %22 ]
%30 = tail call signext i8 @toupper(i8 signext %29)
%31 = icmp eq i8 %24, %30
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = add nuw i64 %28, 1
%34 = getelementptr inbounds i8, i8* %13, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %18, label %27
37: ; preds = %27
%38 = trunc i64 %28 to i32
br label %39
39: ; preds = %18, %37, %9, %6
%40 = phi i32 [ 0, %6 ], [ 0, %9 ], [ %38, %37 ], [ 0, %18 ]
ret i32 %40
}