#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*/ abort();
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ perror(char *);
void fcntl_set_nonblock(int fd, int on) {
  int rv;
  int fl;
  rv = fcntl(fd, F_GETFL);
  if (rv == -1) {
    perror("fcntl");
    abort();
  }
  fl = rv;
  if (on) {
    fl |= O_NONBLOCK;
  } else {
    fl &= ~O_NONBLOCK;
  }
  rv = fcntl(fd, F_SETFL, fl);
  if (rv == -1) {
    perror("fcntl");
    abort();
  }
}


x86 assembly (clang, -O0):
<fcntl_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1171 <fcntl_set_nonblock+0x41>
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1195 <fcntl_set_nonblock+0x65>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11a7 <fcntl_set_nonblock+0x77>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11dd <fcntl_set_nonblock+0xad>
lea    0xe2f(%rip),%rdi
call   1050 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcntl_set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1180 <fcntl_set_nonblock+0x50>
mov    0x2e95(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1180 <fcntl_set_nonblock+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe79(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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

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