#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ SIGTSTP;
scalar_t__ errno;
int getch();
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int nc_getch(bool mapraw, bool *wasraw) {
  bool ctrl_v = false;
  int ch;
restart:
  errno = 0;
  ch = getch();
  if (ch < 0 && errno == EINTR)
    goto restart;
  if (ctrl_v)
    return ch;
  if (ch == (('z') & 037)) {
    raise(SIGTSTP);
    goto restart;
  }
  if (mapraw) {
    if (ch == '\r') {
      ch = '\n';
    } else if (ch == (('v') & 037)) {
      if (wasraw)
        *wasraw = true;
      ctrl_v = true;
      goto restart;
    }
    if (wasraw)
      *wasraw = false;
  }
  return ch;
}


x86 assembly (clang, -O0):
<nc_getch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e9b(%rip),%rax
movq   $0x0,(%rax)
mov    $0x0,%al
call   1040 <getch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1177 <nc_getch+0x57>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    1177 <nc_getch+0x57>
jmp    1136 <nc_getch+0x16>
cmpl   $0x0,-0x14(%rbp)
je     118c <nc_getch+0x6c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1219 <nc_getch+0xf9>
cmpl   $0x1a,-0x18(%rbp)
jne    11a9 <nc_getch+0x89>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
jmp    1136 <nc_getch+0x16>
cmpl   $0x0,-0x8(%rbp)
je     1213 <nc_getch+0xf3>
cmpl   $0xd,-0x18(%rbp)
jne    11c9 <nc_getch+0xa9>
movl   $0xa,-0x18(%rbp)
jmp    11f9 <nc_getch+0xd9>
cmpl   $0x16,-0x18(%rbp)
jne    11f4 <nc_getch+0xd4>
cmpq   $0x0,-0x10(%rbp)
je     11e8 <nc_getch+0xc8>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    1136 <nc_getch+0x16>
jmp    11f9 <nc_getch+0xd9>
cmpq   $0x0,-0x10(%rbp)
je     120e <nc_getch+0xee>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1213 <nc_getch+0xf3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nc_getch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    $0x1,%r13b
mov    0x2e9d(%rip),%rbp
mov    0x2e8e(%rip),%rbx
mov    0x2e9f(%rip),%r12
jmp    1160 <nc_getch+0x40>
mov    (%r12),%edi
call   1030 <raise@plt>
mov    $0x1,%r13b
nopw   0x0(%rax,%rax,1)
movq   $0x0,0x0(%rbp)
xor    %eax,%eax
call   1040 <getch@plt>
test   %eax,%eax
jns    117c <nc_getch+0x5c>
mov    0x0(%rbp),%rcx
cmp    (%rbx),%rcx
je     1160 <nc_getch+0x40>
test   $0x1,%r13b
je     11bb <nc_getch+0x9b>
cmp    $0x1a,%eax
je     114b <nc_getch+0x2b>
test   %r14d,%r14d
je     11bb <nc_getch+0x9b>
cmp    $0x16,%eax
jne    11a5 <nc_getch+0x85>
xor    %r13d,%r13d
test   %r15,%r15
je     1160 <nc_getch+0x40>
movl   $0x1,(%r15)
xor    %r13d,%r13d
jmp    1160 <nc_getch+0x40>
cmp    $0xd,%eax
jne    11af <nc_getch+0x8f>
mov    $0xa,%eax
test   %r15,%r15
je     11bb <nc_getch+0x9b>
movl   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@SIGTSTP = global i32 0
define i32 @nc_getch(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 0, i32* %6
br label %8
8: ; preds = %43, %25, %16, %2
store i64 0, i64* @errno
%9 = call i32 (...) @getch()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %12
br label %8
17: ; preds = %12, %8
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32, i32* %7
store i32 %21, i32* %3
br label %53
22: ; preds = %17
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 26
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @SIGTSTP
%27 = call i32 @raise(i32 %26)
br label %8
28: ; preds = %22
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %28
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 13
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 10, i32* %7
br label %45
35: ; preds = %31
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, 22
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32*, i32** %5
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = load i32*, i32** %5
store i32 1, i32* %42
br label %43
43: ; preds = %41, %38
store i32 1, i32* %6
br label %8
44: ; preds = %35
br label %45
45: ; preds = %44, %34
%46 = load i32*, i32** %5
%47 = icmp ne i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load i32*, i32** %5
store i32 0, i32* %49
br label %50
50: ; preds = %48, %45
br label %51
51: ; preds = %50, %28
%52 = load i32, i32* %7
store i32 %52, i32* %3
br label %53
53: ; preds = %51, %20
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@SIGTSTP = global i32 0
define i32 @nc_getch(i32 %0, i32* writeonly %1) {
%3 = icmp eq i32 %0, 0
%4 = icmp eq i32* %1, null
br label %5
5: ; preds = %23, %2
%6 = phi i1 [ true, %2 ], [ %24, %23 ]
br label %7
7: ; preds = %5, %10
store i64 0, i64* @errno
%8 = tail call i32 (...) @getch()
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
br i1 %13, label %7, label %14
14: ; preds = %10, %7
br i1 %6, label %15, label %30
15: ; preds = %14
%16 = icmp eq i32 %8, 26
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* @SIGTSTP
%19 = tail call i32 @raise(i32 %18)
br label %23
20: ; preds = %15
br i1 %3, label %30, label %21
21: ; preds = %20
switch i32 %8, label %27 [
i32 13, label %26
i32 22, label %22
]
22: ; preds = %21
br i1 %4, label %23, label %25
23: ; preds = %22, %25, %17
%24 = phi i1 [ true, %17 ], [ false, %25 ], [ false, %22 ]
br label %5
25: ; preds = %22
store i32 1, i32* %1
br label %23
26: ; preds = %21
br label %27
27: ; preds = %21, %26
%28 = phi i32 [ 10, %26 ], [ %8, %21 ]
br i1 %4, label %30, label %29
29: ; preds = %27
store i32 0, i32* %1
br label %30
30: ; preds = %20, %14, %29, %27
%31 = phi i32 [ %28, %29 ], [ %28, %27 ], [ %8, %14 ], [ %8, %20 ]
ret i32 %31
}