#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 /*<<< orphan*/ perror(char *);
scalar_t__ unlikely(int);
int evaio_set_nonblocking(int fd) {
  int flags;
  if (unlikely((flags = fcntl(fd, F_GETFL))) < 0) {
    perror("getting O_NONBLOCK mode");
    return flags;
  }
  if (unlikely(!(flags & O_NONBLOCK) &&
               fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0)) {
    perror("setting O_NONBLOCK mode");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<evaio_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,%edi
mov    %edi,-0xc(%rbp)
call   1050 <unlikely@plt>
cmp    $0x0,%rax
jge    1179 <evaio_set_nonblocking+0x49>
lea    0xe97(%rip),%rdi
call   1040 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f1 <evaio_set_nonblocking+0xc1>
mov    -0xc(%rbp),%ecx
mov    0x2e65(%rip),%rax
and    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
jne    11bb <evaio_set_nonblocking+0x8b>
mov    -0x8(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <unlikely@plt>
cmp    $0x0,%rax
je     11ea <evaio_set_nonblocking+0xba>
lea    0xe3f(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <evaio_set_nonblocking+0xc1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evaio_set_nonblocking>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <unlikely@plt>
test   %rax,%rax
js     1193 <evaio_set_nonblocking+0x63>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
test   %ebx,%edx
jne    117e <evaio_set_nonblocking+0x4e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
or     %ebx,%edx
mov    %r14d,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
mov    %ebp,%edi
call   1050 <unlikely@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    119c <evaio_set_nonblocking+0x6c>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe66(%rip),%rdi
jmp    11a8 <evaio_set_nonblocking+0x78>
mov    $0xffffffff,%ebx
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
jmp    118c <evaio_set_nonblocking+0x5c>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [24 x i8] c"getting O_NONBLOCK mode\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [24 x i8] c"setting O_NONBLOCK mode\00"
define i32 @evaio_set_nonblocking(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 = call i64 @unlikely(i32 %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %34
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i32, i32* @O_NONBLOCK
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = load i32, i32* %3
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %4
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 (i32, i32, ...) @fcntl(i32 %19, i32 %20, i32 %23)
%25 = icmp slt i32 %24, 0
br label %26
26: ; preds = %18, %13
%27 = phi i1 [ false, %13 ], [ %25, %18 ]
%28 = zext i1 %27 to i32
%29 = call i64 @unlikely(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %34
33: ; preds = %26
store i32 0, i32* %2
br label %34
34: ; preds = %33, %31, %10
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [24 x i8] c"getting O_NONBLOCK mode\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [24 x i8] c"setting O_NONBLOCK mode\00"
define i32 @evaio_set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = tail call i64 @unlikely(i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = load i32, i32* @O_NONBLOCK
%8 = and i32 %7, %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = load i32, i32* @F_SETFL
%12 = or i32 %7, %3
%13 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %12)
%14 = lshr i32 %13, 31
br label %15
15: ; preds = %10, %6
%16 = phi i32 [ 0, %6 ], [ %14, %10 ]
%17 = tail call i64 @unlikely(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15, %1
%20 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %15 ]
%21 = phi i32 [ %3, %1 ], [ -1, %15 ]
%22 = tail call i32 @perror(i8* %20)
br label %23
23: ; preds = %19, %15
%24 = phi i32 [ 0, %15 ], [ %21, %19 ]
ret i32 %24
}