#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);
int net_set_nonblocking(int fd) {
  int rc;
  int nonblocking = 1;
  rc = fcntl(fd, F_GETFL, 0);
  if (rc < 0)
    return -1;
  rc = fcntl(fd, F_SETFL, nonblocking ? (rc | O_NONBLOCK) : (rc & ~O_NONBLOCK));
  if (rc < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<net_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114e <net_set_nonblocking+0x3e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <net_set_nonblocking+0xb0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     117e <net_set_nonblocking+0x6e>
mov    -0xc(%rbp),%eax
mov    0x2e74(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <net_set_nonblocking+0x82>
mov    -0xc(%rbp),%eax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b9 <net_set_nonblocking+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <net_set_nonblocking+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_set_nonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1147 <net_set_nonblocking+0x37>
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%esi
mov    0x2eb1(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
sar    $0x1f,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @net_set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 %0, i32 %2, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i32, i32* @F_SETFL
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %3
%9 = tail call i32 @fcntl(i32 %0, i32 %6, i32 %8)
%10 = ashr i32 %9, 31
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ -1, %1 ], [ %10, %5 ]
ret i32 %12
}