#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 errno;
int fcntl(int, int /*<<< orphan*/, int);
int setNonBlock(int fd, char value) {
  int flags = fcntl(fd, F_GETFL, 0);
  if (flags < 0)
    return errno;
  if (value)
    return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
  return fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
}


x86 assembly (clang, -O0):
<setNonBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1152 <setNonBlock+0x42>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a6 <setNonBlock+0x96>
cmpb   $0x0,-0x9(%rbp)
je     1181 <setNonBlock+0x71>
mov    -0x8(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    0x2e76(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
jmp    11a6 <setNonBlock+0x96>
mov    -0x8(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setNonBlock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1148 <setNonBlock+0x38>
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ead(%rip),%rcx
mov    (%rcx),%edx
test   %bpl,%bpl
je     1158 <setNonBlock+0x48>
or     %eax,%edx
mov    %ebx,%edi
jmp    1160 <setNonBlock+0x50>
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
not    %edx
and    %edx,%eax
mov    %ebx,%edi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @setNonBlock(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
%7 = load i32, i32* %4
%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 slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @errno
store i32 %13, i32* %3
br label %32
14: ; preds = %2
%15 = load i8, i8* %5
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %4
%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)
store i32 %23, i32* %3
br label %32
24: ; preds = %14
%25 = load i32, i32* %4
%26 = load i32, i32* @F_SETFL
%27 = load i32, i32* %6
%28 = load i32, i32* @O_NONBLOCK
%29 = xor i32 %28, -1
%30 = and i32 %27, %29
%31 = call i32 @fcntl(i32 %25, i32 %26, i32 %30)
store i32 %31, i32* %3
br label %32
32: ; preds = %24, %17, %12
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @setNonBlock(i32 %0, i8 signext %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 = load i32, i32* @errno
br label %19
8: ; preds = %2
%9 = icmp eq i8 %1, 0
%10 = load i32, i32* @F_SETFL
%11 = load i32, i32* @O_NONBLOCK
br i1 %9, label %15, label %12
12: ; preds = %8
%13 = or i32 %11, %4
%14 = tail call i32 @fcntl(i32 %0, i32 %10, i32 %13)
br label %19
15: ; preds = %8
%16 = xor i32 %11, -1
%17 = and i32 %4, %16
%18 = tail call i32 @fcntl(i32 %0, i32 %10, i32 %17)
br label %19
19: ; preds = %15, %12, %6
%20 = phi i32 [ %7, %6 ], [ %14, %12 ], [ %18, %15 ]
ret i32 %20
}