#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 ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void set_ctl(int on) {
  struct termios term;
  tcgetattr(STDIN_FILENO, &term);
  if (on)
    term.c_lflag &= ~(ICANON | ECHO);
  else
    term.c_lflag |= (ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &term);
}


x86 assembly (clang, -O0):
<set_ctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpl   $0x0,-0x4(%rbp)
je     1167 <set_ctl+0x47>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    0x2e89(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    117f <set_ctl+0x5f>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    0x2e69(%rip),%rcx
or     (%rcx),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_ctl>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea3(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1030 <tcgetattr@plt>
mov    0x2e89(%rip),%rcx
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
test   %ebx,%ebx
je     1155 <set_ctl+0x35>
not    %eax
and    %eax,(%rsp)
jmp    1158 <set_ctl+0x38>
or     %eax,(%rsp)
mov    (%r14),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1040 <tcsetattr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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