#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 _fd_set_nonblock(int fd) {
  int flags = 0;
  if ((flags = fcntl(fd, F_GETFL)) < 0)
    return -1;
  if (!(flags & O_NONBLOCK)) {
    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_fd_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    114d <_fd_set_nonblock+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <_fd_set_nonblock+0x92>
mov    -0xc(%rbp),%eax
mov    0x2e91(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    119b <_fd_set_nonblock+0x8b>
mov    -0x8(%rbp),%edi
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e70(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1196 <_fd_set_nonblock+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <_fd_set_nonblock+0x92>
jmp    119b <_fd_set_nonblock+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fd_set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1155 <_fd_set_nonblock+0x45>
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1153 <_fd_set_nonblock+0x43>
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1155 <_fd_set_nonblock+0x45>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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