#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 */
struct termios {
  int /*<<< orphan*/ *c_cc;
};

/* Variables and functions */
int /*<<< orphan*/ CTRL(float);
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TCSANOW;
size_t VEOF;
int read(int /*<<< orphan*/, char *, int);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main() {
  struct termios attr[1];
  char c;
  if (tcgetattr(STDIN_FILENO, attr) == -1)
    return 1;
  attr->c_cc[VEOF] = CTRL('f');
  if (tcsetattr(STDIN_FILENO, TCSANOW, attr) == -1)
    return 1;
  while (read(STDIN_FILENO, &c, 1) == 1)
    write(STDOUT_FILENO, &c, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1186 <main+0x36>
movl   $0x1,-0x4(%rbp)
jmp    121e <main+0xce>
movss  0xe72(%rip),%xmm0
call   1050 <CTRL@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    11d6 <main+0x86>
movl   $0x1,-0x4(%rbp)
jmp    121e <main+0xce>
jmp    11db <main+0x8b>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1217 <main+0xc7>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11db <main+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6f(%rip),%r15
mov    (%r15),%edi
lea    0x10(%rsp),%rsi
call   1060 <tcgetattr@plt>
mov    $0x1,%r14d
cmp    $0xffffffff,%eax
je     1205 <main+0xb5>
movss  0xe7b(%rip),%xmm0
call   1050 <CTRL@plt>
mov    0x10(%rsp),%rcx
mov    0x2e2a(%rip),%rdx
mov    (%rdx),%rdx
mov    %eax,(%rcx,%rdx,4)
mov    (%r15),%edi
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     1205 <main+0xb5>
mov    (%r15),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
xor    %r14d,%r14d
cmp    $0x1,%eax
jne    1205 <main+0xb5>
mov    0x2e18(%rip),%rbp
lea    0xf(%rsp),%rbx
nopl   (%rax)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     11e0 <main+0x90>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32* }
@STDIN_FILENO = global i32 0
@VEOF = global i64 0
@TCSANOW = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x %struct.termios]
%3 = alloca i8
store i32 0, i32* %1
%4 = load i32, i32* @STDIN_FILENO
%5 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %2, i64 0, i64 0
%6 = call i32 @tcgetattr(i32 %4, %struct.termios* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %31
9: ; preds = %0
%10 = call i32 @CTRL(float 1.020000e+02)
%11 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %2, i64 0, i64 0
%12 = getelementptr inbounds %struct.termios, %struct.termios* %11, i32 0, i32 0
%13 = load i32*, i32** %12
%14 = load i64, i64* @VEOF
%15 = getelementptr inbounds i32, i32* %13, i64 %14
store i32 %10, i32* %15
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSANOW
%18 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %2, i64 0, i64 0
%19 = call i32 @tcsetattr(i32 %16, i32 %17, %struct.termios* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %9
store i32 1, i32* %1
br label %31
22: ; preds = %9
br label %23
23: ; preds = %27, %22
%24 = load i32, i32* @STDIN_FILENO
%25 = call i32 @read(i32 %24, i8* %3, i32 1)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @STDOUT_FILENO
%29 = call i32 @write(i32 %28, i8* %3, i32 1)
br label %23
30: ; preds = %23
store i32 0, i32* %1
br label %31
31: ; preds = %30, %21, %8
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
%struct.termios = type { i32* }
@STDIN_FILENO = global i32 0
@VEOF = global i64 0
@TCSANOW = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca [1 x %struct.termios]
%2 = alloca i8
%3 = bitcast [1 x %struct.termios]* %1 to i8*
%4 = load i32, i32* @STDIN_FILENO
%5 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %1, i64 0, i64 0
%6 = call i32 @tcgetattr(i32 %4, %struct.termios* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %28, label %8
8: ; preds = %0
%9 = call i32 @CTRL(float 1.020000e+02)
%10 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %1, i64 0, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i64, i64* @VEOF
%13 = getelementptr inbounds i32, i32* %11, i64 %12
store i32 %9, i32* %13
%14 = load i32, i32* @STDIN_FILENO
%15 = load i32, i32* @TCSANOW
%16 = call i32 @tcsetattr(i32 %14, i32 %15, %struct.termios* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %28, label %18
18: ; preds = %8
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @read(i32 %19, i8* %2, i32 1)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %28
22: ; preds = %18, %22
%23 = load i32, i32* @STDOUT_FILENO
%24 = call i32 @write(i32 %23, i8* %2, i32 1)
%25 = load i32, i32* @STDIN_FILENO
%26 = call i32 @read(i32 %25, i8* %2, i32 1)
%27 = icmp eq i32 %26, 1
br i1 %27, label %22, label %28
28: ; preds = %22, %18, %8, %0
%29 = phi i32 [ 1, %0 ], [ 1, %8 ], [ 0, %18 ], [ 0, %22 ]
ret i32 %29
}