#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;
scalar_t__ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_noecho(int fd) {
  struct termios stermios;
  if (tcgetattr(fd, &stermios) < 0)
    return -1;
  stermios.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  stermios.c_oflag &= ~(ONLCR);
  return tcsetattr(fd, TCSANOW, &stermios);
}


x86 assembly (clang, -O0):
<set_noecho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
jge    114d <set_noecho+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a4 <set_noecho+0x84>
mov    0x2e8c(%rip),%rax
mov    (%rax),%eax
mov    0x2e7b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
mov    0x2e51(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <tcsetattr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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     1186 <set_noecho+0x66>
mov    0x2ea3(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e79(%rip),%rax
or     (%rax),%ecx
mov    0x2e68(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
jmp    118b <set_noecho+0x6b>
mov    $0xffffffff,%eax
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
@ONLCR = global i32 0
@TCSANOW = global i32 0
define i32 @set_noecho(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %29
9: ; preds = %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* %4, 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* %4, i32 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* %3
%27 = load i32, i32* @TCSANOW
%28 = call i32 @tcsetattr(i32 %26, i32 %27, %struct.termios* %4)
store i32 %28, i32* %2
br label %29
29: ; preds = %9, %8
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@ONLCR = global i32 0
@TCSANOW = global i32 0
define i32 @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 %25, 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* @ONLCR
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%21 = load i32, i32* %20
%22 = and i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %0, i32 %23, %struct.termios* %2)
br label %25
25: ; preds = %1, %6
%26 = phi i32 [ %24, %6 ], [ -1, %1 ]
ret i32 %26
}