#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 */

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int /*<<< orphan*/ STDIN_FILENO;
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int);
void set_getch_nb(int nb) {
  int flags;
  if (!nb) {
    flags = fcntl(STDIN_FILENO, F_GETFL, 0);
    fcntl(STDIN_FILENO, F_SETFL, flags & ~O_NONBLOCK);
  } else {
    fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
  }
}


x86 assembly (clang, -O0):
<set_getch_nb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    116e <set_getch_nb+0x5e>
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    0x2e87(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
jmp    118e <set_getch_nb+0x7e>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_getch_nb>:
push   %rbx
mov    %edi,%eax
mov    0x2eae(%rip),%rbx
mov    (%rbx),%edi
test   %eax,%eax
je     1138 <set_getch_nb+0x28>
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2eb8(%rip),%rax
mov    (%rax),%edx
pop    %rbx
jmp    1030 <fcntl@plt>
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    (%rbx),%edi
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%edx
not    %edx
and    %eax,%edx
pop    %rbx
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @set_getch_nb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = load i32, i32* @STDIN_FILENO
%8 = load i32, i32* @F_GETFL
%9 = call i32 @fcntl(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = load i32, i32* @STDIN_FILENO
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* %3
%13 = load i32, i32* @O_NONBLOCK
%14 = xor i32 %13, -1
%15 = and i32 %12, %14
%16 = call i32 @fcntl(i32 %10, i32 %11, i32 %15)
br label %22
17: ; preds = %1
%18 = load i32, i32* @STDIN_FILENO
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* @O_NONBLOCK
%21 = call i32 @fcntl(i32 %18, i32 %19, i32 %20)
br label %22
22: ; preds = %17, %6
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define void @set_getch_nb(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = load i32, i32* @STDIN_FILENO
br i1 %2, label %4, label %13
4: ; preds = %1
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 @fcntl(i32 %3, i32 %5, i32 0)
%7 = load i32, i32* @STDIN_FILENO
%8 = load i32, i32* @F_SETFL
%9 = load i32, i32* @O_NONBLOCK
%10 = xor i32 %9, -1
%11 = and i32 %6, %10
%12 = tail call i32 @fcntl(i32 %7, i32 %8, i32 %11)
br label %17
13: ; preds = %1
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* @O_NONBLOCK
%16 = tail call i32 @fcntl(i32 %3, i32 %14, i32 %15)
br label %17
17: ; preds = %13, %4
ret void
}