#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 /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int unix_set_nonblock(int fd) {
  int flags, ret;
  flags = fcntl(fd, F_GETFL);
  if (flags == -1)
    ret = -1;
  else
    flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  if (flags == -1)
    ret = -1;
  else if (ret != -1)
    ret = 0;
  if (ret == -1)
    fprintf(stderr, "fcntl(): %s\n", strerror(errno));
  return ret;
}


x86 assembly (clang, -O0):
<unix_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1167 <unix_set_nonblock+0x37>
movl   $0xffffffff,-0xc(%rbp)
jmp    1189 <unix_set_nonblock+0x59>
mov    -0x4(%rbp),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    119f <unix_set_nonblock+0x6f>
movl   $0xffffffff,-0xc(%rbp)
jmp    11b5 <unix_set_nonblock+0x85>
cmpl   $0xffffffff,-0xc(%rbp)
je     11b0 <unix_set_nonblock+0x80>
movl   $0x0,-0xc(%rbp)
jmp    11b5 <unix_set_nonblock+0x85>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11eb <unix_set_nonblock+0xbb>
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unix_set_nonblock>:
push   %rbx
mov    %edi,%ebx
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1165 <unix_set_nonblock+0x35>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e90(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"fcntl(): %s\0A\00"
@errno = global i32 0
define i32 @unix_set_nonblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @F_GETFL
%7 = call i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %4
br label %18
11: ; preds = %1
%12 = load i32, i32* %2
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %3
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 (i32, i32, ...) @fcntl(i32 %12, i32 %13, i32 %16)
store i32 %17, i32* %3
br label %18
18: ; preds = %11, %10
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %4
br label %27
22: ; preds = %18
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %4
br label %26
26: ; preds = %25, %22
br label %27
27: ; preds = %26, %21
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %30, %27
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"fcntl(): %s\0A\00"
@errno = global i32 0
define i32 @unix_set_nonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, 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)
br label %10
10: ; preds = %1, %5
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %13)
ret i32 -1
}