#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 const, int /*<<< orphan*/, ...);
int set_nonblock(const int fd) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL)) < 0) {
    goto error;
  }
  if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
    goto error;
  }
  return 0;
error:
  return 1;
}


x86 assembly (clang, -O0):
<set_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)
cmp    $0x0,%eax
jge    113f <set_nonblock+0x2f>
jmp    1178 <set_nonblock+0x68>
mov    -0x8(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e93(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    116c <set_nonblock+0x5c>
jmp    1178 <set_nonblock+0x68>
movl   $0x0,-0x4(%rbp)
jmp    117f <set_nonblock+0x6f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     114d <set_nonblock+0x3d>
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ead(%rip),%rcx
or     (%rcx),%eax
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1152 <set_nonblock+0x42>
mov    $0x1,%ebx
mov    %ebx,%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_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 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %20
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @F_SETFL
%13 = load i32, i32* %4
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %13, %14
%16 = call i32 (i32, i32, ...) @fcntl(i32 %11, i32 %12, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %10
br label %20
19: ; preds = %10
store i32 0, i32* %2
br label %21
20: ; preds = %18, %9
store i32 1, i32* %2
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @set_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 %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 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %5, %1
br label %12
12: ; preds = %5, %11
%13 = phi i32 [ 1, %11 ], [ 0, %5 ]
ret i32 %13
}