#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 fcntl(int, int /*<<< orphan*/, ...);
void setnonblock(int fd) {
  int fl;
  fl = fcntl(fd, F_GETFL);
  assert(fl >= 0);
  fl |= O_NONBLOCK;
  fl = fcntl(fd, F_SETFL, fl);
  assert(fl >= 0);
}


x86 assembly (clang, -O0):
<setnonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
mov    0x2e9e(%rip),%rax
or     (%rax),%ebp
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
not    %eax
shr    $0x1f,%eax
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @setnonblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_GETFL
%6 = call i32 (i32, i32, ...) @fcntl(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp sge i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* @O_NONBLOCK
%12 = load i32, i32* %3
%13 = or i32 %12, %11
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %3
%17 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp sge i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @setnonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = xor i32 %3, -1
%5 = lshr i32 %4, 31
%6 = tail call i32 @assert(i32 %5)
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %3
%9 = load i32, i32* @F_SETFL
%10 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %9, i32 %8)
%11 = xor i32 %10, -1
%12 = lshr i32 %11, 31
%13 = tail call i32 @assert(i32 %12)
ret void
}