#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;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int ECHO;
int ECHOE;
int ECHOK;
int ECHONL;
int /*<<< orphan*/ IGNCR;
int /*<<< orphan*/ TCSANOW;
scalar_t__ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_noecho(int fd) {
  struct termios stermios;
  if (tcgetattr(fd, &stermios) < 0) {
    return;
  }
  stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  stermios.c_iflag |= (IGNCR);
  tcsetattr(fd, TCSANOW, &stermios);
}


x86 assembly (clang, -O0):
<set_noecho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1146 <set_noecho+0x26>
jmp    1197 <set_noecho+0x77>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e61(%rip),%rcx
or     (%rcx),%eax
mov    0x2e50(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_noecho>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
js     1182 <set_noecho+0x62>
mov    0x2e9b(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e71(%rip),%rax
or     (%rax),%ecx
mov    0x2e60(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
or     %eax,0xc(%rsp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@IGNCR = global i32 0
@TCSANOW = global i32 0
define void @set_noecho(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
br label %27
8: ; preds = %1
%9 = load i32, i32* @ECHO
%10 = load i32, i32* @ECHOE
%11 = or i32 %9, %10
%12 = load i32, i32* @ECHOK
%13 = or i32 %11, %12
%14 = load i32, i32* @ECHONL
%15 = or i32 %13, %14
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @IGNCR
%21 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%22 = load i32, i32* %21
%23 = or i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* %2
%25 = load i32, i32* @TCSANOW
%26 = call i32 @tcsetattr(i32 %24, i32 %25, %struct.termios* %3)
br label %27
27: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@IGNCR = global i32 0
@TCSANOW = global i32 0
define void @set_noecho(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = load i32, i32* @ECHO
%8 = load i32, i32* @ECHOE
%9 = or i32 %8, %7
%10 = load i32, i32* @ECHOK
%11 = or i32 %9, %10
%12 = load i32, i32* @ECHONL
%13 = or i32 %11, %12
%14 = xor i32 %13, -1
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, %14
store i32 %17, i32* %15
%18 = load i32, i32* @IGNCR
%19 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %0, i32 %22, %struct.termios* %2)
br label %24
24: ; preds = %1, %6
ret void
}