#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*/ STDIN_FILENO;
int /*<<< orphan*/ enableRawMode();
scalar_t__ iscntrl(char);
int /*<<< orphan*/ printf(char *, char, ...);
int read(int /*<<< orphan*/, char *, int);
int main() {
  enableRawMode();
  char c;
  while (read(STDIN_FILENO, &c, 1) == 1 && c != 'q') {
    if (iscntrl(c)) {
      printf("%d\n", c);
    } else {
      printf("%d (%c)\n", c, c);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <enableRawMode@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x6(%rbp)
jne    118a <main+0x4a>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
setne  %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
test   $0x1,%al
jne    119a <main+0x5a>
jmp    11e1 <main+0xa1>
movsbl -0x5(%rbp),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%rax
je     11c4 <main+0x84>
lea    0xe4c(%rip),%rdi
movsbl -0x5(%rbp),%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11dc <main+0x9c>
mov    -0x5(%rbp),%al
movsbl -0x5(%rbp),%edx
lea    0xe32(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <enableRawMode@plt>
mov    0x2e86(%rip),%r12
mov    (%r12),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    11dd <main+0x9d>
mov    0xf(%rsp),%al
cmp    $0x71,%al
je     11dd <main+0x9d>
lea    0xe83(%rip),%r14
lea    0xf(%rsp),%rbx
lea    0xe73(%rip),%r15
nopl   (%rax)
movsbl %al,%ebp
mov    %ebp,%edi
call   1040 <iscntrl@plt>
test   %rax,%rax
je     11b0 <main+0x70>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11be <main+0x7e>
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x1,%eax
jne    11dd <main+0x9d>
movzbl 0xf(%rsp),%eax
cmp    $0x71,%al
jne    1190 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [9 x i8] c"%d (%c)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
store i32 0, i32* %1
%3 = call i32 (...) @enableRawMode()
br label %4
4: ; preds = %26, %0
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @read(i32 %5, i8* %2, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 113
br label %12
12: ; preds = %8, %4
%13 = phi i1 [ false, %4 ], [ %11, %8 ]
br i1 %13, label %14, label %27
14: ; preds = %12
%15 = load i8, i8* %2
%16 = call i64 @iscntrl(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i8, i8* %2
%20 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %19)
br label %26
21: ; preds = %14
%22 = load i8, i8* %2
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %22, i32 %24)
br label %26
26: ; preds = %21, %18
br label %4
27: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [9 x i8] c"%d (%c)\0A\00"
define i32 @main() {
%1 = alloca i8
%2 = tail call i32 (...) @enableRawMode()
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %1, i32 1)
%5 = icmp eq i32 %4, 1
%6 = load i8, i8* %1
%7 = icmp ne i8 %6, 113
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %25
9: ; preds = %0, %18
%10 = phi i8 [ %22, %18 ], [ %6, %0 ]
%11 = tail call i64 @iscntrl(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8 signext %10)
br label %18
15: ; preds = %9
%16 = sext i8 %10 to i32
%17 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 signext %10, i32 %16)
br label %18
18: ; preds = %15, %13
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @read(i32 %19, i8* %1, i32 1)
%21 = icmp eq i32 %20, 1
%22 = load i8, i8* %1
%23 = icmp ne i8 %22, 113
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %9, label %25
25: ; preds = %18, %0
ret i32 0
}