#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*/, ...);
void socket_nonblock(int fd, int enable) {
  int flag = fcntl(fd, F_GETFL);
  if (enable) {
    fcntl(fd, F_SETFL, flag | O_NONBLOCK);
  } else {
    fcntl(fd, F_SETFL, flag & ~O_NONBLOCK);
  }
}


x86 assembly (clang, -O0):
<socket_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1162 <socket_nonblock+0x52>
mov    -0x4(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e94(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
jmp    1186 <socket_nonblock+0x76>
mov    -0x4(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2eba(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebx,%ebx
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
cmove  %ecx,%edx
mov    %ebp,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>

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

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