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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ osexit(int, char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int tty_echo(int fd, int on) {
  struct termios tty;
  tcgetattr(fd, &tty);
  if (!on) {
    tty.c_lflag &= ~ECHO;
  } else {
    tty.c_lflag |= ECHO;
  }
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    osexit(3, "error: disable echo failed");
  }
  return 1;
}


x86 assembly (clang, -O0):
<tty_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmpl   $0x0,-0x8(%rbp)
jne    116b <tty_echo+0x3b>
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    117a <tty_echo+0x4a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
je     11aa <tty_echo+0x7a>
mov    $0x3,%edi
lea    0xe5b(%rip),%rsi
call   1030 <osexit@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_echo>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
test   %ebp,%ebp
je     1151 <tty_echo+0x21>
or     %eax,(%rsp)
jmp    1156 <tty_echo+0x26>
not    %eax
and    %eax,(%rsp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <tcsetattr@plt>
test   %rax,%rax
je     117f <tty_echo+0x4f>
lea    0xe8b(%rip),%rsi
mov    $0x3,%edi
call   1030 <osexit@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str = [27 x i8] c"error: disable echo failed\00"
define i32 @tty_echo(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %5)
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @ECHO
%12 = xor i32 %11, -1
%13 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, %12
store i32 %15, i32* %13
br label %21
16: ; preds = %2
%17 = load i32, i32* @ECHO
%18 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %19, %17
store i32 %20, i32* %18
br label %21
21: ; preds = %16, %10
%22 = load i32, i32* %3
%23 = load i32, i32* @TCSANOW
%24 = call i64 @tcsetattr(i32 %22, i32 %23, %struct.termios* %5)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @osexit(i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %21
ret i32 1
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str = [27 x i8] c"error: disable echo failed\00"
define i32 @tty_echo(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp eq i32 %1, 0
%7 = load i32, i32* @ECHO
br i1 %6, label %8, label %13
8: ; preds = %2
%9 = xor i32 %7, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
br label %17
13: ; preds = %2
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %7
store i32 %16, i32* %14
br label %17
17: ; preds = %13, %8
%18 = load i32, i32* @TCSANOW
%19 = call i64 @tcsetattr(i32 %0, i32 %18, %struct.termios* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @osexit(i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
ret i32 1
}