#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*/ assert(int);
int /*<<< orphan*/ error(char *);
int fcntl(int, int /*<<< orphan*/, int);
void fd_set_nonblocking(int fd) {
  int fval;
  assert(fd >= 0);
  if ((fval = fcntl(fd, F_GETFL, 0)) < 0)
    error("fcntl(F_GETFL) failed: %m");
  if (fcntl(fd, F_SETFL, fval | O_NONBLOCK) < 0)
    error("fcntl(F_SETFL) failed: %m");
  return;
}


x86 assembly (clang, -O0):
<fd_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%edi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1177 <fd_set_nonblocking+0x47>
lea    0xe8e(%rip),%rdi
call   1050 <error@plt>
mov    -0x4(%rbp),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e5b(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    11a9 <fd_set_nonblocking+0x79>
lea    0xe76(%rip),%rdi
call   1050 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_set_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1163 <fd_set_nonblocking+0x33>
lea    0xea2(%rip),%rdi
call   1050 <error@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
test   %eax,%eax
js     1189 <fd_set_nonblocking+0x59>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <error@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [26 x i8] c"fcntl(F_GETFL) failed: %m\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [26 x i8] c"fcntl(F_SETFL) failed: %m\00"
define void @fd_set_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp sge i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i32, i32* %2
%9 = load i32, i32* @F_GETFL
%10 = call i32 @fcntl(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %3
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
%15 = load i32, i32* %2
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* %3
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = call i32 @fcntl(i32 %15, i32 %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %14
ret void
}

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