#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_cc;
  int /*<<< orphan*/ c_lflag;
};

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


x86 assembly (clang, -O0):
<nb_set_nonblocking_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpl   $0x0,-0x4(%rbp)
je     1173 <nb_set_nonblocking_input+0x53>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1182 <nb_set_nonblocking_input+0x62>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nb_set_nonblocking_input>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2ea0(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
test   %ebx,%ebx
je     1168 <nb_set_nonblocking_input+0x48>
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    116c <nb_set_nonblocking_input+0x4c>
or     %eax,0x10(%rsp)
mov    (%r14),%edi
mov    0x2e72(%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*, i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define void @nb_set_nonblocking_input(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 %18
8: ; preds = %1
%9 = load i32, i32* @ICANON
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%15 = load i32*, i32** %14
%16 = load i64, i64* @VMIN
%17 = getelementptr inbounds i32, i32* %15, i64 %16
store i32 1, i32* %17
br label %23
18: ; preds = %1
%19 = load i32, i32* @ICANON
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
br label %23
23: ; preds = %18, %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*, i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
define void @nb_set_nonblocking_input(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
br i1 %6, label %17, label %8
8: ; preds = %1
%9 = xor i32 %7, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32*, i32** %13
%15 = load i64, i64* @VMIN
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 1, i32* %16
br label %21
17: ; preds = %1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%19 = load i32, i32* %18
%20 = or i32 %19, %7
store i32 %20, i32* %18
br label %21
21: ; preds = %17, %8
%22 = load i32, i32* @STDIN_FILENO
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %22, i32 %23, %struct.termios* %2)
ret void
}