#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 */
typedef int /*<<< orphan*/ quit;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ disableRawMode(int /*<<< orphan*/);
int enableRawMode(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ isprint(int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stdout;
void linenoisePrintKeyCodes(void) {
  char quit[4];
  printf("Linenoise key codes debugging mode.\n"
         "Press keys to see scan codes. Type 'quit' at any time to exit.\n");
  if (enableRawMode(STDIN_FILENO) == -1)
    return;
  memset(quit, ' ', 4);
  while (1) {
    char c;
    int nread;
    nread = read(STDIN_FILENO, &c, 1);
    if (nread <= 0)
      continue;
    memmove(quit, quit + 1, sizeof(quit) - 1);
    quit[sizeof(quit) - 1] = c;
    if (memcmp(quit, "quit", sizeof(quit)) == 0)
      break;
    printf("'%c' %02x (%d) (type quit to exit)\n", isprint((int)c) ? c : '?',
           (int)c, (int)c);
    printf("\r");
    fflush(stdout);
  }
  disableRawMode(STDIN_FILENO);
}


x86 assembly (clang, -O0):
<linenoisePrintKeyCodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
jne    11c2 <linenoisePrintKeyCodes+0x32>
jmp    12b2 <linenoisePrintKeyCodes+0x122>
lea    -0x4(%rbp),%rdi
mov    $0x20,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     11fe <linenoisePrintKeyCodes+0x6e>
jmp    11d5 <linenoisePrintKeyCodes+0x45>
lea    -0x4(%rbp),%rdi
lea    -0x4(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3,%edx
call   10b0 <memmove@plt>
mov    -0x5(%rbp),%al
mov    %al,-0x1(%rbp)
lea    -0x4(%rbp),%rdi
lea    0xe3f(%rip),%rsi
mov    $0x4,%edx
call   1080 <memcmp@plt>
cmp    $0x0,%rax
jne    123e <linenoisePrintKeyCodes+0xae>
jmp    12a4 <linenoisePrintKeyCodes+0x114>
movsbl -0x5(%rbp),%edi
call   10a0 <isprint@plt>
cmp    $0x0,%rax
je     125d <linenoisePrintKeyCodes+0xcd>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    126a <linenoisePrintKeyCodes+0xda>
mov    $0x3f,%eax
mov    %eax,-0x10(%rbp)
jmp    126a <linenoisePrintKeyCodes+0xda>
mov    -0x10(%rbp),%esi
movsbl -0x5(%rbp),%edx
movsbl -0x5(%rbp),%ecx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
jmp    11d5 <linenoisePrintKeyCodes+0x45>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   1040 <disableRawMode@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linenoisePrintKeyCodes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe67(%rip),%rdi
call   1050 <puts@plt>
mov    0x2e0a(%rip),%r14
mov    (%r14),%edi
call   1030 <enableRawMode@plt>
cmp    $0xffffffff,%eax
je     1298 <linenoisePrintKeyCodes+0xe8>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
lea    0x3(%rsp),%r15
lea    0xdfe(%rip),%r12
mov    0x2dd7(%rip),%r13
nopl   0x0(%rax)
mov    (%r14),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
jle    1210 <linenoisePrintKeyCodes+0x60>
mov    %rbx,%rdi
lea    0x5(%rsp),%rsi
mov    $0x3,%edx
call   10d0 <memmove@plt>
movsbl 0x3(%rsp),%ebp
mov    %bpl,0x7(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   10a0 <memcmp@plt>
test   %rax,%rax
je     1290 <linenoisePrintKeyCodes+0xe0>
mov    %ebp,%edi
call   10c0 <isprint@plt>
test   %rax,%rax
mov    %ebp,%esi
mov    $0x3f,%eax
cmove  %eax,%esi
lea    0xd95(%rip),%rdi
mov    %ebp,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xd,%edi
call   1040 <putchar@plt>
mov    0x0(%r13),%edi
call   10b0 <fflush@plt>
jmp    1210 <linenoisePrintKeyCodes+0x60>
mov    (%r14),%edi
call   1060 <disableRawMode@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [100 x i8] c"Linenoise key codes debugging mode.\0APress keys to see scan codes. Type 'quit' at any time to exit.\0A\00"
@STDIN_FILENO = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [36 x i8] c"'%c' %02x (%d) (type quit to exit)\0A\00"
@.str.3 = [2 x i8] c"\0D\00"
@stdout = global i32 0
define void @linenoisePrintKeyCodes() {
%1 = alloca [4 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @enableRawMode(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
br label %51
9: ; preds = %0
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i8 signext 32, i32 4)
br label %12
12: ; preds = %9, %17, %38
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @read(i32 %13, i8* %2, i32 1)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @memmove(i8* %19, i8* %21, i32 3)
%23 = load i8, i8* %2
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
store i8 %23, i8* %24
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%26 = call i64 @memcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %18
br label %48
29: ; preds = %18
%30 = load i8, i8* %2
%31 = sext i8 %30 to i32
%32 = call i64 @isprint(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8, i8* %2
%36 = sext i8 %35 to i32
br label %38
37: ; preds = %29
br label %38
38: ; preds = %37, %34
%39 = phi i32 [ %36, %34 ], [ 63, %37 ]
%40 = load i8, i8* %2
%41 = sext i8 %40 to i32
%42 = load i8, i8* %2
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %41, i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 @fflush(i32 %46)
br label %12
48: ; preds = %28
%49 = load i32, i32* @STDIN_FILENO
%50 = call i32 @disableRawMode(i32 %49)
br label %51
51: ; preds = %48, %8
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [36 x i8] c"'%c' %02x (%d) (type quit to exit)\0A\00"
@stdout = global i32 0
@str = [99 x i8] c"Linenoise key codes debugging mode.\0APress keys to see scan codes. Type 'quit' at any time to exit.\00"
define void @linenoisePrintKeyCodes() {
%1 = alloca [4 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @str, i64 0, i64 0))
%5 = load i32, i32* @STDIN_FILENO
%6 = tail call i32 @enableRawMode(i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %34, label %8
8: ; preds = %0
%9 = call i32 @memset(i8* %3, i8 signext 32, i32 4)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
br label %12
12: ; preds = %30, %8
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @read(i32 %13, i8* %2, i32 1)
%15 = icmp slt i32 %14, 1
br i1 %15, label %30, label %16
16: ; preds = %12
%17 = call i32 @memmove(i8* %3, i8* %10, i32 3)
%18 = load i8, i8* %2
store i8 %18, i8* %11
%19 = call i64 @memcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = sext i8 %18 to i32
%23 = call i64 @isprint(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32 63, i32 %22
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %22, i32 %22)
%27 = call i32 @putchar(i32 13)
%28 = load i32, i32* @stdout
%29 = call i32 @fflush(i32 %28)
br label %30
30: ; preds = %12, %21
br label %12
31: ; preds = %16
%32 = load i32, i32* @STDIN_FILENO
%33 = call i32 @disableRawMode(i32 %32)
br label %34
34: ; preds = %0, %31
ret void
}