#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;
  scalar_t__ *c_cc;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void gui_nonblock(int state) {
  struct termios ttystate;
  tcgetattr(STDIN_FILENO, &ttystate);
  if (state == 1) {
    ttystate.c_lflag &= ~ICANON;
    ttystate.c_lflag &= ~ECHO;
    ttystate.c_cc[VTIME] = 0;
    ttystate.c_cc[VMIN] = 0;
  } else if (state == 0) {
    ttystate.c_lflag |= ICANON;
    ttystate.c_lflag |= ECHO;
  }
  tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
}


x86 assembly (clang, -O0):
<gui_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpl   $0x1,-0x4(%rbp)
jne    119c <gui_nonblock+0x7c>
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e52(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    11c9 <gui_nonblock+0xa9>
cmpl   $0x0,-0x4(%rbp)
jne    11c4 <gui_nonblock+0xa4>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11c9 <gui_nonblock+0xa9>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_nonblock>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2e90(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %ebx,%ebx
je     1189 <gui_nonblock+0x69>
cmp    $0x1,%ebx
jne    11a3 <gui_nonblock+0x83>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    0x2e8a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
jmp    11a3 <gui_nonblock+0x83>
mov    0x2e28(%rip),%rax
mov    0x8(%rsp),%ecx
or     (%rax),%ecx
mov    0x2e43(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    (%r14),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <tcsetattr@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64* }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define void @gui_nonblock(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 eq i32 %6, 1
br i1 %7, label %8, label %27
8: ; preds = %1
%9 = load i32, i32* @ICANON
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @ECHO
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%20 = load i64*, i64** %19
%21 = load i64, i64* @VTIME
%22 = getelementptr inbounds i64, i64* %20, i64 %21
store i64 0, i64* %22
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%24 = load i64*, i64** %23
%25 = load i64, i64* @VMIN
%26 = getelementptr inbounds i64, i64* %24, i64 %25
store i64 0, i64* %26
br label %40
27: ; preds = %1
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* @ICANON
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @ECHO
%36 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%37 = load i32, i32* %36
%38 = or i32 %37, %35
store i32 %38, i32* %36
br label %39
39: ; preds = %30, %27
br label %40
40: ; preds = %39, %8
%41 = load i32, i32* @STDIN_FILENO
%42 = load i32, i32* @TCSANOW
%43 = call i32 @tcsetattr(i32 %41, i32 %42, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i64* }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define void @gui_nonblock(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)
switch i32 %0, label %27 [
i32 1, label %6
i32 0, label %20
]
6: ; preds = %1
%7 = load i32, i32* @ICANON
%8 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%9 = load i32, i32* %8
%10 = load i32, i32* @ECHO
%11 = or i32 %7, %10
%12 = xor i32 %11, -1
%13 = and i32 %9, %12
store i32 %13, i32* %8
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%15 = load i64*, i64** %14
%16 = load i64, i64* @VTIME
%17 = getelementptr inbounds i64, i64* %15, i64 %16
store i64 0, i64* %17
%18 = load i64, i64* @VMIN
%19 = getelementptr inbounds i64, i64* %15, i64 %18
store i64 0, i64* %19
br label %27
20: ; preds = %1
%21 = load i32, i32* @ICANON
%22 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %23, %21
%25 = load i32, i32* @ECHO
%26 = or i32 %25, %24
store i32 %26, i32* %22
br label %27
27: ; preds = %1, %20, %6
%28 = load i32, i32* @STDIN_FILENO
%29 = load i32, i32* @TCSANOW
%30 = call i32 @tcsetattr(i32 %28, i32 %29, %struct.termios* %2)
ret void
}