#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 c_lflag;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
unsigned char getchar();
int /*<<< orphan*/ putchar(unsigned char);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(int argc, char *args[]) {
  struct termios old_tio, new_tio;
  unsigned char c;
  tcgetattr(STDIN_FILENO, &old_tio);
  new_tio = old_tio;
  new_tio.c_lflag &= (~ICANON & ~ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
  while ((c = getchar()) != '\n') {
    putchar(c);
  };
  tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
  return 0;
}


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)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x21(%rbp)
movzbl %al,%eax
cmp    $0xa,%eax
je     11cd <main+0x8d>
movzbl -0x21(%rbp),%edi
call   1030 <putchar@plt>
jmp    11a9 <main+0x69>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e82(%rip),%rbx
mov    (%rbx),%edi
lea    0x8(%rsp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2e67(%rip),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    0x8(%rsp),%ecx
mov    %ecx,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2e69(%rip),%r14
mov    (%r14),%esi
lea    0x10(%rsp),%rdx
call   1060 <tcsetattr@plt>
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%al
je     11a5 <main+0x65>
movzbl %al,%edi
call   1030 <putchar@plt>
jmp    1190 <main+0x50>
mov    (%rbx),%edi
mov    (%r14),%esi
lea    0x8(%rsp),%rdx
call   1060 <tcsetattr@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca %struct.termios
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @STDIN_FILENO
%10 = call i32 @tcgetattr(i32 %9, %struct.termios* %6)
%11 = bitcast %struct.termios* %7 to i8*
%12 = bitcast %struct.termios* %6 to i8*
%13 = load i32, i32* @ICANON
%14 = xor i32 %13, -1
%15 = load i32, i32* @ECHO
%16 = xor i32 %15, -1
%17 = and i32 %14, %16
%18 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @STDIN_FILENO
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %21, i32 %22, %struct.termios* %7)
br label %24
24: ; preds = %28, %2
%25 = call zeroext i8 (...) @getchar()
store i8 %25, i8* %8
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8, i8* %8
%30 = call i32 @putchar(i8 zeroext %29)
br label %24
31: ; preds = %24
%32 = load i32, i32* @STDIN_FILENO
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %32, i32 %33, %struct.termios* %6)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast %struct.termios* %4 to i8*
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %3)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%11 = load i32, i32* %9
%12 = load i32, i32* @ICANON
%13 = load i32, i32* @ECHO
%14 = or i32 %13, %12
%15 = xor i32 %14, -1
%16 = and i32 %11, %15
store i32 %16, i32* %10
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %4)
%20 = call zeroext i8 (...) @getchar()
%21 = icmp eq i8 %20, 10
br i1 %21, label %27, label %22
22: ; preds = %2, %22
%23 = phi i8 [ %25, %22 ], [ %20, %2 ]
%24 = call i32 @putchar(i8 zeroext %23)
%25 = call zeroext i8 (...) @getchar()
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %22
27: ; preds = %22, %2
%28 = load i32, i32* @STDIN_FILENO
%29 = load i32, i32* @TCSANOW
%30 = call i32 @tcsetattr(i32 %28, i32 %29, %struct.termios* %3)
ret i32 0
}