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

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


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    115d <set_noecho+0x2d>
lea    0xea8(%rip),%rdi
call   1050 <die@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
mov    0x2e6b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e52(%rip),%rcx
or     (%rcx),%eax
mov    0x2e41(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11c7 <set_noecho+0x97>
lea    0xe4e(%rip),%rdi
call   1050 <die@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
jns    1152 <set_noecho+0x22>
lea    0xeb3(%rip),%rdi
call   1050 <die@plt>
mov    0x2e87(%rip),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e5d(%rip),%rax
or     (%rax),%ecx
mov    0x2e4c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
test   %rax,%rax
jns    11b1 <set_noecho+0x81>
lea    0xe64(%rip),%rdi
call   1050 <die@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@.str = [16 x i8] c"tcgetattr error\00"
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ONLCR = global i32 0
@TCSANOW = global i32 0
@.str.1 = [16 x i8] c"tcsetattr error\00"
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 %9
7: ; preds = %1
%8 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* @ECHO
%11 = load i32, i32* @ECHOE
%12 = or i32 %10, %11
%13 = load i32, i32* @ECHOK
%14 = or i32 %12, %13
%15 = load i32, i32* @ECHONL
%16 = or i32 %14, %15
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @ONLCR
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* %2
%27 = load i32, i32* @TCSANOW
%28 = call i64 @tcsetattr(i32 %26, i32 %27, %struct.termios* %3)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %9
%31 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %9
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@.str = [16 x i8] c"tcgetattr error\00"
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ONLCR = global i32 0
@TCSANOW = global i32 0
@.str.1 = [16 x i8] c"tcsetattr error\00"
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 %6, label %8
6: ; preds = %1
%7 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* @ECHO
%10 = load i32, i32* @ECHOE
%11 = or i32 %10, %9
%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* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @ONLCR
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @TCSANOW
%26 = call i64 @tcsetattr(i32 %0, i32 %25, %struct.termios* %2)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %8
%29 = call i32 @die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %8
ret void
}