#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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
scalar_t__ input_available();
int read(int /*<<< orphan*/, char *, int);
int read_char() {
  char buff[256];
  int nch = 0;
  while (input_available()) {
    nch = read(STDIN_FILENO, buff, sizeof(buff));
  }
  return nch ? buff[nch - 1] : -1;
}


x86 assembly (clang, -O0):
<read_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x104(%rbp)
mov    $0x0,%al
call   1040 <input_available@plt>
cmp    $0x0,%rax
je     116b <read_char+0x4b>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    -0x100(%rbp),%rsi
mov    $0x100,%edx
call   1030 <read@plt>
mov    %eax,-0x104(%rbp)
jmp    1135 <read_char+0x15>
cmpl   $0x0,-0x104(%rbp)
je     1196 <read_char+0x76>
mov    -0x104(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x100(%rbp,%rax,1),%eax
ff
mov    %eax,-0x108(%rbp)
jmp    11a6 <read_char+0x86>
mov    $0xffffffff,%eax
mov    %eax,-0x108(%rbp)
jmp    11a6 <read_char+0x86>
mov    -0x108(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_char>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   1040 <input_available@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     117a <read_char+0x5a>
mov    0x2e9a(%rip),%rbx
mov    %rsp,%r15
nopl   0x0(%rax)
mov    (%rbx),%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1030 <read@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <input_available@plt>
test   %rax,%rax
jne    1150 <read_char+0x30>
test   %ebp,%ebp
je     117a <read_char+0x5a>
movslq %ebp,%rax
movsbl -0x1(%rax,%r15,1),%r14d
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
define i32 @read_char() {
%1 = alloca [256 x i8]
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %6, %0
%4 = call i64 (...) @input_available()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i32, i32* @STDIN_FILENO
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 256)
store i32 %9, i32* %2
br label %3
10: ; preds = %3
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %2
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
br label %21
20: ; preds = %10
br label %21
21: ; preds = %20, %13
%22 = phi i32 [ %19, %13 ], [ -1, %20 ]
ret i32 %22
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
define i32 @read_char() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i64 (...) @input_available()
%4 = icmp eq i64 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %0, %5
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @read(i32 %6, i8* %2, i32 256)
%8 = tail call i64 (...) @input_available()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = icmp eq i32 %7, 0
br i1 %11, label %18, label %12
12: ; preds = %10
%13 = add nsw i32 %7, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
br label %18
18: ; preds = %0, %10, %12
%19 = phi i32 [ %17, %12 ], [ -1, %10 ], [ -1, %0 ]
ret i32 %19
}