#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);
int /*<<< orphan*/ rr_net_error(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int rr_net_nonblock(char *err, int fd) {
  int flag = fcntl(fd, F_GETFL, 0);
  if (flag == -1) {
    rr_net_error(err, "fcntl(F_GETFL): %s", strerror(errno));
    return -1;
  }
  if (fcntl(fd, F_SETFL, flag | O_NONBLOCK) == -1) {
    rr_net_error(err, "fcntl(F_SETFL): %s", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rr_net_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1193 <rr_net_nonblock+0x63>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe7e(%rip),%rsi
call   1040 <rr_net_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <rr_net_nonblock+0xc4>
mov    -0x14(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11ed <rr_net_nonblock+0xbd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe37(%rip),%rsi
call   1040 <rr_net_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f4 <rr_net_nonblock+0xc4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rr_net_nonblock>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     117b <rr_net_nonblock+0x4b>
mov    0x2e7f(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e86(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a2 <rr_net_nonblock+0x72>
lea    0xe9a(%rip),%rbx
jmp    1182 <rr_net_nonblock+0x52>
lea    0xe7e(%rip),%rbx
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <rr_net_error@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [19 x i8] c"fcntl(F_GETFL): %s\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [19 x i8] c"fcntl(F_SETFL): %s\00"
define i32 @rr_net_nonblock(i8* %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %1, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @F_SETFL
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %4
%10 = tail call i32 @fcntl(i32 %1, i32 %7, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %6, %2
%13 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %6 ]
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 @rr_net_error(i8* %0, i8* %13, i32 %15)
br label %17
17: ; preds = %12, %6
%18 = phi i32 [ 0, %6 ], [ -1, %12 ]
ret i32 %18
}