#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 /*<<< orphan*/ perror(char *);
void setNonBlocking(int fd, int status) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL, 0)) < 0) {
    perror("F_GETFL error");
  }
  if (!status) {
    if (flags & O_NONBLOCK) {
      flags ^= O_NONBLOCK;
    } else
      return;
  } else {
    flags |= O_NONBLOCK;
  }
  fcntl(fd, F_SETFL, flags);
}


x86 assembly (clang, -O0):
<setNonBlocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1159 <setNonBlocking+0x39>
lea    0xeac(%rip),%rdi
call   1040 <perror@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1196 <setNonBlocking+0x76>
mov    -0xc(%rbp),%eax
mov    0x2e7b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     118c <setNonBlocking+0x6c>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <setNonBlocking+0x71>
jmp    11b9 <setNonBlocking+0x99>
jmp    11a5 <setNonBlocking+0x85>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setNonBlocking>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1170 <setNonBlocking+0x50>
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
test   %r14d,%r14d
je     1151 <setNonBlocking+0x31>
or     %ebp,%edx
jmp    1157 <setNonBlocking+0x37>
test   %ebp,%edx
je     116b <setNonBlocking+0x4b>
xor    %ebp,%edx
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fcntl@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe89(%rip),%rdi
call   1040 <perror@plt>
jmp    113f <setNonBlocking+0x1f>

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

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