#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 fcntl(int, int /*<<< orphan*/, ...);
int fa_socket_nonblock(int socket, int enable) {
  if (enable)
    return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK);
  else
    return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK);
}


x86 assembly (clang, -O0):
<fa_socket_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     116d <fa_socket_nonblock+0x5d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    %eax,%edx
mov    0x2e8c(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
jmp    11b2 <fa_socket_nonblock+0xa2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    %eax,%edx
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fa_socket_nonblock>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2eb9(%rip),%rax
mov    (%rax),%r14d
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2eaf(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebx,%ebx
cmove  %ecx,%edx
mov    %ebp,%edi
mov    %r14d,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcntl@plt>

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

LLVM IR (-O2):
@F_SETFL = global i32 0
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @fa_socket_nonblock(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @F_GETFL
%6 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %5)
%7 = load i32, i32* @O_NONBLOCK
%8 = xor i32 %7, -1
%9 = and i32 %6, %8
%10 = or i32 %7, %6
%11 = select i1 %3, i32 %9, i32 %10
%12 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %4, i32 %11)
ret i32 %12
}