#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*/ assert(int);
int fcntl(int, int /*<<< orphan*/, int);
int fd_set_nonblocking(int fd) {
  int fval;
  assert(fd >= 0);
  if ((fval = fcntl(fd, F_GETFL, 0)) < 0)
    return (-1);
  if (fcntl(fd, F_SETFL, fval | O_NONBLOCK) < 0)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<fd_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%edi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1167 <fd_set_nonblocking+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <fd_set_nonblocking+0x80>
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1199 <fd_set_nonblocking+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <fd_set_nonblocking+0x80>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_set_nonblocking>:
push   %rbx
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1163 <fd_set_nonblocking+0x43>
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e95(%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 @fd_set_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %3
%10 = load i32, i32* @F_GETFL
%11 = call i32 @fcntl(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %24
14: ; preds = %1
%15 = load i32, i32* %3
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* %4
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = call i32 @fcntl(i32 %15, i32 %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 -1, i32* %2
br label %24
23: ; preds = %14
store i32 0, i32* %2
br label %24
24: ; preds = %23, %22, %13
%25 = load i32, i32* %2
ret i32 %25
}

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