#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*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, ...);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char);
int /*<<< orphan*/ printf(char *, scalar_t__);
int read(int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char nl = '\012';
  unsigned char schar;
  int geton = 0;
  int save;
  save = fcntl(0, F_GETFL);
  fcntl(0, F_SETFL, save | O_NONBLOCK);
  while (1) {
    int j;
    int k;
    if (geton == 0) {
      j = read(0, (void *)&schar, 1);
      if (-1 == j) {
        if (EAGAIN != errno)
          printf("errno = %d\n", errno);
        continue;
      }
      if (0 == j) {
        exit(1);
      }
      if ('\n' == (char)schar)
        continue;
      if ((2 == argc) && ('\040' == (char)schar))
        continue;
      fprintf(stdout, "%c", (char)schar);
      fflush(stdout);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0xa,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
xor    %edi,%edi
mov    $0x0,%al
call   1030 <fcntl@plt>
cmpl   $0x0,-0x18(%rbp)
jne    128a <main+0x12a>
xor    %edi,%edi
lea    -0x12(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    $0xffffffff,%eax
cmp    -0x20(%rbp),%eax
jne    1214 <main+0xb4>
mov    0x2dca(%rip),%rax
mov    (%rax),%rax
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rax
je     120f <main+0xaf>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rsi
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
jmp    11b4 <main+0x54>
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    1229 <main+0xc9>
mov    $0x1,%edi
call   1080 <exit@plt>
movsbl -0x12(%rbp),%ecx
mov    $0xa,%eax
cmp    %ecx,%eax
jne    123f <main+0xdf>
jmp    11b4 <main+0x54>
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    1263 <main+0x103>
movsbl -0x12(%rbp),%ecx
mov    $0x20,%eax
cmp    %ecx,%eax
jne    1263 <main+0x103>
jmp    11b4 <main+0x54>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
movsbl -0x12(%rbp),%edx
call   1060 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    11b4 <main+0x54>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r12d
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e51(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e58(%rip),%rcx
or     (%rcx),%eax
xor    %edi,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
lea    0x7(%rsp),%rbx
mov    0x2e07(%rip),%r13
mov    0x2e20(%rip),%rbp
lea    0xe49(%rip),%r14
mov    0x2e02(%rip),%r15
jmp    11e0 <main+0x80>
mov    (%r15),%edi
movsbl %al,%edx
lea    0xe3f(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%r15),%edi
call   1070 <fflush@plt>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1210 <main+0xb0>
test   %eax,%eax
je     1224 <main+0xc4>
movzbl 0x7(%rsp),%eax
cmp    $0xa,%al
je     11e0 <main+0x80>
cmp    $0x2,%r12d
jne    11c0 <main+0x60>
cmp    $0x20,%al
je     11e0 <main+0x80>
jmp    11c0 <main+0x60>
nopl   (%rax)
mov    0x0(%rbp),%rsi
cmp    %rsi,0x0(%r13)
je     11e0 <main+0x80>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    11e0 <main+0x80>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EAGAIN = global i64 0
@errno = global i64 0
@.str = [12 x i8] c"errno = %d\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 10, i8* %6
store i32 0, i32* %8
%12 = load i32, i32* @F_GETFL
%13 = call i32 (i32, i32, ...) @fcntl(i32 0, i32 %12)
store i32 %13, i32* %9
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* %9
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %15, %16
%18 = call i32 (i32, i32, ...) @fcntl(i32 0, i32 %14, i32 %17)
br label %19
19: ; preds = %2, %33, %43, %51, %58
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %58
22: ; preds = %19
%23 = call i32 @read(i32 0, i8* %7, i32 1)
store i32 %23, i32* %10
%24 = load i32, i32* %10
%25 = icmp eq i32 -1, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i64, i64* @EAGAIN
%28 = load i64, i64* @errno
%29 = icmp ne i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i64, i64* @errno
%32 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %31)
br label %33
33: ; preds = %30, %26
br label %19
34: ; preds = %22
%35 = load i32, i32* %10
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %34
%40 = load i8, i8* %7
%41 = sext i8 %40 to i32
%42 = icmp eq i32 10, %41
br i1 %42, label %43, label %44
43: ; preds = %39
br label %19
44: ; preds = %39
%45 = load i32, i32* %4
%46 = icmp eq i32 2, %45
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = icmp eq i32 32, %49
br i1 %50, label %51, label %52
51: ; preds = %47
br label %19
52: ; preds = %47, %44
%53 = load i32, i32* @stdout
%54 = load i8, i8* %7
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %54)
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
br label %58
58: ; preds = %52, %19
br label %19
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@EAGAIN = global i64 0
@errno = global i64 0
@.str = [12 x i8] c"errno = %d\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 (i32, i32, ...) @fcntl(i32 0, i32 %4)
%6 = load i32, i32* @F_SETFL
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %5
%9 = tail call i32 (i32, i32, ...) @fcntl(i32 0, i32 %6, i32 %8)
%10 = icmp eq i32 %0, 2
br label %11
11: ; preds = %27, %2
%12 = call i32 @read(i32 0, i8* %3, i32 1)
switch i32 %12, label %21 [
i32 -1, label %13
i32 0, label %19
]
13: ; preds = %11
%14 = load i64, i64* @EAGAIN
%15 = load i64, i64* @errno
%16 = icmp eq i64 %14, %15
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %27
19: ; preds = %11
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i8, i8* %3
%23 = icmp eq i8 %22, 10
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = icmp eq i8 %22, 32
%26 = select i1 %10, i1 %25, i1 false
br i1 %26, label %27, label %28
27: ; preds = %24, %21, %13, %17, %28
br label %11
28: ; preds = %24
%29 = load i32, i32* @stdout
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 signext %22)
%31 = load i32, i32* @stdout
%32 = tail call i32 @fflush(i32 %31)
br label %27
}