#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 getch();
int /*<<< orphan*/ printw(char *, ...);
int /*<<< orphan*/ ungetch(char);
void *catchInput(void *threadInput) {
  bool ignoreInput = false;
  char *temp = (char *)threadInput;
  char output = ' ';
  while (1) {
    *temp = getch();
    if (*temp == 'q')
      return 0;
    if (*temp == '\n') {
      if (ignoreInput) {
        printw("Ignore is now off.\n");
      } else {
        printw("Ignore is now on.\n");
      }
      ignoreInput = !ignoreInput;
    } else if (!ignoreInput) {
      ungetch(*temp);
      output = getch();
      printw("[%c] accepted.\n", output);
      ignoreInput = true;
      printw("Ignore is now on.\n");
    } else {
      printw("[%c] ignored.\n", *temp);
    }
  }
}


x86 assembly (clang, -O0):
<catchInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x20,-0x19(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
jne    1176 <catchInput+0x46>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11c7 <catchInput+0x97>
cmpl   $0x0,-0xc(%rbp)
je     11a3 <catchInput+0x73>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
jmp    11b1 <catchInput+0x81>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
jmp    122d <catchInput+0xfd>
cmpl   $0x0,-0xc(%rbp)
jne    1213 <catchInput+0xe3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <ungetch@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
movl   $0x1,-0xc(%rbp)
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
jmp    1228 <catchInput+0xf8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printw@plt>
jmp    122d <catchInput+0xfd>
jmp    114f <catchInput+0x1f>

x86 assembly (clang, -O2):
<catchInput>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xecf(%rip),%r14
lea    0xeb4(%rip),%r13
lea    0xed4(%rip),%r15
lea    0xedd(%rip),%r12
xor    %ebp,%ebp
jmp    1173 <catchInput+0x43>
xchg   %ax,%ax
test   %ebp,%ebp
mov    %r13,%rdi
cmove  %r14,%rdi
xor    %eax,%eax
call   1030 <printw@plt>
xor    $0x1,%ebp
xor    %eax,%eax
call   1050 <getch@plt>
mov    %al,(%rbx)
cmp    $0xa,%al
je     1160 <catchInput+0x30>
cmp    $0x71,%al
je     11c8 <catchInput+0x98>
movsbl %al,%esi
test   %ebp,%ebp
je     119c <catchInput+0x6c>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printw@plt>
mov    $0x1,%ebp
jmp    1173 <catchInput+0x43>
mov    %esi,%edi
call   1040 <ungetch@plt>
xor    %eax,%eax
call   1050 <getch@plt>
movsbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printw@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printw@plt>
mov    $0x1,%ebp
jmp    1173 <catchInput+0x43>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Ignore is now off.\0A\00"
@.str.1 = [19 x i8] c"Ignore is now on.\0A\00"
@.str.2 = [16 x i8] c"[%c] accepted.\0A\00"
@.str.3 = [15 x i8] c"[%c] ignored.\0A\00"
define i8* @catchInput(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
store i8* %6, i8** %4
store i8 32, i8* %5
br label %7
7: ; preds = %1, %50
%8 = call signext i8 (...) @getch()
%9 = load i8*, i8** %4
store i8 %8, i8* %9
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 113
br i1 %13, label %14, label %15
14: ; preds = %7
ret i8* null
15: ; preds = %7
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %32
20: ; preds = %15
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %23
%28 = load i32, i32* %3
%29 = icmp ne i32 %28, 0
%30 = xor i1 %29, true
%31 = zext i1 %30 to i32
store i32 %31, i32* %3
br label %50
32: ; preds = %15
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %44, label %35
35: ; preds = %32
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = call i32 @ungetch(i8 signext %37)
%39 = call signext i8 (...) @getch()
store i8 %39, i8* %5
%40 = load i8, i8* %5
%41 = sext i8 %40 to i32
%42 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %41)
store i32 1, i32* %3
%43 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %49
44: ; preds = %32
%45 = load i8*, i8** %4
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %44, %35
br label %50
50: ; preds = %49, %27
br label %7
}

LLVM IR (-O2):
@.str = [20 x i8] c"Ignore is now off.\0A\00"
@.str.1 = [19 x i8] c"Ignore is now on.\0A\00"
@.str.2 = [16 x i8] c"[%c] accepted.\0A\00"
@.str.3 = [15 x i8] c"[%c] ignored.\0A\00"
define noalias i8* @catchInput(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %20, %1
%3 = phi i32 [ 0, %1 ], [ %21, %20 ]
%4 = tail call signext i8 (...) @getch()
store i8 %4, i8* %0
%5 = sext i8 %4 to i32
switch i8 %4, label %12 [
i8 113, label %6
i8 10, label %7
]
6: ; preds = %2
ret i8* null
7: ; preds = %2
%8 = icmp eq i32 %3, 0
%9 = select i1 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0)
%10 = tail call i32 (i8*, ...) @printw(i8* %9)
%11 = xor i32 %3, 1
br label %20
12: ; preds = %2
%13 = icmp eq i32 %3, 0
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = tail call i32 @ungetch(i8 signext %4)
%16 = tail call signext i8 (...) @getch()
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %14, %22, %7
%21 = phi i32 [ %11, %7 ], [ 1, %22 ], [ 1, %14 ]
br label %2
22: ; preds = %12
%23 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %20
}