#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 ECHOE;
int ECHOK;
int ECHONL;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_noecho(int fd) {
  struct termios term;
  if (tcgetattr(fd, &term) < 0) {
    syslog(LOG_INFO, "tcgetattr error");
    exit(0);
  }
  term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  if (tcsetattr(fd, TCSANOW, &term) < 0) {
    syslog(LOG_INFO, "tcsetattr error");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<set_noecho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
jge    117d <set_noecho+0x3d>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1030 <syslog@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    0x2e4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e32(%rip),%rcx
or     (%rcx),%eax
mov    0x2e21(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11e5 <set_noecho+0xa5>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
call   1030 <syslog@plt>
xor    %edi,%edi
call   1060 <exit@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   1040 <tcgetattr@plt>
test   %rax,%rax
js     11a0 <set_noecho+0x60>
mov    0x2e83(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e59(%rip),%rax
or     (%rax),%ecx
mov    0x2e48(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1050 <tcsetattr@plt>
test   %rax,%rax
js     11b2 <set_noecho+0x72>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
jmp    11c2 <set_noecho+0x82>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1030 <syslog@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

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