#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 set_nonblocking(int fd, int nonblocking) {
  int rc;
  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):
<set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    114a <set_nonblocking+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <set_nonblocking+0xac>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117a <set_nonblocking+0x6a>
mov    -0x10(%rbp),%eax
mov    0x2e78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
jmp    118e <set_nonblocking+0x7e>
mov    -0x10(%rbp),%eax
mov    0x2e64(%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,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b5 <set_nonblocking+0xa5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <set_nonblocking+0xac>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1156 <set_nonblocking+0x46>
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ead(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
sar    $0x1f,%eax
jmp    115b <set_nonblocking+0x4b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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