#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*/ ICANON;
int /*<<< orphan*/ TCSADRAIN;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void settermmode(int mode) {
  struct termios t;
  tcgetattr(0, &t);
  if (mode) {
    t.c_lflag &= ~ECHO;
    t.c_lflag &= ~ICANON;
  } else {
    t.c_lflag |= ECHO;
    t.c_lflag |= ICANON;
  }
  tcsetattr(0, TCSADRAIN, &t);
}


x86 assembly (clang, -O0):
<settermmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpl   $0x0,-0x4(%rbp)
je     1169 <settermmode+0x49>
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1187 <settermmode+0x67>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x8(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settermmode>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
mov    0x2eae(%rip),%rax
mov    (%rax),%ecx
mov    0x8(%rsp),%eax
test   %ebx,%ebx
je     1153 <settermmode+0x33>
mov    0x2e85(%rip),%rdx
or     (%rdx),%ecx
not    %ecx
and    %ecx,%eax
jmp    115e <settermmode+0x3e>
or     %ecx,%eax
mov    0x2e74(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@ECHO = global i32 0
@ICANON = global i32 0
@TCSADRAIN = global i32 0
define void @settermmode(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = call i32 @tcgetattr(i32 0, %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 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = load i32, i32* @ICANON
%14 = xor i32 %13, -1
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = and i32 %16, %14
store i32 %17, i32* %15
br label %27
18: ; preds = %1
%19 = load i32, i32* @ECHO
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @ICANON
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
br label %27
27: ; preds = %18, %7
%28 = load i32, i32* @TCSADRAIN
%29 = call i32 @tcsetattr(i32 0, i32 %28, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@ECHO = global i32 0
@ICANON = global i32 0
@TCSADRAIN = global i32 0
define void @settermmode(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 0, %struct.termios* %2)
%5 = icmp eq i32 %0, 0
%6 = load i32, i32* @ECHO
%7 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%8 = load i32, i32* %7
br i1 %5, label %14, label %9
9: ; preds = %1
%10 = load i32, i32* @ICANON
%11 = or i32 %6, %10
%12 = xor i32 %11, -1
%13 = and i32 %8, %12
br label %18
14: ; preds = %1
%15 = or i32 %8, %6
%16 = load i32, i32* @ICANON
%17 = or i32 %16, %15
br label %18
18: ; preds = %14, %9
%19 = phi i32 [ %13, %9 ], [ %17, %14 ]
store i32 %19, i32* %7
%20 = load i32, i32* @TCSADRAIN
%21 = call i32 @tcsetattr(i32 0, i32 %20, %struct.termios* %2)
ret void
}