#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__ EAGAIN;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ enable_raw_mode();
scalar_t__ errno;
scalar_t__ iscntrl(char);
int /*<<< orphan*/ printf(char *, char, ...);
int read(int /*<<< orphan*/, char *, int);
int main(int argc, char *argv[]) {
  enable_raw_mode();
  while (1) {
    char c = '\0';
    if (read(STDIN_FILENO, &c, 1) == -1 && errno != EAGAIN)
      die("read");
    if (iscntrl(c)) {
      printf("%d\r\n", c);
    } else {
      printf("%d ('%c')\r\n", c, c);
    }
    if (c == 'q')
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <enable_raw_mode@plt>
movb   $0x0,-0x11(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    11b7 <main+0x67>
mov    0x2e48(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
je     11b7 <main+0x67>
lea    0xe4e(%rip),%rdi
call   1070 <die@plt>
movsbl -0x11(%rbp),%edi
call   1040 <iscntrl@plt>
cmp    $0x0,%rax
je     11e1 <main+0x91>
lea    0xe34(%rip),%rdi
movsbl -0x11(%rbp),%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f9 <main+0xa9>
mov    -0x11(%rbp),%al
movsbl -0x11(%rbp),%edx
lea    0xe1b(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x71,%eax
jne    120b <main+0xbb>
jmp    1210 <main+0xc0>
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <enable_raw_mode@plt>
mov    0x2e6f(%rip),%r13
lea    0x7(%rsp),%rbx
mov    0x2e53(%rip),%r14
lea    0xe8e(%rip),%r15
lea    0xe82(%rip),%r12
jmp    11a4 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x71,%bpl
je     1203 <main+0xb3>
movb   $0x0,0x7(%rsp)
mov    0x0(%r13),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x90>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     11e0 <main+0x90>
lea    0xe2b(%rip),%rdi
call   1070 <die@plt>
nopw   0x0(%rax,%rax,1)
movsbl 0x7(%rsp),%ebp
mov    %ebp,%edi
call   1040 <iscntrl@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x71,%bpl
jne    11a4 <main+0x54>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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