#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*/, ...);
int cras_make_fd_nonblocking(int fd) {
  int fl;
  fl = fcntl(fd, F_GETFL);
  if (fl < 0)
    return fl;
  if (fl & O_NONBLOCK)
    return 0;
  return fcntl(fd, F_SETFL, fl | O_NONBLOCK);
}


x86 assembly (clang, -O0):
<cras_make_fd_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1146 <cras_make_fd_nonblocking+0x36>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1189 <cras_make_fd_nonblocking+0x79>
mov    -0xc(%rbp),%eax
mov    0x2e98(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1167 <cras_make_fd_nonblocking+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1189 <cras_make_fd_nonblocking+0x79>
mov    -0x8(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e6b(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cras_make_fd_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1152 <cras_make_fd_nonblocking+0x42>
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1154 <cras_make_fd_nonblocking+0x44>
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %ebx,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @cras_make_fd_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %25
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* @O_NONBLOCK
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
store i32 0, i32* %2
br label %25
18: ; preds = %12
%19 = load i32, i32* %3
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %4
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 (i32, i32, ...) @fcntl(i32 %19, i32 %20, i32 %23)
store i32 %24, i32* %2
br label %25
25: ; preds = %18, %17, %10
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @cras_make_fd_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp slt i32 %3, 0
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 = load i32, i32* @F_SETFL
%11 = or i32 %6, %3
%12 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %10, i32 %11)
br label %13
13: ; preds = %5, %1, %9
%14 = phi i32 [ %12, %9 ], [ %3, %1 ], [ 0, %5 ]
ret i32 %14
}