#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 fcntl(int, int /*<<< orphan*/, ...);
void set_nonblocking(int fd) {
  int val;
  if ((val = fcntl(fd, F_GETFL)) == -1)
    return;
  if (!(val & O_NONBLOCK)) {
    val |= O_NONBLOCK;
    fcntl(fd, F_SETFL, val);
  }
}


x86 assembly (clang, -O0):
<set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    113f <set_nonblocking+0x2f>
jmp    1179 <set_nonblocking+0x69>
mov    -0x8(%rbp),%eax
mov    0x2e9f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1179 <set_nonblocking+0x69>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1135 <set_nonblocking+0x25>
mov    0x2eb9(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
je     1137 <set_nonblocking+0x27>
pop    %rbx
ret
or     %eax,%edx
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
pop    %rbx
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @set_nonblocking(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 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
br label %22
9: ; preds = %1
%10 = load i32, i32* %3
%11 = load i32, i32* @O_NONBLOCK
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = load i32, i32* @O_NONBLOCK
%16 = load i32, i32* %3
%17 = or i32 %16, %15
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %3
%21 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19, i32 %20)
br label %22
22: ; preds = %8, %14, %9
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = load i32, i32* @O_NONBLOCK
%7 = and i32 %6, %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = or i32 %6, %3
%11 = load i32, i32* @F_SETFL
%12 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %10)
br label %13
13: ; preds = %5, %9, %1
ret void
}