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


x86 assembly (clang, -O0):
<nonblock>:
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    -0x8(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1159 <nonblock+0x49>
movl   $0xffffffff,-0x4(%rbp)
jmp    1179 <nonblock+0x69>
mov    -0x8(%rbp),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e79(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nonblock>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2eb3(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    (%r14),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1159 <nonblock+0x49>
mov    0x2e97(%rip),%rax
mov    (%rax),%esi
mov    0x2e9e(%rip),%rax
or     (%rax),%ebp
mov    %ebx,%edi
mov    %ebp,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcntl@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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