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


x86 assembly (clang, -O0):
<cio_nonblock>:
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    1147 <cio_nonblock+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <cio_nonblock+0x86>
mov    -0xc(%rbp),%eax
mov    0x2e97(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1190 <cio_nonblock+0x80>
mov    -0x8(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e76(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    1190 <cio_nonblock+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <cio_nonblock+0x86>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cio_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
js     1155 <cio_nonblock+0x45>
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1153 <cio_nonblock+0x43>
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1155 <cio_nonblock+0x45>
mov    %ebx,%ebp
mov    %ebp,%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 @cio_nonblock(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 %11
10: ; preds = %1
store i32 -1, i32* %2
br label %27
11: ; preds = %1
%12 = load i32, i32* %4
%13 = load i32, i32* @O_NONBLOCK
%14 = and i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i32, i32* %3
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %4
%20 = load i32, i32* @O_NONBLOCK
%21 = or i32 %19, %20
%22 = call i32 (i32, i32, ...) @fcntl(i32 %17, i32 %18, i32 %21)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
store i32 -1, i32* %2
br label %27
25: ; preds = %16, %11
%26 = load i32, i32* %3
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %24, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @cio_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
}