#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*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void BarTermSetEcho(char enable) {
  struct termios termopts;
  tcgetattr(fileno(stdin), &termopts);
  if (enable == 1) {
    termopts.c_lflag |= ECHO;
  } else {
    termopts.c_lflag &= ~ECHO;
  }
  tcsetattr(fileno(stdin), TCSANOW, &termopts);
}


x86 assembly (clang, -O0):
<BarTermSetEcho>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1040 <tcgetattr@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x1,%eax
jne    1178 <BarTermSetEcho+0x48>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    118a <BarTermSetEcho+0x5a>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BarTermSetEcho>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eab(%rip),%r14
mov    (%r14),%edi
call   1030 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   1040 <tcgetattr@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
cmp    $0x1,%bl
jne    1162 <BarTermSetEcho+0x32>
or     %eax,(%rsp)
jmp    1167 <BarTermSetEcho+0x37>
not    %eax
and    %eax,(%rsp)
mov    (%r14),%edi
call   1030 <fileno@plt>
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1050 <tcsetattr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define void @BarTermSetEcho(i8 signext %0) {
%2 = alloca i8
%3 = alloca %struct.termios
store i8 %0, i8* %2
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %3)
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @ECHO
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %13, %11
store i32 %14, i32* %12
br label %21
15: ; preds = %1
%16 = load i32, i32* @ECHO
%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
br label %21
21: ; preds = %15, %10
%22 = load i32, i32* @stdin
%23 = call i32 @fileno(i32 %22)
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %23, i32 %24, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define void @BarTermSetEcho(i8 signext %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @stdin
%5 = tail call i32 @fileno(i32 %4)
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %2)
%7 = icmp eq i8 %0, 1
%8 = load i32, i32* @ECHO
br i1 %7, label %9, label %13
9: ; preds = %1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = or i32 %11, %8
store i32 %12, i32* %10
br label %18
13: ; preds = %1
%14 = xor i32 %8, -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
br label %18
18: ; preds = %13, %9
%19 = load i32, i32* @stdin
%20 = call i32 @fileno(i32 %19)
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 %20, i32 %21, %struct.termios* %2)
ret void
}