#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*/ bye();
int /*<<< orphan*/ curscr;
int /*<<< orphan*/ exit(int);
scalar_t__ read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/);
int readchar(void) {
  int cnt;
  unsigned char c;
over:
  cnt = 0;
  while (read(STDIN_FILENO, &c, sizeof(unsigned char)) <= 0)
    if (cnt++ > 100) {
      bye();
      exit(1);
    }
  if (c == ('L' - 'A' + 1)) {
    wrefresh(curscr);
    goto over;
  }
  if (c == '\r')
    return ('\n');
  else
    return (c);
}


x86 assembly (clang, -O0):
<readchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     119a <readchar+0x5a>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x64,%eax
jle    1195 <readchar+0x55>
mov    $0x0,%al
call   1050 <bye@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    114f <readchar+0xf>
movzbl -0x9(%rbp),%eax
cmp    $0xc,%eax
jne    11ba <readchar+0x7a>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1030 <wrefresh@plt>
jmp    1148 <readchar+0x8>
movzbl -0x9(%rbp),%eax
cmp    $0xd,%eax
jne    11d3 <readchar+0x93>
movl   $0xa,-0x4(%rbp)
jmp    11da <readchar+0x9a>
movzbl -0x9(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readchar>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
mov    0x2e90(%rip),%r14
lea    0x7(%rsp),%rbx
mov    0x2e74(%rip),%r15
jmp    1168 <readchar+0x28>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x66,%ebp
je     11a7 <readchar+0x67>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    1160 <readchar+0x20>
movzbl 0x7(%rsp),%eax
cmp    $0xc,%eax
jne    1193 <readchar+0x53>
mov    (%r15),%edi
call   1030 <wrefresh@plt>
xor    %ebp,%ebp
jmp    1168 <readchar+0x28>
cmp    $0xd,%al
jne    119c <readchar+0x5c>
mov    $0xa,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1050 <bye@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@curscr = global i32 0
define i32 @readchar() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
br label %4
4: ; preds = %21, %0
store i32 0, i32* %2
br label %5
5: ; preds = %16, %4
%6 = load i32, i32* @STDIN_FILENO
%7 = call i64 @read(i32 %6, i8* %3, i32 1)
%8 = icmp sle i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
store i32 %11, i32* %2
%12 = icmp sgt i32 %10, 100
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 (...) @bye()
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
br label %5
17: ; preds = %5
%18 = load i8, i8* %3
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 12
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @curscr
%23 = call i32 @wrefresh(i32 %22)
br label %4
24: ; preds = %17
%25 = load i8, i8* %3
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 13
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 10, i32* %1
br label %32
29: ; preds = %24
%30 = load i8, i8* %3
%31 = zext i8 %30 to i32
store i32 %31, i32* %1
br label %32
32: ; preds = %29, %28
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@curscr = global i32 0
define i32 @readchar() {
%1 = alloca i8
br label %2
2: ; preds = %10, %0
%3 = phi i32 [ 0, %0 ], [ %11, %10 ]
%4 = load i32, i32* @STDIN_FILENO
%5 = call i64 @read(i32 %4, i8* %1, i32 1)
%6 = icmp slt i64 %5, 1
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = add nuw nsw i32 %3, 1
%9 = icmp eq i32 %8, 102
br i1 %9, label %12, label %10
10: ; preds = %7, %17
%11 = phi i32 [ %8, %7 ], [ 0, %17 ]
br label %2
12: ; preds = %7
%13 = tail call i32 (...) @bye()
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8, i8* %1
switch i8 %16, label %20 [
i8 12, label %17
i8 13, label %22
]
17: ; preds = %15
%18 = load i32, i32* @curscr
%19 = tail call i32 @wrefresh(i32 %18)
br label %10
20: ; preds = %15
%21 = zext i8 %16 to i32
br label %22
22: ; preds = %15, %20
%23 = phi i32 [ %21, %20 ], [ 10, %15 ]
ret i32 %23
}