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


x86 assembly (clang, -O0):
<_nxweb_set_non_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1146 <_nxweb_set_non_block+0x36>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1184 <_nxweb_set_non_block+0x74>
mov    -0x8(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
or     -0xc(%rbp),%edx
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    117d <_nxweb_set_non_block+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <_nxweb_set_non_block+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @_nxweb_set_non_block(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%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 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %22
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* @O_NONBLOCK
%16 = load i32, i32* %4
%17 = or i32 %16, %15
store i32 %17, i32* %4
%18 = call i32 (i32, i32, ...) @fcntl(i32 %13, i32 %14, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 -1, i32* %2
br label %22
21: ; preds = %12
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @_nxweb_set_non_block(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 %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 (i32, i32, ...) @fcntl(i32 %0, i32 %6, i32 %8)
%10 = ashr i32 %9, 31
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ %3, %1 ], [ %10, %5 ]
ret i32 %12
}