#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*/ vt_mode_get(struct termios *);
int /*<<< orphan*/ vt_mode_set(struct termios *);
void vt_mode_set_echo(int echo) {
  struct termios attr;
  vt_mode_get(&attr);
  if (echo) {
    attr.c_lflag |= (ECHO | ECHOE | ECHOK | ECHONL);
  } else {
    attr.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
  }
  vt_mode_set(&attr);
}


x86 assembly (clang, -O0):
<vt_mode_set_echo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <vt_mode_get@plt>
cmpl   $0x0,-0x4(%rbp)
je     116d <vt_mode_set_echo+0x4d>
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    0x2e92(%rip),%rcx
or     (%rcx),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    119a <vt_mode_set_echo+0x7a>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    0x2e63(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e39(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <vt_mode_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vt_mode_set_echo>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
call   1040 <vt_mode_get@plt>
mov    0x2eb0(%rip),%rcx
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e86(%rip),%rcx
or     (%rcx),%eax
mov    0x2e75(%rip),%rcx
or     (%rcx),%eax
test   %ebx,%ebx
je     115f <vt_mode_set_echo+0x3f>
or     %eax,0x8(%rsp)
jmp    1165 <vt_mode_set_echo+0x45>
not    %eax
and    %eax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <vt_mode_set@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
define void @vt_mode_set_echo(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @vt_mode_get(%struct.termios* %3)
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %1
%8 = load i32, i32* @ECHO
%9 = load i32, i32* @ECHOE
%10 = or i32 %8, %9
%11 = load i32, i32* @ECHOK
%12 = or i32 %10, %11
%13 = load i32, i32* @ECHONL
%14 = or i32 %12, %13
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = or i32 %16, %14
store i32 %17, i32* %15
br label %30
18: ; preds = %1
%19 = load i32, i32* @ECHO
%20 = load i32, i32* @ECHOE
%21 = or i32 %19, %20
%22 = load i32, i32* @ECHOK
%23 = or i32 %21, %22
%24 = load i32, i32* @ECHONL
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
br label %30
30: ; preds = %18, %7
%31 = call i32 @vt_mode_set(%struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
define void @vt_mode_set_echo(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @vt_mode_get(%struct.termios* %2)
%5 = icmp eq i32 %0, 0
%6 = load i32, i32* @ECHO
%7 = load i32, i32* @ECHOE
%8 = or i32 %7, %6
%9 = load i32, i32* @ECHOK
%10 = or i32 %8, %9
%11 = load i32, i32* @ECHONL
%12 = or i32 %10, %11
br i1 %5, label %17, label %13
13: ; preds = %1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %12, %15
store i32 %16, i32* %14
br label %22
17: ; preds = %1
%18 = xor i32 %12, -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
br label %22
22: ; preds = %17, %13
%23 = call i32 @vt_mode_set(%struct.termios* %2)
ret void
}