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


x86 assembly (clang, -O0):
<_skt_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ead(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1183 <_skt_set_nonblocking+0x73>
mov    -0x8(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e8c(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    117e <_skt_set_nonblocking+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <_skt_set_nonblocking+0x7a>
jmp    1183 <_skt_set_nonblocking+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_skt_set_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2eba(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1150 <_skt_set_nonblocking+0x40>
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1150 <_skt_set_nonblocking+0x40>
mov    $0xffffffff,%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 @_skt_set_nonblocking(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 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @O_NONBLOCK
%10 = and i32 %8, %9
%11 = icmp ne i32 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* %4
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %15, %16
%18 = call i32 @fcntl(i32 %13, i32 %14, i32 %17)
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 -1, i32* %2
br label %23
21: ; preds = %12
br label %22
22: ; preds = %21, %1
store i32 0, i32* %2
br label %23
23: ; preds = %22, %20
%24 = load i32, i32* %2
ret i32 %24
}

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