#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;
long O_NONBLOCK;
int /*<<< orphan*/ err(int, char *);
scalar_t__ fcntl(int, int /*<<< orphan*/, ...);
void set_nonblock_mode(int fd, int value) {
  long flags;
  flags = fcntl(fd, F_GETFL);
  if (flags == -1)
    err(1, "fcntl");
  if (value) {
    flags |= O_NONBLOCK;
  } else {
    flags &= ~O_NONBLOCK;
  }
  if (fcntl(fd, F_SETFL, flags) != 0)
    err(1, "fcntl");
}


x86 assembly (clang, -O0):
<set_nonblock_mode>:
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
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0xffffffffffffffff,-0x10(%rbp)
jne    1161 <set_nonblock_mode+0x41>
mov    $0x1,%edi
lea    0xea4(%rip),%rsi
call   1040 <err@plt>
cmpl   $0x0,-0x8(%rbp)
je     1182 <set_nonblock_mode+0x62>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1198 <set_nonblock_mode+0x78>
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
xor    $0xffffffffffffffff,%rax
and    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
je     11ca <set_nonblock_mode+0xaa>
mov    $0x1,%edi
lea    0xe3b(%rip),%rsi
call   1040 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblock_mode>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %rax,%rbp
cmp    $0xffffffffffffffff,%rax
jne    1153 <set_nonblock_mode+0x33>
lea    0xeb7(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%rdx
mov    %rdx,%rax
or     %rbp,%rax
not    %rdx
and    %rbp,%rdx
test   %r14d,%r14d
cmovne %rax,%rdx
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %rax,%rax
je     119c <set_nonblock_mode+0x7c>
lea    0xe72(%rip),%rsi
mov    $0x1,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <err@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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